Class: Associationist::Associations::SingularAssociation

Inherits:
ActiveRecord::Associations::SingularAssociation
  • Object
show all
Defined in:
lib/associationist/associations/singular_association.rb

Instance Method Summary collapse

Instance Method Details

#association_scopeObject



4
5
6
7
8
9
10
# File 'lib/associationist/associations/singular_association.rb', line 4

def association_scope
  @_association_scope ||= if reflection.config.scope_proc
                            reflection.config.scope_proc.call(owner)
                          else
                            raise NotImplementedError
                          end
end

#find_targetObject



13
14
15
16
17
18
19
# File 'lib/associationist/associations/singular_association.rb', line 13

def find_target(async: false)
  if reflection.config.scope_proc
    super
  else
    reflection.config.loader_proc.call(owner) # TODO: use async load
  end
end

#find_target?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/associationist/associations/singular_association.rb', line 30

def find_target?
  !loaded?
end

#force_reload_readerObject



46
47
48
49
# File 'lib/associationist/associations/singular_association.rb', line 46

def force_reload_reader
  reload
  target
end

#klassObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/associationist/associations/singular_association.rb', line 34

def klass
  if reflection.config.scope_proc
    association_scope.klass
  else
    if reflection.config.class_name
      reflection.config.class_name.constantize
    else
      Object
    end
  end
end