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

Instance Method Summary collapse

Methods included from AttributeAssignment

#assign_attributes, #get_internal_data, included, #internal_data, #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, #model_name

Methods included from Validations

#invalid?, #valid?

Methods included from Delegation

#respond_to?

Constructor Details

#initialize(attributes, table_name, object_class) ⇒ ArrayWithMetaData

Returns a new instance of ArrayWithMetaData.



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

def initialize(attributes, table_name, object_class)
  _attributes = attributes.dup

  @table_name, @object_class = table_name, object_class

  @internal_array = [*_attributes[table_name]].map { |array_entry| object_class.new(array_entry).tap { |object| object.reloaded = true } }
  _attributes.delete(table_name)

   = _attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



29
30
31
32
# File 'lib/smooth_operator/array_with_meta_data.rb', line 29

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

#table_nameObject (readonly)

Returns the value of attribute table_name.



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

def table_name
  @table_name
end

Instance Method Details

#eachObject



25
26
27
# File 'lib/smooth_operator/array_with_meta_data.rb', line 25

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