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.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(attributes, table_name, object_class) ⇒ ArrayWithMetaData
constructor
A new instance of ArrayWithMetaData.
- #method_missing(method, *args, &block) ⇒ Object
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
Methods included from Delegation
Constructor Details
#initialize(attributes, table_name, object_class) ⇒ 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) } _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_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 |
#table_name ⇒ Object (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
#each ⇒ Object
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 |