Class: SoftValidation::SoftValidation

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

Overview

A SoftValidation is a instance of an actual issue. It strictly a message passing structure.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SoftValidation

Returns a new instance of SoftValidation.

Parameters:

  • args (Hash)


50
51
52
53
54
55
# File 'lib/soft_validation/soft_validation.rb', line 50

def initialize(options = {})
  @fixed = :fix_not_yet_run
  options.each do |k,v|
    send("#{k}=", v)
  end
end

Instance Attribute Details

#attributeSymbol

Returns the attribute (column name), or :base to which the soft validation is tied.

Returns:

  • (Symbol)

    the attribute (column name), or :base to which the soft validation is tied



14
15
16
# File 'lib/soft_validation/soft_validation.rb', line 14

def attribute
  @attribute
end

#failure_messageString

Returns Optional. Requires a fix method. A short message describing the message provided when the soft validation was NOT successfully fixed.

Returns:

  • (String)

    Optional. Requires a fix method. A short message describing the message provided when the soft validation was NOT successfully fixed.



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

def failure_message
  @failure_message
end

#fixSymbol? (readonly)

Returns Optional. The method name of the fix that can resolve this soft validation.

Returns:

  • (Symbol, nil)

    Optional. The method name of the fix that can resolve this soft validation



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

def fix
  @fix
end

#fixedSymbol

Returns Stores a state with one of :fixed (fixes run and SoftValidation was fixed), :fix_error (fixes run and SoftValidation fix failed), :fix_not_triggered (fixes run, and SoftValidation was not triggered because of scope) :fix_not_yet_run (there is a fix method available, but it hasn’t been run) :no_fix_available (no fix method was provided).

Returns:

  • (Symbol)

    Stores a state with one of :fixed (fixes run and SoftValidation was fixed), :fix_error (fixes run and SoftValidation fix failed), :fix_not_triggered (fixes run, and SoftValidation was not triggered because of scope) :fix_not_yet_run (there is a fix method available, but it hasn’t been run) :no_fix_available (no fix method was provided)



47
48
49
# File 'lib/soft_validation/soft_validation.rb', line 47

def fixed
  @fixed
end

#messageString

Returns Required. A short message describing the soft validation.

Returns:

  • (String)

    Required. A short message describing the soft validation



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

def message
  @message
end

#method_instance=(value) ⇒ Symbol? (writeonly)

Returns The method name of the fix that can resolve this soft validation.

Returns:

  • (Symbol, nil)

    The method name of the fix that can resolve this soft validation



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

def method_instance=(value)
  @method_instance = value
end

#resolutionString? (readonly)

Returns Optional. A named route that points to where the issue can be resolved.

Returns:

  • (String, nil)

    Optional. A named route that points to where the issue can be resolved



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

def resolution
  @resolution
end

#success_messageString

Returns Optional. Requires a fix method. A short message describing the message provided when the soft validation was successfully fixed.

Returns:

  • (String)

    Optional. Requires a fix method. A short message describing the message provided when the soft validation was successfully fixed.



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

def success_message
  @success_message
end

Instance Method Details

#descriptionObject



57
58
59
# File 'lib/soft_validation/soft_validation.rb', line 57

def description
  @method_instance.description
end

#fixable?Boolean

Returns:

  • (Boolean)


74
75
76
77
# File 'lib/soft_validation/soft_validation.rb', line 74

def fixable?
  return true if !method_instance.fix.nil?
  false
end

#fixed?Boolean

Returns:

  • (Boolean)


80
81
82
83
# File 'lib/soft_validation/soft_validation.rb', line 80

def fixed?
  return true if fixed == :fixed
  false
end

#result_messageString

Returns:

  • (String)


86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/soft_validation/soft_validation.rb', line 86

def result_message
  case fixed
  when :fix_not_triggered
    'fix available, but not triggered'
  when :no_fix_available
    'no fix available'
  when :fix_not_yet_run
    'fix not yet run'
  when :fixed
    success_message.nil? ? "'#{message}' was fixed (no result message provided)" : success_message
  when :fix_error
    failure_message.nil? ? "'#{message}' was NOT fixed (no result message provided)" : failure_message
  end
end

#soft_validation_methodObject



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

def soft_validation_method
  @method_instance.method
end