Class: ToCsv::Interceptor

Inherits:
Object
  • Object
show all
Defined in:
lib/to_csv/interceptor.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, block = nil) ⇒ Interceptor

Returns a new instance of Interceptor.



3
4
5
6
7
8
# File 'lib/to_csv/interceptor.rb', line 3

def initialize(object,block=nil) 
  @object = object
  @block  = block
  @result = []
  @method_audit = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



24
25
26
27
28
29
# File 'lib/to_csv/interceptor.rb', line 24

def method_missing(sym,*args,&block)
  @method_audit << sym
  result       = @object.send(sym,*args,&block)
  @result      << result
  result
end

Class Method Details

.from(object) ⇒ Object



10
11
12
# File 'lib/to_csv/interceptor.rb', line 10

def self.from(object)
  new(object)
end

Instance Method Details

#to_block(&block) ⇒ Object



14
15
16
17
# File 'lib/to_csv/interceptor.rb', line 14

def to_block(&block)
  @block = block
  self
end

#with_result {|@result, @method_audit| ... } ⇒ Object

Yields:

  • (@result, @method_audit)


19
20
21
22
# File 'lib/to_csv/interceptor.rb', line 19

def with_result
  instance_eval(&@block)
  yield @result, @method_audit
end