Sha256: 1f29250ab92ce1f7b133cffcd1be852ef227c35ba9dae46154b9136e174c3ee8

Contents?: true

Size: 646 Bytes

Versions: 19

Compression:

Stored size: 646 Bytes

Contents

module Pupa
  # A minimal model for a foreign object.
  class ForeignObject
    extend Forwardable
    include Concerns::IndifferentAccess

    attr_reader :attributes, :foreign_keys

    def_delegators :@attributes, :[], :[]=

    def initialize(properties = {})
      hash = symbolize_keys(properties)
      value = hash.delete(:foreign_keys) || {}
      @attributes = hash.merge(value)
      @foreign_keys = value.keys
    end

    def to_h
      {}.tap do |hash|
        attributes.each do |property,value|
          if value == false || value.present?
            hash[property] = value
          end
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
pupa-0.2.4 lib/pupa/models/foreign_object.rb
pupa-0.2.3 lib/pupa/models/foreign_object.rb
pupa-0.2.2 lib/pupa/models/foreign_object.rb
pupa-0.2.1 lib/pupa/models/foreign_object.rb
pupa-0.2.0 lib/pupa/models/foreign_object.rb
pupa-0.1.11 lib/pupa/models/foreign_object.rb
pupa-0.1.10 lib/pupa/models/foreign_object.rb
pupa-0.1.9 lib/pupa/models/foreign_object.rb
pupa-0.1.8 lib/pupa/models/foreign_object.rb
pupa-0.1.7 lib/pupa/models/foreign_object.rb
pupa-0.1.6 lib/pupa/models/foreign_object.rb
pupa-0.1.5 lib/pupa/models/foreign_object.rb
pupa-0.1.4 lib/pupa/models/foreign_object.rb
pupa-0.1.3 lib/pupa/models/foreign_object.rb
pupa-0.1.2 lib/pupa/models/foreign_object.rb
pupa-0.1.1 lib/pupa/models/foreign_object.rb
pupa-0.1.0 lib/pupa/models/foreign_object.rb
pupa-0.0.13 lib/pupa/models/foreign_object.rb
pupa-0.0.12 lib/pupa/models/foreign_object.rb