Class: SoftValidation::SoftValidationMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/soft_validation/soft_validation_method.rb

Overview

A metadata structure for each soft validation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ SoftValidationMethod

Returns a new instance of SoftValidationMethod.

Parameters:

  • args (Hash)

Raises:



39
40
41
42
43
44
# File 'lib/soft_validation/soft_validation_method.rb', line 39

def initialize(options)
  raise(SoftValidationError, 'missing method and klass') if options[:method].nil? || options[:klass].nil?
  options.each do |k,v|
    send("#{k}=", v)
  end
end

Instance Attribute Details

#descriptionString?

human description of this soft validation

Returns:

  • (String, nil)


20
21
22
# File 'lib/soft_validation/soft_validation_method.rb', line 20

def description
  @description
end

#fixSymbol?

Returns the name of the method that will fix this issue.

Returns:

  • (Symbol, nil)

    the name of the method that will fix this issue



32
33
34
# File 'lib/soft_validation/soft_validation_method.rb', line 32

def fix
  @fix
end

#flaggedBoolean

Returns flagged methods are not executed by default.

Returns:

  • (Boolean)

    flagged methods are not executed by default



36
37
38
# File 'lib/soft_validation/soft_validation_method.rb', line 36

def flagged
  @flagged
end

#klassObject

the (base) klass that has method

Parameters:

  • (Symbol)


12
13
14
# File 'lib/soft_validation/soft_validation_method.rb', line 12

def klass
  @klass
end

#methodObject

the soft validation method

Parameters:

  • (Symbol)


8
9
10
# File 'lib/soft_validation/soft_validation_method.rb', line 8

def method
  @method
end

#nameString?

Returns human name/title of this soft validation.

Returns:

  • (String, nil)

    human name/title of this soft validation



16
17
18
# File 'lib/soft_validation/soft_validation_method.rb', line 16

def name
  @name
end

#resolutionArray

Returns:

  • (Array)


24
25
26
# File 'lib/soft_validation/soft_validation_method.rb', line 24

def resolution
  @resolution
end

#setSymbol?

Returns assign this soft validation method to a set.

Returns:

  • (Symbol, nil)

    assign this soft validation method to a set



28
29
30
# File 'lib/soft_validation/soft_validation_method.rb', line 28

def set
  @set
end

Instance Method Details

#described?Boolean

@return

a name and description provided

Returns:

  • (Boolean)


62
63
64
# File 'lib/soft_validation/soft_validation_method.rb', line 62

def described?
  !name.blank? && !description.blank?
end

#fixable?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/soft_validation/soft_validation_method.rb', line 73

def fixable?
  @fix.kind_of?(Symbol)
end

#flagged?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/soft_validation/soft_validation_method.rb', line 78

def flagged? 
  @flagged == true
end

#matches?(is_fixable, include_flagged = false) ⇒ Boolean (private)

Returns Boolean true - the soft validation method should be retained false - the soft validation method does not match, it will be excluded from soft_validate().

Parameters:

  • is_fixable (Boolean, nil)

    nil, false - don’t require method be fixable to pass true - require method to be fixable to pass

  • is_flagged (Boolean)

    true - allow all false - allow only if not flagged

Returns:

  • (Boolean)

    Boolean true - the soft validation method should be retained false - the soft validation method does not match, it will be excluded from soft_validate()



99
100
101
102
103
# File 'lib/soft_validation/soft_validation_method.rb', line 99

def matches?(is_fixable, include_flagged = false)
  a = is_fixable.nil? ? true : (is_fixable ? fixable? : true)
  b = include_flagged == true ? true : !flagged
  a && b
end

#resolutions?Boolean

@return

whether there resolutions

Returns:

  • (Boolean)


68
69
70
# File 'lib/soft_validation/soft_validation_method.rb', line 68

def resolutions?
  resolution.size > 0
end

#to_sObject

@return

a human readable string describing the general point of this soft validation method


84
85
86
# File 'lib/soft_validation/soft_validation_method.rb', line 84

def to_s
  [(name.blank? ? "#{method} (temporary name)" : name), (description.blank? ? '(no description provided)' : description)].join(': ')
end