Module: ActivePresenter::ProxyMethods

Defined in:
lib/proxy.rb

Overview

Proxy

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/proxy.rb', line 50

def method_missing(sym, *args)
  syms = sym.to_s
  if syms.match(/.=$/)
    key = syms.chop
    gen_methods(key)
    self.send("#{key}=", args.from_args)
  else
    key = sym.to_s
    gen_methods(key)
    self.send("#{key}", args.from_args)
  end

end

Instance Method Details

#add_is_a(x) ⇒ Object



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

def add_is_a(x)
  @is_a_list << x
  @is_a_list.flatten!
  @is_a_list.uniq!
end

#create_method(name, &block) ⇒ Object



32
33
34
# File 'lib/proxy.rb', line 32

def create_method(name, &block)
  self.class.send(:define_method, name, &block)
end

#initialize(options = {}, is_a_list = []) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/proxy.rb', line 24

def initialize(options = {}, is_a_list = [])
  if !options.nil? && options.is_a?(Hash)
    options.each_pair {|k,v| self.send("#{k}=", v)}
  end
  @is_a_list = [ActivePresenter::Proxy]
  self.add_is_a(is_a_list)
end

#is_a?(x) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/proxy.rb', line 36

def is_a?(x)
  test_is_a?(x) ? true : super(x)
end

#kind_of?(x) ⇒ Boolean

Returns:

  • (Boolean)


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

def kind_of?(x)
  test_is_a?(x) ? true : super(x)
end