| Class | ActiveLdap::Association::Proxy |
| In: |
lib/active_ldap/association/proxy.rb
|
| Parent: | Object |
| respond_to? | -> | proxy_respond_to? |
| extend | -> | proxy_extend |
# File lib/active_ldap/association/proxy.rb, line 8
8: def initialize(owner, options)
9: @owner = owner
10: @options = options
11: reset
12: extend(options[:extend]) if options[:extend]
13: end
# File lib/active_ldap/association/proxy.rb, line 20
20: def ===(other)
21: load_target and other === @target
22: end
# File lib/active_ldap/association/proxy.rb, line 51
51: def exists?
52: load_target
53: not @target.nil?
54: end
# File lib/active_ldap/association/proxy.rb, line 29
29: def reload
30: reset
31: load_target
32: end
# File lib/active_ldap/association/proxy.rb, line 24
24: def reset
25: @target = nil
26: @loaded = false
27: end
# File lib/active_ldap/association/proxy.rb, line 15
15: def respond_to?(symbol, include_priv=false)
16: proxy_respond_to?(symbol, include_priv) or
17: (load_target && @target.respond_to?(symbol, include_priv))
18: end
# File lib/active_ldap/association/proxy.rb, line 46
46: def target=(target)
47: @target = target
48: loaded
49: end
# File lib/active_ldap/association/proxy.rb, line 93
93: def find_options(options={})
94: if @owner.connection != @owner.class.connection
95: {:connection => @owner.connection}.merge(options)
96: else
97: options
98: end
99: end
# File lib/active_ldap/association/proxy.rb, line 62
62: def foreign_class
63: klass = @owner.class.associated_class(@options[:association_id])
64: klass = @owner.class.module_eval(klass) if klass.is_a?(String)
65: klass
66: end
# File lib/active_ldap/association/proxy.rb, line 76
76: def foreign_key
77: @options[:foreign_key_name] || foreign_class.dn_attribute
78: end
# File lib/active_ldap/association/proxy.rb, line 101
101: def infect_connection(target)
102: conn = @owner.instance_variable_get("@connection")
103: target.connection = conn if conn
104: end
# File lib/active_ldap/association/proxy.rb, line 80
80: def load_target
81: if !@owner.new_entry? or have_foreign_key?
82: begin
83: @target = find_target unless loaded?
84: rescue EntryNotFound
85: reset
86: end
87: end
88:
89: loaded if target
90: target
91: end
# File lib/active_ldap/association/proxy.rb, line 57
57: def method_missing(method, *args, &block)
58: load_target
59: @target.send(method, *args, &block)
60: end