Class: ActiveModel::ErrorCollecting::ErrorMessage
- Inherits:
-
Object
- Object
- ActiveModel::ErrorCollecting::ErrorMessage
- Includes:
- Comparable
- Defined in:
- lib/active_model/error_collecting/error_message.rb
Constant Summary collapse
- CALLBACKS_OPTIONS =
[:if, :unless, :on, :allow_nil, :allow_blank, :strict]
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .build(base, attribute, message, options = nil) ⇒ Object
- .identify(message, override) ⇒ Object
-
.normalize(message) ⇒ Object
return the message either as nil, symbol, or string.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #hash ⇒ Object
-
#initialize(base, attribute, type, message, options = {}) ⇒ ErrorMessage
constructor
A new instance of ErrorMessage.
- #inspect ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(base, attribute, type, message, options = {}) ⇒ ErrorMessage
Returns a new instance of ErrorMessage.
49 50 51 52 53 54 55 |
# File 'lib/active_model/error_collecting/error_message.rb', line 49 def initialize(base, attribute, type, , = {}) @base = base @attribute = attribute @type = type = = end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
47 48 49 |
# File 'lib/active_model/error_collecting/error_message.rb', line 47 def attribute @attribute end |
#base ⇒ Object (readonly)
Returns the value of attribute base.
47 48 49 |
# File 'lib/active_model/error_collecting/error_message.rb', line 47 def base @base end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
47 48 49 |
# File 'lib/active_model/error_collecting/error_message.rb', line 47 def end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
47 48 49 |
# File 'lib/active_model/error_collecting/error_message.rb', line 47 def end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
47 48 49 |
# File 'lib/active_model/error_collecting/error_message.rb', line 47 def type @type end |
Class Method Details
.build(base, attribute, message, options = nil) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/active_model/error_collecting/error_message.rb', line 38 def self.build(base, attribute, , =nil) = ? : {} = .except(*CALLBACKS_OPTIONS) symbol, string = identify , .delete(:message) new(base, attribute, symbol, string, ) end |
.identify(message, override) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/active_model/error_collecting/error_message.rb', line 21 def self.identify(, override) symbol = string = nil = normalize override = normalize override symbol = if .is_a?(Symbol) symbol = override if override.is_a?(Symbol) string = if .is_a?(String) string = override if override.is_a?(String) string = nil if string.blank? [symbol, string] end |
.normalize(message) ⇒ Object
return the message either as nil, symbol, or string
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/active_model/error_collecting/error_message.rb', line 8 def self.normalize() case when nil nil when Symbol when Proc .call else .to_s end end |
Instance Method Details
#<=>(other) ⇒ Object
57 58 59 |
# File 'lib/active_model/error_collecting/error_message.rb', line 57 def <=> (other) to_hash <=> other.to_hash end |
#==(other) ⇒ Object
82 83 84 85 |
# File 'lib/active_model/error_collecting/error_message.rb', line 82 def ==(other) return type == other if other.is_a?(Symbol) to_s == other.to_s end |
#hash ⇒ Object
70 71 72 |
# File 'lib/active_model/error_collecting/error_message.rb', line 70 def hash to_hash.hash end |
#inspect ⇒ Object
78 79 80 |
# File 'lib/active_model/error_collecting/error_message.rb', line 78 def inspect to_s.inspect end |
#to_hash ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/active_model/error_collecting/error_message.rb', line 61 def to_hash { attribute: attribute, type: type, message: , options: } end |
#to_s ⇒ Object
74 75 76 |
# File 'lib/active_model/error_collecting/error_message.rb', line 74 def to_s HumanMessageFormatter.new(base, self). end |