Class: Axel::Associations::Base

Inherits:
Object
  • Object
show all
Defined in:
app/models/axel/associations/base.rb

Direct Known Subclasses

BelongsTo, HasMany, HasOne

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, relation_name, options) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
# File 'app/models/axel/associations/base.rb', line 8

def initialize(model, relation_name, options)
  self.model = model
  self.relation_name = relation_name.to_s
  self.options = options || {}
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



4
5
6
# File 'app/models/axel/associations/base.rb', line 4

def model
  @model
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'app/models/axel/associations/base.rb', line 6

def options
  @options
end

#relation_nameObject

Returns the value of attribute relation_name.



5
6
7
# File 'app/models/axel/associations/base.rb', line 5

def relation_name
  @relation_name
end

Instance Method Details

#handles_method?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/models/axel/associations/base.rb', line 14

def handles_method?(method_name)
  matchers.any? { |matcher| method_name.to_s.match(matcher) }
end

#run_method(instance, method_name, *args, &block) ⇒ Object



18
19
20
21
22
23
24
# File 'app/models/axel/associations/base.rb', line 18

def run_method(instance, method_name, *args, &block)
  if included?
    included_getter(instance, *args, &block)
  else
    method_chooser(method_name)[instance, *args, &block]
  end
end