Class: SmoothOperator::ArrayWithMetaData

Inherits:
OpenStruct::Base show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/smooth_operator/array_with_meta_data.rb

Instance Attribute Summary collapse

Attributes included from AttributeAssignment

#_meta_data, #_options

Instance Method Summary collapse

Methods inherited from OpenStruct::Base

strict_behaviour, strict_behaviour=

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

Methods included from Validations

#invalid?, #valid?

Methods included from Delegation

#respond_to?

Constructor Details

#initialize(attributes, object_class) ⇒ ArrayWithMetaData

Returns a new instance of ArrayWithMetaData.



13
14
15
16
17
18
19
20
# File 'lib/smooth_operator/array_with_meta_data.rb', line 13

def initialize(attributes, object_class)
  _attributes, _resources_name = attributes.dup, 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



27
28
29
30
# File 'lib/smooth_operator/array_with_meta_data.rb', line 27

def method_missing(method, *args, &block)
  _method = method.to_s
  .include?(_method) ? [_method] : super
end

Instance Attribute Details

#internal_arrayObject (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_dataObject (readonly)

Returns the value of attribute meta_data.



9
10
11
# File 'lib/smooth_operator/array_with_meta_data.rb', line 9

def 
  
end

Instance Method Details

#eachObject



23
24
25
# File 'lib/smooth_operator/array_with_meta_data.rb', line 23

def each
  internal_array.each { |array_entry| yield array_entry }
end