Class: Lazy

Inherits:
Object
  • Object
show all
Defined in:
lib/audit/lib/lazy.rb

Overview

To change this template, choose Tools | Templates and open the template in the editor.

Instance Method Summary collapse

Constructor Details

#initialize(obj, eval_method, *eval_args, &eval_block) ⇒ Lazy

Returns a new instance of Lazy.



5
6
7
8
9
10
11
12
13
# File 'lib/audit/lib/lazy.rb', line 5

def initialize(obj, eval_method, *eval_args, &eval_block)
  @obj = obj
  @eval_method = eval_method
  @eval_args = *eval_args
  @eval_block = eval_block

  #debugging
  raise "Object #{@obj.class.name} does not contain method #{@eval_method}" unless @obj.methods.include? @eval_method
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



15
16
17
18
# File 'lib/audit/lib/lazy.rb', line 15

def method_missing(method, *args, &block)
  @evaluated = @obj.send(@eval_method, *@eval_args, &@eval_block) if @evaluated.nil?
  @evaluated.send(method, *args, &block)
end

Instance Method Details

#debug_lazyObject



30
31
32
# File 'lib/audit/lib/lazy.rb', line 30

def debug_lazy()
  return [@obj, @eval_method, @eval_args, @eval_block]
end

#getObject



34
35
36
# File 'lib/audit/lib/lazy.rb', line 34

def get()
 return @obj
end

#methodsObject



25
26
27
28
# File 'lib/audit/lib/lazy.rb', line 25

def methods()
  @evaluated = @obj.send(@eval_method, *@eval_args, &@eval_block) if @evaluated.nil?
  return @evaluated.methods()
end

#to_yaml(opts = {}) ⇒ Object



20
21
22
23
# File 'lib/audit/lib/lazy.rb', line 20

def to_yaml(opts = {})
  @evaluated = @obj.send(@eval_method, *@eval_args, &@eval_block) if @evaluated.nil?
  return @evaluated.to_yaml(opts)
end