Class: JsonApiResource::Associations::Base

Inherits:
Object
  • Object
show all
Includes:
Errors
Defined in:
lib/json_api_resource/associations/base.rb

Direct Known Subclasses

BelongsTo, HasMany, HasManyPrefetched, HasOne

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(associated_class, name, opts = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/json_api_resource/associations/base.rb', line 7

def initialize(associated_class, name, opts = {})
  self.name   = name.to_sym
  self.root   = associated_class
  @opts       = opts.merge( skip_pagination: true )
  
  self.action = @opts.delete :action       do default_action end
  self.key    = @opts.delete :foreign_key  do server_key end

  self.key    = self.key.try :to_sym
  validate_options
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



5
6
7
# File 'lib/json_api_resource/associations/base.rb', line 5

def action
  @action
end

#keyObject

Returns the value of attribute key.



5
6
7
# File 'lib/json_api_resource/associations/base.rb', line 5

def key
  @key
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/json_api_resource/associations/base.rb', line 5

def name
  @name
end

#rootObject

Returns the value of attribute root.



5
6
7
# File 'lib/json_api_resource/associations/base.rb', line 5

def root
  @root
end

Instance Method Details

#callable?(root_insatnce) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/json_api_resource/associations/base.rb', line 27

def callable?( root_insatnce )
  raise NotImplementedError
end

#default_nilObject

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/json_api_resource/associations/base.rb', line 31

def default_nil
  raise NotImplementedError
end

#klassObject

klass has to be lazy initted for circular dependencies



36
37
38
39
40
41
# File 'lib/json_api_resource/associations/base.rb', line 36

def klass
  @klass ||= begin
    klass = @opts.delete(:class_name).try :constantize
    klass || @opts.delete( :class ) do derived_class end
  end
end

#optsObject



47
48
49
# File 'lib/json_api_resource/associations/base.rb', line 47

def opts
  @opts.except *ASSOCIATION_OPTS
end

#post_process(value) ⇒ Object



43
44
45
# File 'lib/json_api_resource/associations/base.rb', line 43

def post_process( value )
  value
end

#query(root_insatnce) ⇒ Object

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/json_api_resource/associations/base.rb', line 23

def query( root_insatnce )
  raise NotImplementedError
end

#typeObject

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/json_api_resource/associations/base.rb', line 19

def type
  raise NotImplementedError
end