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:



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

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
  @has_fix = true if @has_fix.nil?
end

Instance Attribute Details

#descriptionObject

@return[String, nil] human description of this soft validation



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

def description
  @description
end

#has_fixObject

@return

by default everything is fixable
   nil = fixable
   true = fixable (default value, not necessary option)
   false = not fixable
manual assertion of whether the method has a fix
!! This needs better reconcilition ultimately, as it is not coupled with sv_method inspection !!


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

def has_fix
  @has_fix
end

#klassObject

@param the (base) klass that has method



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

def klass
  @klass
end

#methodObject

@param the soft validation method



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

def method
  @method
end

#nameObject

@return[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

#setObject

@return[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)


65
66
67
# File 'lib/soft_validation/soft_validation_method.rb', line 65

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

#fixable?Boolean

Returns alias for has_fix

Returns:

  • (Boolean)

    alias for has_fix



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

def fixable?
  has_fix
end

#resolutions?Boolean

@return

whether there resolutions

Returns:

  • (Boolean)


71
72
73
# File 'lib/soft_validation/soft_validation_method.rb', line 71

def resolutions?
  resolution.size > 0
end

#to_sObject

@return

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


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

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