Class: Requisite::BoundaryObject
- Inherits:
-
Object
- Object
- Requisite::BoundaryObject
- Defined in:
- lib/requisite/boundary_object.rb
Direct Known Subclasses
Class Method Summary collapse
- .attribute(name, options = {}) ⇒ Object
- .attribute!(name, options = {}) ⇒ Object
- .attribute_keys ⇒ Object
- .attribute_keys_with_inheritance ⇒ Object
- .serialized_attributes(&block) ⇒ Object
Class Method Details
.attribute(name, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/requisite/boundary_object.rb', line 4 def attribute(name, ={}) attribute_keys << name define_method(name) do resolved_name = [:rename] || name result = self.send(:convert, resolved_name) result = self.send(:parse_typed_hash, resolved_name, [:typed_hash]) if [:typed_hash] result = self.send(:parse_scalar_hash, resolved_name) if [:scalar_hash] result = self.send(:parse_typed_array, resolved_name, [:typed_array]) if [:typed_array] result = [:default] if (.key?(:default) && empty_result?(result)) raise_bad_type_if_type_mismatch(result, [:type]) if [:type] && result result = result.to_s if [:stringify] result end end |
.attribute!(name, options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/requisite/boundary_object.rb', line 19 def attribute!(name, ={}) attribute_keys << name define_method(name) do resolved_name = [:rename] || name result = self.send(:convert!, resolved_name) result = self.send(:parse_typed_hash, resolved_name, [:typed_hash]) if [:typed_hash] result = self.send(:parse_scalar_hash, resolved_name) if [:scalar_hash] result = self.send(:parse_typed_array, resolved_name, [:typed_array]) if [:typed_array] result = result.to_s if [:stringify] raise_bad_type_if_type_mismatch(result, [:type]) if [:type] result end end |
.attribute_keys ⇒ Object
38 39 40 |
# File 'lib/requisite/boundary_object.rb', line 38 def attribute_keys @attribute_keys || [] end |
.attribute_keys_with_inheritance ⇒ Object
42 43 44 |
# File 'lib/requisite/boundary_object.rb', line 42 def attribute_keys_with_inheritance superclass.respond_to?(:attribute_keys_with_inheritance) ? superclass.attribute_keys_with_inheritance.concat(attribute_keys) : attribute_keys || [] end |
.serialized_attributes(&block) ⇒ Object
33 34 35 36 |
# File 'lib/requisite/boundary_object.rb', line 33 def serialized_attributes(&block) @attribute_keys = [] instance_eval(&block) end |