Class: Errorio::Error
- Inherits:
-
Object
- Object
- Errorio::Error
- Defined in:
- lib/errorio/error.rb
Overview
Error object for errors collection
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#full_message(attribute, message) ⇒ Object
Returns a full message for a given attribute.
-
#initialize(base, attribute, type, options) ⇒ Error
constructor
A new instance of Error.
- #message ⇒ Object
Constructor Details
#initialize(base, attribute, type, options) ⇒ Error
Returns a new instance of Error.
4 5 6 7 8 9 |
# File 'lib/errorio/error.rb', line 4 def initialize(base, attribute, type, ) @base = base @attribute = attribute @type = type @options = .symbolize_keys end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
12 13 14 |
# File 'lib/errorio/error.rb', line 12 def attribute @attribute end |
#base ⇒ Object (readonly)
Returns the value of attribute base.
11 12 13 |
# File 'lib/errorio/error.rb', line 11 def base @base end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/errorio/error.rb', line 14 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/errorio/error.rb', line 13 def type @type end |
Instance Method Details
#full_message(attribute, message) ⇒ Object
Returns a full message for a given attribute. person.errors.full_message(:name, ‘is invalid’) # => “Name is invalid”
22 23 24 25 26 27 28 |
# File 'lib/errorio/error.rb', line 22 def (attribute, ) attr_name = attribute.to_s.tr('.', '_').humanize return "#{attr_name} #{}" if @base.nil? attr_name = @base.class.human_attribute_name(attribute, default: attr_name) I18n.t(:"errors.format", default: '%{attribute} %{message}', attribute: attr_name, message: ) end |
#message ⇒ Object
16 17 18 |
# File 'lib/errorio/error.rb', line 16 def [:message] end |