Class: Pupa::ForeignObject

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Concerns::IndifferentAccess
Defined in:
lib/pupa/models/foreign_object.rb

Overview

A minimal model for a foreign object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(properties = {}) ⇒ ForeignObject

Returns a new instance of ForeignObject.



11
12
13
14
15
16
# File 'lib/pupa/models/foreign_object.rb', line 11

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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



7
8
9
# File 'lib/pupa/models/foreign_object.rb', line 7

def attributes
  @attributes
end

#foreign_keysObject (readonly)

Returns the value of attribute foreign_keys.



7
8
9
# File 'lib/pupa/models/foreign_object.rb', line 7

def foreign_keys
  @foreign_keys
end

Instance Method Details

#to_hObject



18
19
20
21
22
23
24
25
26
# File 'lib/pupa/models/foreign_object.rb', line 18

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