Exception: NoBrainer::Error::InvalidType
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- NoBrainer::Error::InvalidType
- Defined in:
- lib/no_brainer/error.rb
Instance Attribute Summary collapse
-
#attr_name ⇒ Object
Returns the value of attribute attr_name.
-
#error ⇒ Object
Returns the value of attribute error.
-
#model ⇒ Object
Returns the value of attribute model.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #human_type_name ⇒ Object
-
#initialize(options = {}) ⇒ InvalidType
constructor
A new instance of InvalidType.
- #message ⇒ Object
- #update(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ InvalidType
Returns a new instance of InvalidType.
33 34 35 |
# File 'lib/no_brainer/error.rb', line 33 def initialize(={}) update() end |
Instance Attribute Details
#attr_name ⇒ Object
Returns the value of attribute attr_name.
32 33 34 |
# File 'lib/no_brainer/error.rb', line 32 def attr_name @attr_name end |
#error ⇒ Object
Returns the value of attribute error.
32 33 34 |
# File 'lib/no_brainer/error.rb', line 32 def error @error end |
#model ⇒ Object
Returns the value of attribute model.
32 33 34 |
# File 'lib/no_brainer/error.rb', line 32 def model @model end |
#type ⇒ Object
Returns the value of attribute type.
32 33 34 |
# File 'lib/no_brainer/error.rb', line 32 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
32 33 34 |
# File 'lib/no_brainer/error.rb', line 32 def value @value end |
Instance Method Details
#human_type_name ⇒ Object
42 43 44 |
# File 'lib/no_brainer/error.rb', line 42 def human_type_name type.to_s.underscore.humanize.downcase end |
#message ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/no_brainer/error.rb', line 51 def return super unless model && attr_name && error value = self.value mock = model.allocate mock.singleton_class.send(:define_method, :read_attribute_for_validation) { |_| value } mock.errors.add(attr_name, :invalid_type, **error) mock.errors..first end |
#update(options = {}) ⇒ Object
37 38 39 40 |
# File 'lib/no_brainer/error.rb', line 37 def update(={}) .assert_valid_keys(:model, :attr_name, :type, :value, :error) .each { |k,v| instance_variable_set("@#{k}", v) } end |