Class: ActiveLdap::Association::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/active_ldap/association/proxy.rb

Direct Known Subclasses

BelongsTo, Collection

Instance Method Summary collapse

Constructor Details

#initialize(owner, options) ⇒ Proxy

Returns a new instance of Proxy.



7
8
9
10
11
12
# File 'lib/active_ldap/association/proxy.rb', line 7

def initialize(owner, options)
  @owner = owner
  @options = options
  extend(options[:extend]) if options[:extend]
  reset
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



56
57
58
59
# File 'lib/active_ldap/association/proxy.rb', line 56

def method_missing(method, *args, &block)
  load_target
  @target.send(method, *args, &block)
end

Instance Method Details

#===(other) ⇒ Object



19
20
21
# File 'lib/active_ldap/association/proxy.rb', line 19

def ===(other)
  load_target and other === @target
end

#exists?Boolean

Returns:

  • (Boolean)


50
51
52
53
# File 'lib/active_ldap/association/proxy.rb', line 50

def exists?
  load_target
  not @target.nil?
end

#loadedObject



37
38
39
# File 'lib/active_ldap/association/proxy.rb', line 37

def loaded
  @loaded = true
end

#loaded?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/active_ldap/association/proxy.rb', line 33

def loaded?
  @loaded
end

#proxy_respond_to?Object



4
# File 'lib/active_ldap/association/proxy.rb', line 4

alias_method :proxy_respond_to?, :respond_to?

#reloadObject



28
29
30
31
# File 'lib/active_ldap/association/proxy.rb', line 28

def reload
  reset
  load_target
end

#resetObject



23
24
25
26
# File 'lib/active_ldap/association/proxy.rb', line 23

def reset
  @target = nil
  @loaded = false
end

#respond_to?(symbol, include_priv = false) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/active_ldap/association/proxy.rb', line 14

def respond_to?(symbol, include_priv=false)
  proxy_respond_to?(symbol, include_priv) or
    (load_target && @target.respond_to?(symbol, include_priv))
end

#targetObject



41
42
43
# File 'lib/active_ldap/association/proxy.rb', line 41

def target
  @target
end

#target=(target) ⇒ Object



45
46
47
48
# File 'lib/active_ldap/association/proxy.rb', line 45

def target=(target)
  @target = target
  loaded
end