Class: AttrJson::Associations::Association::Base

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

Direct Known Subclasses

BelongsTo, HasCollection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, args, options = {}) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/attr_json/associations/association/base.rb', line 9

def initialize(owner, args, options = {})
  @owner = owner
  @name = args[0]
  @scope = args[1]
  @options = options

  @class_name = resolve(:class_name)
  @klass = @class_name.constantize
  @primary_key = resolve(:primary_key)
  @foreign_key = resolve(:foreign_key)
end

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name.



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

def class_name
  @class_name
end

#foreign_keyObject

Returns the value of attribute foreign_key.



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

def foreign_key
  @foreign_key
end

#klassObject

Returns the value of attribute klass.



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

def klass
  @klass
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/attr_json/associations/association/base.rb', line 6

def name
  @name
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/attr_json/associations/association/base.rb', line 6

def options
  @options
end

#ownerObject

Returns the value of attribute owner.



6
7
8
# File 'lib/attr_json/associations/association/base.rb', line 6

def owner
  @owner
end

#primary_keyObject

Returns the value of attribute primary_key.



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

def primary_key
  @primary_key
end

#scopeObject

Returns the value of attribute scope.



6
7
8
# File 'lib/attr_json/associations/association/base.rb', line 6

def scope
  @scope
end

Instance Method Details

#scopedObject



21
22
23
24
25
26
27
# File 'lib/attr_json/associations/association/base.rb', line 21

def scoped
  if @scope
    @klass.all.instance_exec(&@scope)
  else
    @klass.all
  end
end