Class: Chartio::ForeignKeyRelationship

Inherits:
Object
  • Object
show all
Defined in:
lib/chartio/foreign_key_relationship.rb

Constant Summary collapse

FIELDS =
[
  :parent_table, :parent_primary_key, :child_table,
  :child_foreign_key, :polymorphic_field
]

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ForeignKeyRelationship

Returns a new instance of ForeignKeyRelationship.



11
12
13
14
15
# File 'lib/chartio/foreign_key_relationship.rb', line 11

def initialize(*args)
  args.each_with_index do |ele, index|
    instance_variable_set("@#{FIELDS[index]}", ele)
  end
end

Instance Method Details

#to_aObject



17
18
19
# File 'lib/chartio/foreign_key_relationship.rb', line 17

def to_a
  FIELDS.map { |x| self.send(x) }
end

#to_hObject



21
22
23
24
25
26
# File 'lib/chartio/foreign_key_relationship.rb', line 21

def to_h
  FIELDS.inject({}) do |hash, element|
    hash[element] = self.send(element)
    hash
  end
end