Class: Agrippa::Proxy

Inherits:
BasicObject
Includes:
Methods
Defined in:
lib/agrippa/proxy.rb

Direct Known Subclasses

Maybe, State

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Methods

included, name

Constructor Details

#initialize(value, *methods) ⇒ Proxy

Returns a new instance of Proxy.



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

def initialize(value, *methods)
    @value, @proxied_methods = value, {}
    __build_method_lookup_table(value, methods.flatten)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



48
49
50
51
# File 'lib/agrippa/proxy.rb', line 48

def method_missing(method, *args, &block)
    ::Kernel.raise(::NoMethodError,
        "Implement method_missing in a subclass.")
end

Instance Attribute Details

#proxied_methodsObject (readonly)

Returns the value of attribute proxied_methods.



12
13
14
# File 'lib/agrippa/proxy.rb', line 12

def proxied_methods
  @proxied_methods
end

Instance Method Details

#_Object



23
24
25
# File 'lib/agrippa/proxy.rb', line 23

def _
    @value
end

#__set_proxied_methods(lookup_hash) ⇒ Object



53
54
55
56
# File 'lib/agrippa/proxy.rb', line 53

def __set_proxied_methods(lookup_hash)
    @proxied_methods = lookup_hash
    self
end

#_deep_valueObject



27
28
29
30
# File 'lib/agrippa/proxy.rb', line 27

def _deep_value
    return(@value) unless @value.respond_to?(:_value)
    @value._value
end

#_valueObject



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

def _value
    @value
end

#is_a?(klass) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/agrippa/proxy.rb', line 39

def is_a?(klass)
    @value.is_a?(klass) || (klass == ::Agrippa::Proxy)
end

#proxied_method?(method) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
# File 'lib/agrippa/proxy.rb', line 43

def proxied_method?(method)
    @proxied_methods.empty? \
        or @proxied_methods.has_key?(method.to_sym)
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
# File 'lib/agrippa/proxy.rb', line 32

def respond_to?(method, include_private = false)
    return(true) if (method == :_value)
    return(true) if (method == :proxied_methods)
    return(true) if (method == :proxied_method?)
    @value.respond_to?(method, include_private)
end