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.



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

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

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

Instance Method Details

#===(other) ⇒ Object



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

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

#exists?Boolean

Returns:

  • (Boolean)


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

def exists?
  load_target
  not @target.nil?
end

#loadedObject



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

def loaded
  @loaded = true
end

#loaded?Boolean

Returns:

  • (Boolean)


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

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



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

def reload
  reset
  load_target
end

#resetObject



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

def reset
  @target = nil
  @loaded = false
end

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

Returns:

  • (Boolean)


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

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

#targetObject



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

def target
  @target
end

#target=(target) ⇒ Object



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

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