Class: JsonApiClient::Relationships::TopLevelRelations

Inherits:
Object
  • Object
show all
Defined in:
lib/json_api_client/relationships/top_level_relations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record_class, relations) ⇒ TopLevelRelations

Returns a new instance of TopLevelRelations.



7
8
9
10
# File 'lib/json_api_client/relationships/top_level_relations.rb', line 7

def initialize(record_class, relations)
  @relations = relations
  @record_class = record_class
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/json_api_client/relationships/top_level_relations.rb', line 16

def method_missing(method, *args)
  if respond_to_missing?(method)
    fetch_relation(method)
  else
    super
  end
end

Instance Attribute Details

#record_classObject (readonly)

Returns the value of attribute record_class.



5
6
7
# File 'lib/json_api_client/relationships/top_level_relations.rb', line 5

def record_class
  @record_class
end

#relationsObject (readonly)

Returns the value of attribute relations.



5
6
7
# File 'lib/json_api_client/relationships/top_level_relations.rb', line 5

def relations
  @relations
end

Instance Method Details

#fetch_relation(relation_name) ⇒ Object



24
25
26
27
# File 'lib/json_api_client/relationships/top_level_relations.rb', line 24

def fetch_relation(relation_name)
  link_definition = relations.fetch(relation_name.to_s)
  record_class.requestor.linked(link_definition)
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/json_api_client/relationships/top_level_relations.rb', line 12

def respond_to_missing?(method, include_private = false)
  relations.has_key?(method.to_s) || super
end