Class: Delighted::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/delighted/resource.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Resource

Returns a new instance of Resource.



20
21
22
23
24
# File 'lib/delighted/resource.rb', line 20

def initialize(attributes = {})
  @id = attributes[:id]
  define_id_reader if @id
  build_from_attributes(attributes)
end

Class Attribute Details

.expandable_attributesObject



7
8
9
# File 'lib/delighted/resource.rb', line 7

def expandable_attributes
  @expandable_attributes ||= {}
end

.pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/delighted/resource.rb', line 4

def path
  @path
end

.singleton_resource=(value) ⇒ Object (writeonly)

Sets the attribute singleton_resource

Parameters:

  • value

    the value to set the attribute singleton_resource to.



5
6
7
# File 'lib/delighted/resource.rb', line 5

def singleton_resource=(value)
  @singleton_resource = value
end

Class Method Details

.singleton_resource?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/delighted/resource.rb', line 11

def singleton_resource?
  !!@singleton_resource
end

Instance Method Details

#to_hashObject Also known as: to_h

Attributes used for serialization



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/delighted/resource.rb', line 27

def to_hash
  serialized_attributes = attributes.dup

  self.class.expandable_attributes.each_pair.select do |attribute_name, expanded_class|
    if expanded_class === attributes[attribute_name]
      serialized_attributes[attribute_name] = serialized_attributes[attribute_name].id
    end
  end

  serialized_attributes
end