File: pebble.rb

package info (click to toggle)
ruby-naught 1.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 276 kB
  • sloc: ruby: 1,091; makefile: 6
file content (33 lines) | stat: -rw-r--r-- 986 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'naught/null_class_builder/command'

module Naught
  class NullClassBuilder
    module Commands
      class Pebble < ::Naught::NullClassBuilder::Command
        def initialize(builder, output = $stdout)
          @builder = builder
          @output = output
        end

        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
      end
    end
  end
end