Class: PluckMap::Attributes
- Inherits:
-
Object
- Object
- PluckMap::Attributes
- Includes:
- Enumerable
- Defined in:
- lib/pluck_map/attributes.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#selects ⇒ Object
readonly
Returns the value of attribute selects.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](index) ⇒ Object
- #by_id ⇒ Object
- #each(&block) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #ids ⇒ Object
-
#initialize(attributes, model) ⇒ Attributes
constructor
A new instance of Attributes.
- #length ⇒ Object
- #nested? ⇒ Boolean
- #to_json_array ⇒ Object
- #will_map? ⇒ Boolean
Constructor Details
#initialize(attributes, model) ⇒ Attributes
Returns a new instance of Attributes.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/pluck_map/attributes.rb', line 7 def initialize(attributes, model) @model = model @_attributes = attributes.freeze @_attributes_by_id = {} @selects = [] attributes.each do |attribute| attribute.indexes = attribute.selects.map do |select| selects.find_index(select) || begin selects.push(select) selects.length - 1 end end _attributes_by_id[attribute.id] = attribute end _attributes_by_id.freeze end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/pluck_map/attributes.rb', line 5 def model @model end |
#selects ⇒ Object (readonly)
Returns the value of attribute selects.
5 6 7 |
# File 'lib/pluck_map/attributes.rb', line 5 def selects @selects end |
Instance Method Details
#==(other) ⇒ Object
67 68 69 70 |
# File 'lib/pluck_map/attributes.rb', line 67 def ==(other) return false if self.class != other.class _attributes == other.send(:_attributes) end |
#[](index) ⇒ Object
30 31 32 |
# File 'lib/pluck_map/attributes.rb', line 30 def [](index) _attributes[index] end |
#by_id ⇒ Object
44 45 46 |
# File 'lib/pluck_map/attributes.rb', line 44 def by_id _attributes_by_id end |
#each(&block) ⇒ Object
26 27 28 |
# File 'lib/pluck_map/attributes.rb', line 26 def each(&block) _attributes.each(&block) end |
#eql?(other) ⇒ Boolean
76 77 78 79 80 |
# File 'lib/pluck_map/attributes.rb', line 76 def eql?(other) return true if self.equal?(other) return false if self.class != other.class _attributes.eql?(other.send(:_attributes)) end |
#hash ⇒ Object
72 73 74 |
# File 'lib/pluck_map/attributes.rb', line 72 def hash _attributes.hash end |
#ids ⇒ Object
40 41 42 |
# File 'lib/pluck_map/attributes.rb', line 40 def ids _attributes_by_id.keys end |
#length ⇒ Object
34 35 36 |
# File 'lib/pluck_map/attributes.rb', line 34 def length _attributes.length end |
#nested? ⇒ Boolean
61 62 63 |
# File 'lib/pluck_map/attributes.rb', line 61 def nested? _attributes.any?(&:nested?) end |
#to_json_array ⇒ Object
48 49 50 51 52 53 |
# File 'lib/pluck_map/attributes.rb', line 48 def to_json_array PluckMap::BuildJsonArray.new(*selects.map do |select| select = model.arel_table[select] if select.is_a?(Symbol) select end) end |
#will_map? ⇒ Boolean
57 58 59 |
# File 'lib/pluck_map/attributes.rb', line 57 def will_map? _attributes.any?(&:will_map?) end |