Class: ActiveModel::BetterErrors::ErrorMessage
- Inherits:
-
Object
- Object
- ActiveModel::BetterErrors::ErrorMessage
- Includes:
- Comparable
- Defined in:
- lib/active_model/better_errors/error_message.rb
Overview
ErrorMessage
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
- #as_json(*json_args) ⇒ 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.
56 57 58 59 60 61 62 |
# File 'lib/active_model/better_errors/error_message.rb', line 56 def initialize(base, attribute, type, , = {}) @base = base @attribute = attribute @type = type @message = @options = end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
54 55 56 |
# File 'lib/active_model/better_errors/error_message.rb', line 54 def attribute @attribute end |
#base ⇒ Object (readonly)
Returns the value of attribute base.
54 55 56 |
# File 'lib/active_model/better_errors/error_message.rb', line 54 def base @base end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
54 55 56 |
# File 'lib/active_model/better_errors/error_message.rb', line 54 def @message end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
54 55 56 |
# File 'lib/active_model/better_errors/error_message.rb', line 54 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
54 55 56 |
# File 'lib/active_model/better_errors/error_message.rb', line 54 def type @type end |
Class Method Details
.build(base, attribute, message, options = nil) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/active_model/better_errors/error_message.rb', line 45 def self.build(base, attribute, , = nil) = ? : {} = .except(*CALLBACKS_OPTIONS) symbol, string = identify , .delete(:message) new(base, attribute, symbol, string, ) end |
.identify(message, override) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/active_model/better_errors/error_message.rb', line 28 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
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_model/better_errors/error_message.rb', line 15 def self.normalize() case when nil nil when Symbol when Proc .call else .to_s end end |
Instance Method Details
#<=>(other) ⇒ Object
64 65 66 |
# File 'lib/active_model/better_errors/error_message.rb', line 64 def <=>(other) to_hash <=> other.to_hash end |
#==(other) ⇒ Object
93 94 95 96 |
# File 'lib/active_model/better_errors/error_message.rb', line 93 def ==(other) return type == other if other.is_a?(Symbol) to_s == other.to_s end |
#as_json(*json_args) ⇒ Object
77 78 79 |
# File 'lib/active_model/better_errors/error_message.rb', line 77 def as_json(*json_args) to_hash end |
#hash ⇒ Object
81 82 83 |
# File 'lib/active_model/better_errors/error_message.rb', line 81 def hash to_hash.hash end |
#inspect ⇒ Object
89 90 91 |
# File 'lib/active_model/better_errors/error_message.rb', line 89 def inspect to_s.inspect end |
#to_hash ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/active_model/better_errors/error_message.rb', line 68 def to_hash { attribute: attribute, type: type, message: , options: } end |
#to_s ⇒ Object
85 86 87 |
# File 'lib/active_model/better_errors/error_message.rb', line 85 def to_s ::ActiveModel::BetterErrors.(base, self) end |