Class: ThinModels::Struct::Typed
- Inherits:
-
ThinModels::Struct
- Object
- ThinModels::Struct
- ThinModels::Struct::Typed
- Includes:
- Typisch::Typed
- Defined in:
- lib/thin_models/struct/typed.rb
Instance Attribute Summary
Attributes inherited from ThinModels::Struct
Class Method Summary collapse
Instance Method Summary collapse
- #[]=(attribute, value) ⇒ Object
-
#check_attributes ⇒ Object
this will only type-check non-lazy properties – not much point passing lazy properties if it’s going to eagerly fetch them right away just to type-check them.
Methods inherited from ThinModels::Struct
#[], #attribute_loaded?, #attributes, attributes, #check_attribute, #fetch, #freeze, #has_lazy_values?, #initialize, #initialize_copy, #inspect, json_create, #loaded_attributes, #loaded_values, #merge, #merge!, new_skipping_checks, #remove_lazy_values, #to_json
Constructor Details
This class inherits a constructor from ThinModels::Struct
Class Method Details
.type_available ⇒ Object
12 13 14 15 16 17 |
# File 'lib/thin_models/struct/typed.rb', line 12 def type_available type.property_names_to_types.map do |name, type| attribute(name) unless attributes.include?(name) || method_defined?(name) alias_method(:"#{name}?", name) if type.excluding_null.is_a?(Typisch::Type::Boolean) end end |
Instance Method Details
#[]=(attribute, value) ⇒ Object
29 30 31 32 33 |
# File 'lib/thin_models/struct/typed.rb', line 29 def []=(attribute, value) raise NameError, "no attribute #{attribute.inspect} in #{self.class}" unless self.class.attributes.include?(attribute) @values[attribute] = value type_check_property(attribute) end |
#check_attributes ⇒ Object
this will only type-check non-lazy properties – not much point passing lazy properties if it’s going to eagerly fetch them right away just to type-check them.
23 24 25 26 27 |
# File 'lib/thin_models/struct/typed.rb', line 23 def check_attributes self.class.type.property_names.each do |property| type_check_property(property) if @values.has_key?(property) end end |