Class: Proxen::Proxy
- Inherits:
-
Object
- Object
- Proxen::Proxy
- Defined in:
- lib/proxen.rb
Class Method Summary collapse
Instance Method Summary collapse
- #blankify! ⇒ Object
- #handle(instance, sym, *args, &block) ⇒ Object
-
#initialize(klass, *args) ⇒ Proxy
constructor
A new instance of Proxy.
Constructor Details
#initialize(klass, *args) ⇒ Proxy
Returns a new instance of Proxy.
22 23 24 25 26 27 28 |
# File 'lib/proxen.rb', line 22 def initialize(klass, *args) @klass = klass @options = args.last.is_a?(Hash) ? args.pop : {} @targets = Array(args).flatten blankify! if @options[:blank_slate] end |
Class Method Details
.add(klass, *args) ⇒ Object
4 5 6 |
# File 'lib/proxen.rb', line 4 def add(klass, *args) store[klass] = new(klass, *args) end |
.handle(instance, sym, *args, &block) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/proxen.rb', line 8 def handle(instance, sym, *args, &block) klass = Object.instance_method(:class).bind(instance).call if proxy = store[klass] proxy.handle(instance, sym, *args, &block) end end |
Instance Method Details
#blankify! ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/proxen.rb', line 42 def blankify! @klass.class_eval do instance_methods.each do |sym| undef_method(sym) unless sym.to_s =~ /__/ end end end |
#handle(instance, sym, *args, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/proxen.rb', line 30 def handle(instance, sym, *args, &block) if target = target_for(instance, sym) sym = sym.to_s[0..-2] # Delete ! if @options[:compile] compile(target, sym) instance.__send__(sym, *args, &block) else instance.__send__(target).__send__(sym, *args, &block) end end end |