Class: Trax::Model::UUIDArray
- Inherits:
-
Object
- Object
- Trax::Model::UUIDArray
- Includes:
- Enumerable
- Defined in:
- lib/trax/model/uuid_array.rb
Instance Attribute Summary collapse
-
#uuids ⇒ Object
readonly
Returns the value of attribute uuids.
Instance Method Summary collapse
- #<<(val) ⇒ Object
- #each {|@uuids.each(&block)| ... } ⇒ Object
-
#initialize(*uuids) ⇒ UUIDArray
constructor
A new instance of UUIDArray.
- #records ⇒ Object
- #records_grouped_by_count ⇒ Object
- #records_grouped_by_uuid ⇒ Object
Constructor Details
#initialize(*uuids) ⇒ UUIDArray
Returns a new instance of UUIDArray.
8 9 10 |
# File 'lib/trax/model/uuid_array.rb', line 8 def initialize(*uuids) @uuids = uuids.map{ |uuid_string| uuid_string.try(&:uuid) }.compact end |
Instance Attribute Details
#uuids ⇒ Object (readonly)
Returns the value of attribute uuids.
6 7 8 |
# File 'lib/trax/model/uuid_array.rb', line 6 def uuids @uuids end |
Instance Method Details
#<<(val) ⇒ Object
16 17 18 19 |
# File 'lib/trax/model/uuid_array.rb', line 16 def <<(val) reset_instance_variables(:record_types, :records_grouped_by_count, :records_grouped_by_uuid) @uuids.push(::Trax::Model::UUID.new(val)) end |
#each {|@uuids.each(&block)| ... } ⇒ Object
12 13 14 |
# File 'lib/trax/model/uuid_array.rb', line 12 def each(&block) yield @uuids.each(&block) end |
#records ⇒ Object
21 22 23 24 25 |
# File 'lib/trax/model/uuid_array.rb', line 21 def records @records ||= group_by_record_type.to_a.map{|pair| pair[0].by_id(*pair[1]) }.flatten.compact end |
#records_grouped_by_count ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/trax/model/uuid_array.rb', line 31 def records_grouped_by_count @records_grouped_by_count ||= begin {}.tap do |hash| @uuids.group_by_count.each_pair do |uuid, count| record = records_grouped_by_uuid[uuid].first hash[record] = count end hash end end end |
#records_grouped_by_uuid ⇒ Object
27 28 29 |
# File 'lib/trax/model/uuid_array.rb', line 27 def records_grouped_by_uuid @records_grouped_by_uuid ||= records.group_by(&:id) end |