Sha256: 504c94eebafcaff8864398464db115bad6ac0a4ca426e3d0cf7601bcbb86dd04

Contents?: true

Size: 496 Bytes

Versions: 2

Compression:

Stored size: 496 Bytes

Contents

module ActiverecordToPoro
  class Metadata
    attr_accessor :primary_key_column, :primary_key_value


    def initialize_from_ar(ar_object=nil)
      unless ar_object.nil?
        set_primary_key(ar_object)
      end
    end

    def set_primary_key(ar_object)
      self.primary_key_column = ar_object.class.primary_key
      self.primary_key_value = ar_object.send(self.primary_key_column)
    end

    def to_hash
      { self.primary_key_column => self.primary_key_value }
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activerecord_to_poro-0.0.2 lib/activerecord_to_poro/metadata.rb
activerecord_to_poro-0.0.1 lib/activerecord_to_poro/metadata.rb