Module: FirstResponder::InstanceMethods
- Defined in:
- lib/first_responder.rb
Instance Method Summary collapse
-
#initialize(fmt = nil, data) ⇒ Object
Every instance must instantiate itself with a format and corresponding data.
- #invalid?(execute = true) ⇒ Boolean
- #valid?(execute = true) ⇒ Boolean
Instance Method Details
#initialize(fmt = nil, data) ⇒ Object
Every instance must instantiate itself with a format and corresponding data. Given that information, formats are validated, data is parsed using that format, after which the attributes defined on the class are set to the hash value at the defined location.
19 20 21 22 23 |
# File 'lib/first_responder.rb', line 19 def initialize(fmt=nil, data) @format = ensure_format(fmt) if fmt @data = data.is_a?(Hash) ? data : deserialize(data, fmt) map_attrs end |
#invalid?(execute = true) ⇒ Boolean
31 32 33 |
# File 'lib/first_responder.rb', line 31 def invalid?(execute=true) !valid?(execute) end |
#valid?(execute = true) ⇒ Boolean
25 26 27 28 29 |
# File 'lib/first_responder.rb', line 25 def valid?(execute=true) return true if all_attributes_valid? proc_on_invalid.call(@data, errors) if execute return no_nesting? ? super : false end |