Module: Verbosify

Included in:
AutoObject, VerboseObject
Defined in:
lib/verbose_object.rb

Overview

Author

Nicolas Pouillard <[email protected]>.

Copyright

Copyright © 2005 Nicolas Pouillard. All rights reserved.

License

GNU General Public License (GPL).

Revision

$Id: /w/fey/ruby_ex/trunk/lib/verbose_object.rb 21865 2006-02-18T17:13:28.680350Z pouillar $

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *a, &b) ⇒ Object



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

def method_missing ( m, *a, &b )
  super($1.to_sym) if m.to_s =~ /^__blank_slate_(.+)/
  verbose_object_method_missing(m, *a, &b)
end

Instance Attribute Details

#verbose_object_optionsObject

Returns the value of attribute verbose_object_options.



9
10
11
# File 'lib/verbose_object.rb', line 9

def verbose_object_options
  @verbose_object_options
end

#verbose_object_referenceObject

Returns the value of attribute verbose_object_reference.



8
9
10
# File 'lib/verbose_object.rb', line 8

def verbose_object_reference
  @verbose_object_reference
end

Instance Method Details

#initialize(anObject, opts = nil) ⇒ Object



11
12
13
14
# File 'lib/verbose_object.rb', line 11

def initialize ( anObject, opts=nil )
  @verbose_object_reference = anObject
  self.verbose_object_options = opts
end

#verbose_object?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/verbose_object.rb', line 31

def verbose_object?
  true
end

#verbose_object_empty_trace(action) ⇒ Object



73
74
75
# File 'lib/verbose_object.rb', line 73

def verbose_object_empty_trace ( action )
  inspect # FIXME
end

#verbose_object_method_missing(m, *a, &b) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/verbose_object.rb', line 48

def verbose_object_method_missing ( m, *a, &b )
  begin
    @verbose_object_options[:logger].log(self, m, *a)
  rescue NoMethodError => ex
    STDERR.puts "No valid logger (#{m}) (#{ex})"
  end
  res = verbose_object_send(m, *a, &b)
  return res if @verbose_object_options[:no_rec]
  call = MethodCall.new(m, *a, &b)
  opts = @verbose_object_options.merge(:call => call, :last => self)
  res.verbosify(opts)
end

#verbose_object_send(m, *a, &b) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/verbose_object.rb', line 35

def verbose_object_send ( m, *a, &b )
  if @verbose_object_reference.nil?
    __send__("__blank_slate_#{m}", *a, &b)
  else
    @verbose_object_reference.__send__(m, *a, &b)
  end
end

#verbose_object_trace(action = nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/verbose_object.rb', line 61

def verbose_object_trace ( action=nil )
  call = @verbose_object_options[:call]
  last = @verbose_object_options[:last]
  return verbose_object_empty_trace(action) if call.nil?
  if last.__blank_slate_eql? self
    last = verbose_object_empty_trace(action)
  else
    last = last.verbose_object_trace(action)
  end
  call.to_ruby(last)
end