Module: SmoothOperator::InternalData
- Included in:
- OpenStruct
- Defined in:
- lib/smooth_operator/internal_data.rb
Instance Method Summary collapse
- #internal_data ⇒ Object
- #internal_data_get(attribute_name) ⇒ Object
- #internal_data_push(attribute_name, attribute_value) ⇒ Object
- #known_attribute?(attribute) ⇒ Boolean
- #known_attributes ⇒ Object
Instance Method Details
#internal_data ⇒ Object
6 7 8 |
# File 'lib/smooth_operator/internal_data.rb', line 6 def internal_data @internal_data ||= {} end |
#internal_data_get(attribute_name) ⇒ Object
26 27 28 |
# File 'lib/smooth_operator/internal_data.rb', line 26 def internal_data_get(attribute_name) internal_data[attribute_name] end |
#internal_data_push(attribute_name, attribute_value) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/smooth_operator/internal_data.rb', line 30 def internal_data_push(attribute_name, attribute_value) attribute_name = attribute_name.to_s known_attributes.add attribute_name internal_data[attribute_name] = TypeCasting.cast_to_type(attribute_name, attribute_value, self) if self.class.respond_to?(:smooth_operator?) marked_for_destruction?(attribute_value) if attribute_name == self.class.destroy_key new_record?(true) if attribute_name == self.class.primary_key end end |
#known_attribute?(attribute) ⇒ Boolean
22 23 24 |
# File 'lib/smooth_operator/internal_data.rb', line 22 def known_attribute?(attribute) known_attributes.include?(attribute.to_s) end |
#known_attributes ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/smooth_operator/internal_data.rb', line 10 def known_attributes return @known_attributes if defined?(@known_attributes) schema_attributes = if self.class.respond_to?(:internal_structure) self.class.internal_structure.keys else [] end @known_attributes = Set.new(schema_attributes) end |