Class: Naught::NullClassBuilder::Commands::Pebble

Inherits:
Naught::NullClassBuilder::Command show all
Defined in:
lib/naught/null_class_builder/commands/pebble.rb

Instance Attribute Summary

Attributes inherited from Naught::NullClassBuilder::Command

#builder

Instance Method Summary collapse

Methods inherited from Naught::NullClassBuilder::Command

#defer

Constructor Details

#initialize(builder, output = $stdout) ⇒ Pebble

Returns a new instance of Pebble.



7
8
9
10
# File 'lib/naught/null_class_builder/commands/pebble.rb', line 7

def initialize(builder, output = $stdout)
  @builder = builder
  @output = output
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/naught/null_class_builder/commands/pebble.rb', line 12

def call
  defer do |subject|
    subject.module_exec(@output) do |output|
      define_method(:method_missing) do |method_name, *args|
        pretty_args = args.collect(&:inspect).join(', ').tr("\"", "'")
        output.puts "#{method_name}(#{pretty_args}) from #{parse_caller}"
        self
      end

      def parse_caller
        caller = Kernel.caller(2).first
        method_name = caller.match(/\`([\w\s]+(\(\d+\s\w+\))?[\w\s]*)/)
        method_name ? method_name[1] : caller
      end
      private :parse_caller
    end
  end
end