Class: SmoothOperator::ArrayWithMetaData
- Inherits:
-
OpenStruct::Base
- Object
- OpenStruct::Base
- SmoothOperator::ArrayWithMetaData
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/smooth_operator/array_with_meta_data.rb
Instance Attribute Summary collapse
-
#internal_array ⇒ Object
readonly
Returns the value of attribute internal_array.
-
#meta_data ⇒ Object
readonly
Returns the value of attribute meta_data.
-
#object_class ⇒ Object
readonly
Returns the value of attribute object_class.
Attributes included from AttributeAssignment
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(attributes, object_class) ⇒ ArrayWithMetaData
constructor
A new instance of ArrayWithMetaData.
- #method_missing(method, *args, &block) ⇒ Object
Methods included from AttributeAssignment
#assign_attributes, #get_internal_data, #has_data_from_server, included, #internal_data, #parent_object, #push_to_internal_data
Methods included from Serialization
#attributes, #read_attribute_for_serialization, #serializable_hash, #to_hash, #to_json
Methods included from ModelSchema
included, #internal_structure, #known_attributes, #resource_name, #resources_name
Methods included from Validations
Methods included from Delegation
Constructor Details
#initialize(attributes, object_class) ⇒ ArrayWithMetaData
Returns a new instance of ArrayWithMetaData.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/smooth_operator/array_with_meta_data.rb', line 13 def initialize(attributes, object_class) _attributes = attributes.dup @object_class = object_class resources_name = object_class.resources_name @internal_array = [*_attributes[resources_name]].map { |array_entry| object_class.new(array_entry).tap { |object| object.reloaded = true } } _attributes.delete(resources_name) = _attributes end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
30 31 32 33 |
# File 'lib/smooth_operator/array_with_meta_data.rb', line 30 def method_missing(method, *args, &block) _method = method.to_s .include?(_method) ? [_method] : super end |
Instance Attribute Details
#internal_array ⇒ Object (readonly)
Returns the value of attribute internal_array.
9 10 11 |
# File 'lib/smooth_operator/array_with_meta_data.rb', line 9 def internal_array @internal_array end |
#meta_data ⇒ Object (readonly)
Returns the value of attribute meta_data.
9 10 11 |
# File 'lib/smooth_operator/array_with_meta_data.rb', line 9 def end |
#object_class ⇒ Object (readonly)
Returns the value of attribute object_class.
9 10 11 |
# File 'lib/smooth_operator/array_with_meta_data.rb', line 9 def object_class @object_class end |
Instance Method Details
#each ⇒ Object
26 27 28 |
# File 'lib/smooth_operator/array_with_meta_data.rb', line 26 def each internal_array.each { |array_entry| yield array_entry } end |