Class: ObjectJSONMapper::Associations::Association Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/object_json_mapper/associations/association.rb

Overview

This class is abstract.

Base class for association builders

Direct Known Subclasses

HasMany, HasOne

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Association

Returns a new instance of Association.

Parameters:

  • name (Symbol)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :klass (Object)
  • :endpoint (String)
  • :params (Hash)


14
15
16
17
18
19
# File 'lib/object_json_mapper/associations/association.rb', line 14

def initialize(name, options = {})
  @name     = name
  @klass    = options.fetch(:class_name, name)
  @endpoint = options.fetch(:endpoint, name)
  @params   = options.fetch(:params, {})
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/object_json_mapper/associations/association.rb', line 7

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'lib/object_json_mapper/associations/association.rb', line 7

def params
  @params
end

Instance Method Details

#callObject

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/object_json_mapper/associations/association.rb', line 21

def call(*)
  raise NotImplementedError
end

#endpointObject



31
32
33
# File 'lib/object_json_mapper/associations/association.rb', line 31

def endpoint
  @endpoint.to_s.underscore
end

#klassObject



25
26
27
28
29
# File 'lib/object_json_mapper/associations/association.rb', line 25

def klass
  return @klass.to_s.classify.constantize if @klass.is_a?(Symbol)

  @klass
end