Class: Apia::Object

Inherits:
Object
  • Object
show all
Extended by:
Defineable
Defined in:
lib/apia/object.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Defineable

create, inspect, method_missing, name, respond_to_missing?

Constructor Details

#initialize(value) ⇒ Apia::Object

Initialize an instance of this type with the value provided

Parameters:



38
39
40
# File 'lib/apia/object.rb', line 38

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject, Hash (readonly)

Return the raw value object for this type

Returns:



45
46
47
# File 'lib/apia/object.rb', line 45

def value
  @value
end

Class Method Details

.collate_objects(set) ⇒ void

This method returns an undefined value.

Collate all objects that this type references and add them to the given object set

Parameters:



26
27
28
29
30
# File 'lib/apia/object.rb', line 26

def collate_objects(set)
  definition.fields.each_value do |field|
    set.add_object(field.type.klass) if field.type.usable_for_field?
  end
end

.definitionApia::Definitions::Object

Return the definition for this type



17
18
19
# File 'lib/apia/object.rb', line 17

def definition
  @definition ||= Definitions::Object.new(Helpers.class_name_to_id(name))
end

Instance Method Details

#hash(request: nil, path: []) ⇒ Hash

Generate a hash based on the fields defined in this type

Parameters:

  • request (Apia::Request) (defaults to: nil)

    the associated request

Returns:

  • (Hash)


51
52
53
# File 'lib/apia/object.rb', line 51

def hash(request: nil, path: [])
  self.class.definition.fields.generate_hash(@value, object: self, request: request, path: path)
end

#include?(request) ⇒ Boolean

Should this type be included in any output?

Parameters:

Returns:

  • (Boolean)


59
60
61
62
63
64
65
# File 'lib/apia/object.rb', line 59

def include?(request)
  return true if self.class.definition.conditions.empty?

  self.class.definition.conditions.all? do |cond|
    cond.call(@value, request) == true
  end
end