Module: JsonApiClient::Helpers::Associable::ClassMethods

Defined in:
lib/json_api_client/helpers/associable.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to_associationsObject



18
19
20
# File 'lib/json_api_client/helpers/associable.rb', line 18

def belongs_to_associations
  associations.select{|association| association.is_a?(Associations::BelongsTo::Association) }
end

#path(params = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/json_api_client/helpers/associable.rb', line 30

def path(params = nil)
  parts = [table_name]
  if params
    slurp = params.slice(*prefix_params)
    prefix_params.each do |param|
      params.delete(param)
    end
    parts.unshift(prefix_path % slurp)
  else
    parts.unshift(prefix_path)
  end
  parts.reject!{|part| part == "" }
  File.join(*parts)
rescue KeyError
  raise ArgumentError, "Not all prefix parameters specified"
end

#prefix_paramsObject



22
23
24
# File 'lib/json_api_client/helpers/associable.rb', line 22

def prefix_params
  belongs_to_associations.map(&:param)
end

#prefix_pathObject



26
27
28
# File 'lib/json_api_client/helpers/associable.rb', line 26

def prefix_path
  belongs_to_associations.map(&:to_prefix_path).join("/")
end