Sha256: 92940551eca6aaa7855cfed4fa96ef637146fbf7ed2306a0a16fa027094050d0

Contents?: true

Size: 543 Bytes

Versions: 3

Compression:

Stored size: 543 Bytes

Contents

module Chartio
  class ForeignKeyRelationship

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

    attr_accessor(*FIELDS)

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

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

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

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chartio-rails-0.1.0 lib/chartio/foreign_key_relationship.rb
chartio-rails-0.0.2 lib/chartio/foreign_key_relationship.rb
chartio-rails-0.0.1 lib/chartio/foreign_key_relationship.rb