Class: Unit::Types::RelationshipArray

Inherits:
Object
  • Object
show all
Defined in:
lib/unit/types/relationship_array.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ RelationshipArray

Returns a new instance of RelationshipArray.

Parameters:

  • array (Array)


10
11
12
# File 'lib/unit/types/relationship_array.rb', line 10

def initialize(array)
  @data = array
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/unit/types/relationship_array.rb', line 7

def data
  @data
end

Class Method Details

.from_params_array(array) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/unit/types/relationship_array.rb', line 18

def self.from_params_array(array)
  @relationships = []
  array.map do |item|
    @relationships << if item.is_a?(Relationship)
                        item.to_hash[:data]
                      else
                        Relationship.new(item[:type], item[:id]).to_hash[:data] end
  end
  RelationshipArray.new(@relationships).to_hash
end

Instance Method Details

#to_hashObject



14
15
16
# File 'lib/unit/types/relationship_array.rb', line 14

def to_hash
  { "data": data }
end