Class: ReeDao::Associations

Inherits:
Object
  • Object
show all
Includes:
Ree::LinkDSL, AssociationMethods
Defined in:
lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AssociationMethods

extended, included

Constructor Details

#initialize(agg_caller, list, local_vars, parent_dao, autoload_children = false, **opts) ⇒ Associations

Returns a new instance of Associations.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb', line 8

def initialize(agg_caller, list, local_vars, parent_dao, autoload_children = false, **opts)
  @agg_caller = agg_caller
  @list = list
  @local_vars = local_vars
  @global_opts = opts || {}
  @only = opts[:only] if opts[:only]
  @except = opts[:except] if opts[:except]
  @parent_dao = parent_dao
  @autoload_children = autoload_children

  if @only && @except
    shared_keys = @only.intersection(@except)

    if shared_keys.size > 0
      raise ArgumentError.new("you can't use both :only and :except for #{shared_keys.map { "\"#{_1}\"" }.join(", ")} keys")
    end
  end

  if !self.class.sync_mode?
    @assoc_threads = []
    @field_threads = []
  end

  local_vars.each do |k, v|
    instance_variable_set(k, v)

    self.class.define_method k.to_s.gsub('@', '') do
      v
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



149
150
151
152
153
# File 'lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb', line 149

def method_missing(method, *args, &block)
  return super if !agg_caller.private_methods(false).include?(method)

  agg_caller.send(method, *args, &block)
end

Instance Attribute Details

#agg_callerObject (readonly)

Returns the value of attribute agg_caller.



6
7
8
# File 'lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb', line 6

def agg_caller
  @agg_caller
end

#autoload_childrenObject (readonly)

Returns the value of attribute autoload_children.



6
7
8
# File 'lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb', line 6

def autoload_children
  @autoload_children
end

#exceptObject (readonly)

Returns the value of attribute except.



6
7
8
# File 'lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb', line 6

def except
  @except
end

#global_optsObject (readonly)

Returns the value of attribute global_opts.



6
7
8
# File 'lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb', line 6

def global_opts
  @global_opts
end

#listObject (readonly)

Returns the value of attribute list.



6
7
8
# File 'lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb', line 6

def list
  @list
end

#local_varsObject (readonly)

Returns the value of attribute local_vars.



6
7
8
# File 'lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb', line 6

def local_vars
  @local_vars
end

#onlyObject (readonly)

Returns the value of attribute only.



6
7
8
# File 'lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb', line 6

def only
  @only
end

#parent_daoObject (readonly)

Returns the value of attribute parent_dao.



6
7
8
# File 'lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb', line 6

def parent_dao
  @parent_dao
end

Class Method Details

.sync_mode?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb', line 40

def self.sync_mode?
  ReeDao.load_sync_associations_enabled?
end

Instance Method Details

#belongs_to(assoc_name, __opts = nil, &block) ⇒ Object



49
50
51
# File 'lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb', line 49

def belongs_to(assoc_name, __opts = nil, &block)
  association(__method__, assoc_name, __opts, &block)
end

#field(assoc_name, proc) ⇒ Object



72
73
74
# File 'lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb', line 72

def field(assoc_name, proc)
  association(__method__, assoc_name, proc)
end

#has_many(assoc_name, __opts = nil, &block) ⇒ Object



67
68
69
# File 'lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb', line 67

def has_many(assoc_name, __opts = nil, &block)
  association(__method__, assoc_name, __opts, &block)
end

#has_one(assoc_name, __opts = nil, &block) ⇒ Object



58
59
60
# File 'lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb', line 58

def has_one(assoc_name, __opts = nil, &block)
  association(__method__, assoc_name, __opts, &block)
end