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 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

#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
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_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

#object_classObject (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

#eachObject



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