cutter 0.8.6 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +150 -24
- data/lib/cutter/colored_outputs.rb +12 -4
- data/lib/cutter/inspection.rb +34 -36
- data/lib/cutter/stamper.rb +20 -7
- data/lib/cutter/version.rb +1 -1
- metadata +84 -61
    
        data/README.md
    CHANGED
    
    | @@ -2,6 +2,20 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            Two-methods-gem I use a lot for simple debugging & performance measuring purposes.
         | 
| 4 4 |  | 
| 5 | 
            +
            ```#inspect``` method shines when doing reverse engineering, it is especially useful, when it is needed to quickly hack on someone else's code. Also, it is very easy to become 'someone else' for self, when dealing with own code, if it was written very long time ago.
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Besides that ```#stamper``` allows doing some performance measuments in a handy manner, it can be used to create quick and neat demonstrations of how particular pieces of Ruby code perform. 
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            The one interesting possible usage of ```#stamper``` is to optimize performance of templates on Rails View layer, because it often takes a large (compared to M and C layers) load impact because of Rails lazy-evaluation mechanisms.
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            [](http://travis-ci.org/stanislaw/cutter)
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ## Prerequisites
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            It works on 1.8.7, 1.9.3, JRuby and Rubinius
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            ## Installiation
         | 
| 18 | 
            +
             | 
| 5 19 | 
             
            Include it into Gemfile:
         | 
| 6 20 |  | 
| 7 21 | 
             
            ```ruby
         | 
| @@ -10,14 +24,20 @@ group :development, :test do | |
| 10 24 | 
             
            end
         | 
| 11 25 | 
             
            ```
         | 
| 12 26 |  | 
| 13 | 
            -
            ##  | 
| 27 | 
            +
            ## Cutter::Inspection
         | 
| 28 | 
            +
            ### I) #inspect!
         | 
| 14 29 |  | 
| 15 | 
            -
            Insert  | 
| 30 | 
            +
            Insert ```#inspect!``` method into any of your methods:
         | 
| 16 31 |  | 
| 17 32 | 
             
            ```ruby
         | 
| 18 33 | 
             
              def your_method *your_args
         | 
| 19 34 | 
             
                # ...
         | 
| 35 | 
            +
                
         | 
| 20 36 | 
             
                inspect! {} # curly braces are important!    
         | 
| 37 | 
            +
                
         | 
| 38 | 
            +
                # or 
         | 
| 39 | 
            +
                # iii {} as an alias
         | 
| 40 | 
            +
                
         | 
| 21 41 | 
             
                # ...
         | 
| 22 42 | 
             
              end
         | 
| 23 43 |  | 
| @@ -30,12 +50,12 @@ Insert #inspect! method into any of your methods: | |
| 30 50 |  | 
| 31 51 | 
             
            It gives simple but nice trace for inspection: method's name and args that were passed to method.
         | 
| 32 52 |  | 
| 33 | 
            -
            With ```inspect!(:instance){}``` we also see instance variables:
         | 
| 53 | 
            +
            With ```inspect!(:instance) {}``` we also see instance variables:
         | 
| 34 54 |  | 
| 35 55 | 
             
            ```ruby
         | 
| 36 56 | 
             
              def your_method a, b 
         | 
| 37 57 | 
             
                @instance_var = "blip!"
         | 
| 38 | 
            -
                inspect!(:instance){}
         | 
| 58 | 
            +
                inspect!(:instance) {}
         | 
| 39 59 | 
             
              end
         | 
| 40 60 |  | 
| 41 61 | 
             
              # your_method 1, 2
         | 
| @@ -48,7 +68,7 @@ With ```inspect!(:instance){}``` we also see instance variables: | |
| 48 68 | 
             
              #     @instance_var: blip!
         | 
| 49 69 | 
             
            ```
         | 
| 50 70 |  | 
| 51 | 
            -
            With ```inspect!(:self){}``` we have self#inspect of class to which method belongs to:
         | 
| 71 | 
            +
            With ```inspect!(:self) {}``` we have ```self#inspect``` of class to which method belongs to:
         | 
| 52 72 |  | 
| 53 73 | 
             
            ```ruby  
         | 
| 54 74 | 
             
              def your_method name, *args
         | 
| @@ -68,12 +88,12 @@ With ```inspect!(:self){}``` we have self#inspect of class to which method belon | |
| 68 88 | 
             
              #     #<SelfInspectDemo:0x82be488 @variable="I'm variable">
         | 
| 69 89 | 
             
            ```
         | 
| 70 90 |  | 
| 71 | 
            -
            Option  | 
| 91 | 
            +
            Option ```:caller``` gives us caller methods chain:
         | 
| 72 92 |  | 
| 73 93 | 
             
            ```ruby  
         | 
| 74 94 | 
             
              def your_method name, *args
         | 
| 75 95 | 
             
                # ...
         | 
| 76 | 
            -
                inspect!(:caller)
         | 
| 96 | 
            +
                inspect!(:caller) {}
         | 
| 77 97 | 
             
              end
         | 
| 78 98 |  | 
| 79 99 | 
             
              # your_method(1,2,3,4,5) => 
         | 
| @@ -90,13 +110,11 @@ Option :caller gives us caller methods chain: | |
| 90 110 | 
             
              #     /home/stanislaw/.rvm/gems/ruby-1.9.2-p180@310/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:48:in `instance_eval'
         | 
| 91 111 | 
             
            ```
         | 
| 92 112 |  | 
| 93 | 
            -
            And finally ```inspect!(:max){}``` produces maximum information: options
         | 
| 94 | 
            -
            :instance, :self, :caller are included + Ruby's ordinary #inspect method
         | 
| 95 | 
            -
            is called on every variable.
         | 
| 113 | 
            +
            And finally ```inspect!(:max) {}``` produces maximum information: options ```:instance```, ```:self```, ```:caller``` are included and **Ruby's ordinary ```#inspect``` method is called on every variable**.
         | 
| 96 114 |  | 
| 97 115 | 
             
            ```ruby
         | 
| 98 116 | 
             
              def your_method *args
         | 
| 99 | 
            -
                inspect!(:max){}
         | 
| 117 | 
            +
                inspect!(:max) {}
         | 
| 100 118 | 
             
              end
         | 
| 101 119 |  | 
| 102 120 | 
             
              # maximal(1, :two, "three", :four => 5) =>
         | 
| @@ -117,7 +135,7 @@ is called on every variable. | |
| 117 135 | 
             
              #   ...
         | 
| 118 136 | 
             
            ```
         | 
| 119 137 |  | 
| 120 | 
            -
            If you want all  | 
| 138 | 
            +
            If you want all ```#inspect!``` methods fall silent at once, use
         | 
| 121 139 |  | 
| 122 140 | 
             
            ```ruby
         | 
| 123 141 | 
             
            Cutter::Inspection.quiet!
         | 
| @@ -129,27 +147,135 @@ To make them sound again do | |
| 129 147 | 
             
            Cutter::Inspection.loud!
         | 
| 130 148 | 
             
            ```
         | 
| 131 149 |  | 
| 132 | 
            -
             | 
| 150 | 
            +
            ### Three-letters methods
         | 
| 151 | 
            +
             | 
| 152 | 
            +
            ```ruby
         | 
| 153 | 
            +
            class Object
         | 
| 154 | 
            +
              def rrr object = nil
         | 
| 155 | 
            +
                raise object.inspect
         | 
| 156 | 
            +
              end
         | 
| 157 | 
            +
             | 
| 158 | 
            +
              def ppp object = nil
         | 
| 159 | 
            +
                puts object.inspect
         | 
| 160 | 
            +
              end
         | 
| 161 | 
            +
             | 
| 162 | 
            +
              def lll object = nil
         | 
| 163 | 
            +
                Rails.logger.info object.inspect
         | 
| 164 | 
            +
              end if defined? Rails
         | 
| 165 | 
            +
            end
         | 
| 166 | 
            +
            ```
         | 
| 167 | 
            +
             | 
| 168 | 
            +
            ### #iii
         | 
| 169 | 
            +
             | 
| 170 | 
            +
            Instead of ```#inspect!``` you can use ```#iii``` - just an alias more convenient for typing. Finally, you have a group of 4 three-letters methods in your every day debugging workflow.
         | 
| 171 | 
            +
             | 
| 172 | 
            +
            ## II) Cutter::Stamper
         | 
| 173 | 
            +
             | 
| 174 | 
            +
            Acts as ```benchmark {}``` in Rails or ```Benchmark.measure {}``` (common Ruby) but with stamps in any position in block executed.
         | 
| 175 | 
            +
             | 
| 176 | 
            +
            It is much simpler to write Stamper with Stamps than all these Measure-dos.
         | 
| 177 | 
            +
             | 
| 178 | 
            +
            ### Minimal stamper
         | 
| 179 | 
            +
             | 
| 180 | 
            +
            ```stamp!``` method is just an alias for ```stamp```, use whatever you like.
         | 
| 133 181 |  | 
| 134 182 | 
             
            ```ruby
         | 
| 135 | 
            -
             | 
| 136 | 
            -
             | 
| 183 | 
            +
            puts "Minimal stamper"
         | 
| 184 | 
            +
            stamper do |s|
         | 
| 185 | 
            +
              stamp
         | 
| 186 | 
            +
              sleep 0.2
         | 
| 187 | 
            +
              stamp!
         | 
| 188 | 
            +
              sleep 0.2
         | 
| 189 | 
            +
              stamp!
         | 
| 190 | 
            +
            end
         | 
| 191 | 
            +
            ```
         | 
| 192 | 
            +
             | 
| 193 | 
            +
            Will produce:
         | 
| 137 194 |  | 
| 138 | 
            -
             | 
| 195 | 
            +
            ```text
         | 
| 196 | 
            +
            Minimal stamper
         | 
| 139 197 |  | 
| 140 | 
            -
             | 
| 141 | 
            -
             | 
| 142 | 
            -
             | 
| 198 | 
            +
            no name
         | 
| 199 | 
            +
            -------
         | 
| 200 | 
            +
              stamp:       0 ms   
         | 
| 201 | 
            +
              stamp:     200 ms   
         | 
| 202 | 
            +
              stamp:     400 ms   
         | 
| 203 | 
            +
            -------
         | 
| 204 | 
            +
              400ms
         | 
| 205 | 
            +
            ```
         | 
| 143 206 |  | 
| 144 | 
            -
             | 
| 207 | 
            +
            ### Stamper with named stamps
         | 
| 145 208 |  | 
| 146 | 
            -
             | 
| 147 | 
            -
             | 
| 209 | 
            +
            ```ruby
         | 
| 210 | 
            +
            puts "Now with named stamps"
         | 
| 211 | 
            +
             | 
| 212 | 
            +
            Cutter::Stamper.scope :testing_method => "Demonstration of named stamping" do |tm|
         | 
| 213 | 
            +
              tm.msg _1: "first piece"
         | 
| 214 | 
            +
              tm.msg _2: "second piece"
         | 
| 215 | 
            +
            end
         | 
| 216 | 
            +
             | 
| 217 | 
            +
            Cutter::Stamper.scope :inner_scope => "Now internal things" do |i|
         | 
| 218 | 
            +
              i.msg first: "I'm the first inner stamp"
         | 
| 219 | 
            +
            end
         | 
| 220 | 
            +
             | 
| 221 | 
            +
            stamper :testing_method do |tm|
         | 
| 222 | 
            +
              sleep 0.3
         | 
| 223 | 
            +
              tm.stamp! :_1
         | 
| 224 | 
            +
              sleep 0.3
         | 
| 225 | 
            +
              stamper :inner_scope do |i|
         | 
| 226 | 
            +
                sleep 0.2
         | 
| 227 | 
            +
                i.stamp! :first
         | 
| 228 | 
            +
                sleep 0.2
         | 
| 229 | 
            +
                i.stamp! "Stamp with custom text"
         | 
| 230 | 
            +
              end
         | 
| 231 | 
            +
              tm.stamp! :_2
         | 
| 232 | 
            +
            end
         | 
| 233 | 
            +
            ```
         | 
| 234 | 
            +
             | 
| 235 | 
            +
            will result in
         | 
| 236 | 
            +
             | 
| 237 | 
            +
            ```text
         | 
| 238 | 
            +
            Now with named stamps
         | 
| 239 | 
            +
             | 
| 240 | 
            +
            Demonstration of named stamping
         | 
| 241 | 
            +
            -------------------------------
         | 
| 242 | 
            +
              stamp:     300 ms   first piece
         | 
| 243 | 
            +
             | 
| 244 | 
            +
                Now internal things
         | 
| 245 | 
            +
                -------------------
         | 
| 246 | 
            +
                stamp:     201 ms   I'm the first inner stamp
         | 
| 247 | 
            +
                stamp:     401 ms   Stamp with custom text
         | 
| 248 | 
            +
                -------------------
         | 
| 249 | 
            +
                              401ms
         | 
| 250 | 
            +
             | 
| 251 | 
            +
              stamp:    1001 ms   second piece
         | 
| 252 | 
            +
            -------------------------------
         | 
| 253 | 
            +
                                     1001ms
         | 
| 254 | 
            +
            ```
         | 
| 255 | 
            +
             | 
| 256 | 
            +
            ## Notes
         | 
| 257 | 
            +
             | 
| 258 | 
            +
            * Both ```#inspect! {}``` and ```#stamper``` method colorize their output. You can see ```lib/cutter/colored_output.rb``` file to understand how it is done. I will really appreciate any suggestions of how current color scheme can be improved.
         | 
| 259 | 
            +
             | 
| 260 | 
            +
            ## Specs and demos
         | 
| 261 | 
            +
             | 
| 262 | 
            +
            Clone it
         | 
| 263 | 
            +
             | 
| 264 | 
            +
            ```bash
         | 
| 265 | 
            +
            $ git clone https://github.com/stanislaw/cutter
         | 
| 266 | 
            +
            $ cd cutter
         | 
| 267 | 
            +
            ```
         | 
| 268 | 
            +
             | 
| 269 | 
            +
            Specs are just
         | 
| 270 | 
            +
             | 
| 271 | 
            +
            ```ruby
         | 
| 272 | 
            +
            rake
         | 
| 273 | 
            +
            ```
         | 
| 148 274 |  | 
| 149 | 
            -
             | 
| 275 | 
            +
            See demos
         | 
| 150 276 |  | 
| 151 277 | 
             
            ```ruby
         | 
| 152 | 
            -
             | 
| 278 | 
            +
            rake demo
         | 
| 153 279 | 
             
            ```
         | 
| 154 280 |  | 
| 155 281 | 
             
            ## Contributors
         | 
| @@ -1,6 +1,12 @@ | |
| 1 1 | 
             
            require 'colorize'
         | 
| 2 | 
            +
             | 
| 2 3 | 
             
            class Object
         | 
| 3 | 
            -
              
         | 
| 4 | 
            +
              def __colorize__ obj
         | 
| 5 | 
            +
                colors = Cutter::ColoredOutputs.colors_config
         | 
| 6 | 
            +
                color = colors[obj] || :default
         | 
| 7 | 
            +
                color != :default ? to_s.send(color) : to_s
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 4 10 | 
             
              def line sp = ""
         | 
| 5 11 | 
             
                log_coloured sp, "------------------------------", color(:line)
         | 
| 6 12 | 
             
              end
         | 
| @@ -30,20 +36,22 @@ module Cutter | |
| 30 36 |  | 
| 31 37 | 
             
                  def colors_config
         | 
| 32 38 | 
             
                    @colors ||= {
         | 
| 33 | 
            -
                                   | 
| 39 | 
            +
                                  # Colors for #stamper
         | 
| 40 | 
            +
                                  :line => :blue,
         | 
| 34 41 | 
             
                                  :time => :light_blue,
         | 
| 35 42 |  | 
| 36 43 | 
             
                                  :message_name => :cyan,
         | 
| 37 44 | 
             
                                  :message_line => :cyan,
         | 
| 38 45 | 
             
                                  :total_line => :yellow,
         | 
| 39 46 | 
             
                                  :total_count => :yellow,
         | 
| 40 | 
            -
             | 
| 47 | 
            +
             | 
| 41 48 | 
             
                                  # Colors for #inspect!
         | 
| 42 49 | 
             
                                  #  :called_from => :light_magenta,
         | 
| 50 | 
            +
             | 
| 43 51 | 
             
                                  :class_name => :light_green,
         | 
| 44 52 | 
             
                                  :method => :red,
         | 
| 45 53 | 
             
                                  :method_name => :yellow,
         | 
| 46 | 
            -
             | 
| 54 | 
            +
             | 
| 47 55 | 
             
                                  # :source => :white,
         | 
| 48 56 | 
             
                                  # :source_path => :white,
         | 
| 49 57 | 
             
                                  # :source_number => :white,
         | 
    
        data/lib/cutter/inspection.rb
    CHANGED
    
    | @@ -17,10 +17,10 @@ module Cutter | |
| 17 17 | 
             
            end
         | 
| 18 18 |  | 
| 19 19 | 
             
            class Object
         | 
| 20 | 
            -
             | 
| 21 | 
            -
              # #inspect! may be called inside any method as 'inspect! {}' or more  | 
| 20 | 
            +
             | 
| 21 | 
            +
              # #inspect! may be called inside any method as 'inspect! {}' or more rigorously as 'inspect!(binding)'
         | 
| 22 22 | 
             
              # Binding is a Ruby class: http://www.ruby-doc.org/core/classes/Binding.html
         | 
| 23 | 
            -
             | 
| 23 | 
            +
             | 
| 24 24 | 
             
              def inspect! *options, &block
         | 
| 25 25 | 
             
                return true if Cutter::Inspection.quiet?
         | 
| 26 26 |  | 
| @@ -28,16 +28,16 @@ class Object | |
| 28 28 | 
             
                _binding = options.first if options.first.class == Binding
         | 
| 29 29 | 
             
                raise ArgumentError, "Try inspect(binding) or inspect! {}", caller if (!block_given? && !_binding)
         | 
| 30 30 | 
             
                _binding ||= block.binding
         | 
| 31 | 
            -
             | 
| 31 | 
            +
             | 
| 32 32 | 
             
                max = true if options.include? :max
         | 
| 33 33 | 
             
                options << :instance << :max << :self << :caller if max
         | 
| 34 34 | 
             
                options.uniq!
         | 
| 35 | 
            -
             | 
| 35 | 
            +
             | 
| 36 36 | 
             
                iv = true if options.include? :instance
         | 
| 37 37 |  | 
| 38 38 | 
             
                # Want caller methods chain to be traced? - pass option :caller to #inspect!
         | 
| 39 39 | 
             
                _caller = true if options.include? :caller
         | 
| 40 | 
            -
             | 
| 40 | 
            +
             | 
| 41 41 | 
             
                self_inspection = eval('self.inspect', _binding) if options.include? :self
         | 
| 42 42 |  | 
| 43 43 | 
             
                # Basic info
         | 
| @@ -48,53 +48,53 @@ class Object | |
| 48 48 | 
             
                  source_path, source_number = meth.source_location
         | 
| 49 49 | 
             
                end
         | 
| 50 50 |  | 
| 51 | 
            -
                puts "\n%s `%s' %s" % ['method:'. | 
| 51 | 
            +
                puts "\n%s `%s' %s" % ['method:'.__colorize__(:method), method_name.__colorize__(:method_name), ('(maximal tracing)' if max)]
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                puts "  %s %s:%s" % ['source_location:'.__colorize__(:source), source_path.dup.__colorize__(:source_path), source_number.to_s.__colorize__(:source_number)] if source_path && source_number
         | 
| 52 54 |  | 
| 53 | 
            -
                puts "  %s %s | 
| 54 | 
            -
               
         | 
| 55 | 
            -
                puts "  %s %s" % ['called from class:'.to_colorized_string(:called_from), class_name.to_colorized_string(:class_name)]
         | 
| 55 | 
            +
                puts "  %s %s" % ['called from class:'.__colorize__(:called_from), class_name.__colorize__(:class_name)]
         | 
| 56 56 |  | 
| 57 57 | 
             
                # Local Variables
         | 
| 58 58 | 
             
                lvb = eval('local_variables',_binding)
         | 
| 59 | 
            -
                puts "  %s %s" % ['local_variables:'. | 
| 59 | 
            +
                puts "  %s %s" % ['local_variables:'.__colorize__(:lv), ("[]" if lvb.empty?)]
         | 
| 60 60 |  | 
| 61 61 | 
             
                lvb.map do |lv|
         | 
| 62 62 | 
             
                  local_variable = eval(lv.to_s, _binding)
         | 
| 63 | 
            -
                  local_variable = (max ? local_variable.inspect : local_variable. | 
| 63 | 
            +
                  local_variable = (max ? local_variable.inspect : local_variable.__real_to_s__)
         | 
| 64 64 |  | 
| 65 | 
            -
                  puts "    %s: %s" % [lv. | 
| 65 | 
            +
                  puts "    %s: %s" % [lv.__colorize__(:lv_names), local_variable.__colorize__(:lv_values)]
         | 
| 66 66 | 
             
                end if lvb
         | 
| 67 67 |  | 
| 68 68 | 
             
                # Instance Variables
         | 
| 69 69 | 
             
                begin
         | 
| 70 70 | 
             
                  ivb = eval('instance_variables',_binding)
         | 
| 71 | 
            -
             | 
| 72 | 
            -
                  puts "  %s %s" % ["instance_variables:". | 
| 73 | 
            -
             | 
| 71 | 
            +
             | 
| 72 | 
            +
                  puts "  %s %s" % ["instance_variables:".__colorize__(:iv), ("[]" if ivb.empty?)]
         | 
| 73 | 
            +
             | 
| 74 74 | 
             
                  ivb.map do |iv|
         | 
| 75 75 | 
             
                    instance_variable = eval(iv.to_s, _binding)
         | 
| 76 | 
            -
                    instance_variable = (max ? instance_variable.inspect : instance_variable. | 
| 77 | 
            -
             | 
| 78 | 
            -
                    puts "    %s: %s" % [iv. | 
| 76 | 
            +
                    instance_variable = (max ? instance_variable.inspect : instance_variable.__real_to_s__)
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                    puts "    %s: %s" % [iv.__colorize__(:iv_names), instance_variable.__colorize__(:iv_values)]
         | 
| 79 79 | 
             
                  end if ivb
         | 
| 80 80 | 
             
                end if iv
         | 
| 81 81 |  | 
| 82 | 
            -
                # Self inspection | 
| 82 | 
            +
                # Self inspection
         | 
| 83 83 | 
             
                begin
         | 
| 84 | 
            -
                  puts "  self inspection:". | 
| 85 | 
            -
                  puts "  %s" % self_inspection. | 
| 84 | 
            +
                  puts "  self inspection:".__colorize__(:self_inspection)
         | 
| 85 | 
            +
                  puts "  %s" % self_inspection.__colorize__(:self_inspection_trace)
         | 
| 86 86 | 
             
                end if self_inspection
         | 
| 87 87 |  | 
| 88 88 | 
             
                # Caller methods chain
         | 
| 89 89 | 
             
                begin
         | 
| 90 | 
            -
                  puts "  caller methods: ". | 
| 90 | 
            +
                  puts "  caller methods: ".__colorize__(:caller_methods)
         | 
| 91 91 | 
             
                  caller.each do |meth|
         | 
| 92 | 
            -
                    puts "  %s" % meth. | 
| 92 | 
            +
                    puts "  %s" % meth.__colorize__(:caller_method)
         | 
| 93 93 | 
             
                  end
         | 
| 94 94 | 
             
                end if _caller
         | 
| 95 | 
            -
             | 
| 95 | 
            +
             | 
| 96 96 | 
             
                puts "\n"
         | 
| 97 | 
            -
             | 
| 97 | 
            +
             | 
| 98 98 | 
             
                # Yield mysterious things if they exist in block.
         | 
| 99 99 | 
             
                yield if block_given?
         | 
| 100 100 | 
             
              end
         | 
| @@ -104,15 +104,13 @@ class Object | |
| 104 104 | 
             
              protected
         | 
| 105 105 |  | 
| 106 106 | 
             
              # "Real string". It is now used to print Symbols with colons
         | 
| 107 | 
            -
              def  | 
| 108 | 
            -
                 | 
| 109 | 
            -
                 | 
| 110 | 
            -
             | 
| 111 | 
            -
             | 
| 112 | 
            -
             | 
| 113 | 
            -
                 | 
| 114 | 
            -
                color = colors[obj] || :default
         | 
| 115 | 
            -
                color != :default ? to_s.send(color) : to_s
         | 
| 107 | 
            +
              def __real_to_s__
         | 
| 108 | 
            +
                case self
         | 
| 109 | 
            +
                when Symbol, Array, Hash
         | 
| 110 | 
            +
                  inspect
         | 
| 111 | 
            +
                else
         | 
| 112 | 
            +
                  to_s
         | 
| 113 | 
            +
                end
         | 
| 116 114 | 
             
              end
         | 
| 117 115 | 
             
            end
         | 
| 118 116 |  | 
| @@ -121,7 +119,7 @@ class Object | |
| 121 119 | 
             
                raise object.inspect
         | 
| 122 120 | 
             
              end
         | 
| 123 121 |  | 
| 124 | 
            -
              def ppp object = nil | 
| 122 | 
            +
              def ppp object = nil
         | 
| 125 123 | 
             
                puts object.inspect
         | 
| 126 124 | 
             
              end
         | 
| 127 125 |  | 
    
        data/lib/cutter/stamper.rb
    CHANGED
    
    | @@ -16,29 +16,41 @@ class Object | |
| 16 16 | 
             
                end
         | 
| 17 17 | 
             
                spaces = "    " * scope.indent
         | 
| 18 18 | 
             
                puts "\n"
         | 
| 19 | 
            -
                log_coloured spaces, "#{message}",  | 
| 20 | 
            -
                log_coloured spaces, "#{'-'*message.length}",  | 
| 19 | 
            +
                log_coloured spaces, "#{message}", __color__(:message_name)
         | 
| 20 | 
            +
                log_coloured spaces, "#{'-'*message.length}", __color__(:message_line)
         | 
| 21 21 |  | 
| 22 22 | 
             
                scope.time_initial = time_now
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                self.class.send :define_method, :stamp do |*args|
         | 
| 25 | 
            +
                  scope.stamp args.first
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
                self.class.send :alias_method, :stamp!, :stamp
         | 
| 28 | 
            +
                
         | 
| 23 29 | 
             
                yield scope
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                instance_eval do
         | 
| 32 | 
            +
                  undef :stamp if respond_to? :stamp
         | 
| 33 | 
            +
                  undef :stamp! if respond_to? :stamp!
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 24 36 | 
             
                scope.indent -= 1 if scope.indent > 0
         | 
| 25 37 | 
             
                stamper_class.pop
         | 
| 26 38 | 
             
                time_passed = time_now - scope.time_initial
         | 
| 27 | 
            -
             | 
| 39 | 
            +
             | 
| 28 40 | 
             
                tps = "#{time_passed}ms"
         | 
| 29 41 | 
             
                offset = message.length - tps.length
         | 
| 30 42 | 
             
                offset = 0 if offset < 0
         | 
| 31 | 
            -
                log_coloured spaces, "#{'-'*message.length}",  | 
| 32 | 
            -
                log_coloured spaces + "#{' ' * (offset)}", tps,  | 
| 43 | 
            +
                log_coloured spaces, "#{'-'*message.length}", __color__(:total_line)
         | 
| 44 | 
            +
                log_coloured spaces + "#{' ' * (offset)}", tps, __color__(:total_count)
         | 
| 33 45 | 
             
                puts "\n"
         | 
| 34 46 | 
             
              end
         | 
| 35 47 |  | 
| 36 48 | 
             
              private
         | 
| 37 49 |  | 
| 38 | 
            -
              def  | 
| 50 | 
            +
              def __color__ type
         | 
| 39 51 | 
             
                stamper_class.colors_config[type] if stamper_class.colors?
         | 
| 40 52 | 
             
              end
         | 
| 41 | 
            -
             | 
| 53 | 
            +
             | 
| 42 54 | 
             
              def stamper_class
         | 
| 43 55 | 
             
                Cutter::Stamper
         | 
| 44 56 | 
             
              end
         | 
| @@ -107,6 +119,7 @@ module Cutter | |
| 107 119 | 
             
                  print "  " * nindent
         | 
| 108 120 | 
             
                  printf("stamp: %7d ms   #{message}\n", time_passed)
         | 
| 109 121 | 
             
                end
         | 
| 122 | 
            +
                alias_method :stamp!, :stamp
         | 
| 110 123 |  | 
| 111 124 | 
             
                module ClassMethods
         | 
| 112 125 |  | 
    
        data/lib/cutter/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,72 +1,89 @@ | |
| 1 | 
            -
            --- !ruby/object:Gem::Specification
         | 
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: cutter
         | 
| 3 | 
            -
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
               | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              hash: 49
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 | 
            +
              segments: 
         | 
| 7 | 
            +
              - 0
         | 
| 8 | 
            +
              - 8
         | 
| 9 | 
            +
              - 7
         | 
| 10 | 
            +
              version: 0.8.7
         | 
| 6 11 | 
             
            platform: ruby
         | 
| 7 | 
            -
            authors:
         | 
| 12 | 
            +
            authors: 
         | 
| 8 13 | 
             
            - stanislaw
         | 
| 9 14 | 
             
            autorequire: 
         | 
| 10 15 | 
             
            bindir: bin
         | 
| 11 16 | 
             
            cert_chain: []
         | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            -
                none: false
         | 
| 18 | 
            -
                requirements:
         | 
| 19 | 
            -
                - - ! '>='
         | 
| 20 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 21 | 
            -
                    version: '0.5'
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            date: 2012-06-30 00:00:00 Z
         | 
| 19 | 
            +
            dependencies: 
         | 
| 20 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 22 21 | 
             
              type: :runtime
         | 
| 22 | 
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 23 | 
            +
                none: false
         | 
| 24 | 
            +
                requirements: 
         | 
| 25 | 
            +
                - - ">="
         | 
| 26 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 27 | 
            +
                    hash: 1
         | 
| 28 | 
            +
                    segments: 
         | 
| 29 | 
            +
                    - 0
         | 
| 30 | 
            +
                    - 5
         | 
| 31 | 
            +
                    version: "0.5"
         | 
| 32 | 
            +
              version_requirements: *id001
         | 
| 33 | 
            +
              name: colorize
         | 
| 23 34 | 
             
              prerelease: false
         | 
| 24 | 
            -
             | 
| 35 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 36 | 
            +
              type: :development
         | 
| 37 | 
            +
              requirement: &id002 !ruby/object:Gem::Requirement 
         | 
| 25 38 | 
             
                none: false
         | 
| 26 | 
            -
                requirements:
         | 
| 27 | 
            -
                - -  | 
| 28 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            -
                     | 
| 30 | 
            -
             | 
| 39 | 
            +
                requirements: 
         | 
| 40 | 
            +
                - - ">="
         | 
| 41 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 42 | 
            +
                    hash: 3
         | 
| 43 | 
            +
                    segments: 
         | 
| 44 | 
            +
                    - 0
         | 
| 45 | 
            +
                    version: "0"
         | 
| 46 | 
            +
              version_requirements: *id002
         | 
| 31 47 | 
             
              name: bundler
         | 
| 32 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 33 | 
            -
                none: false
         | 
| 34 | 
            -
                requirements:
         | 
| 35 | 
            -
                - - ! '>='
         | 
| 36 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 37 | 
            -
                    version: '0'
         | 
| 38 | 
            -
              type: :development
         | 
| 39 48 | 
             
              prerelease: false
         | 
| 40 | 
            -
             | 
| 49 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 50 | 
            +
              type: :development
         | 
| 51 | 
            +
              requirement: &id003 !ruby/object:Gem::Requirement 
         | 
| 41 52 | 
             
                none: false
         | 
| 42 | 
            -
                requirements:
         | 
| 43 | 
            -
                - -  | 
| 44 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 45 | 
            -
                     | 
| 46 | 
            -
             | 
| 53 | 
            +
                requirements: 
         | 
| 54 | 
            +
                - - ">="
         | 
| 55 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 56 | 
            +
                    hash: 3
         | 
| 57 | 
            +
                    segments: 
         | 
| 58 | 
            +
                    - 0
         | 
| 59 | 
            +
                    version: "0"
         | 
| 60 | 
            +
              version_requirements: *id003
         | 
| 47 61 | 
             
              name: jeweler
         | 
| 48 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 49 | 
            -
                none: false
         | 
| 50 | 
            -
                requirements:
         | 
| 51 | 
            -
                - - ! '>='
         | 
| 52 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 53 | 
            -
                    version: '0'
         | 
| 54 | 
            -
              type: :development
         | 
| 55 62 | 
             
              prerelease: false
         | 
| 56 | 
            -
             | 
| 63 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 64 | 
            +
              type: :development
         | 
| 65 | 
            +
              requirement: &id004 !ruby/object:Gem::Requirement 
         | 
| 57 66 | 
             
                none: false
         | 
| 58 | 
            -
                requirements:
         | 
| 59 | 
            -
                - -  | 
| 60 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            -
                     | 
| 67 | 
            +
                requirements: 
         | 
| 68 | 
            +
                - - ">="
         | 
| 69 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 70 | 
            +
                    hash: 3
         | 
| 71 | 
            +
                    segments: 
         | 
| 72 | 
            +
                    - 0
         | 
| 73 | 
            +
                    version: "0"
         | 
| 74 | 
            +
              version_requirements: *id004
         | 
| 75 | 
            +
              name: rspec
         | 
| 76 | 
            +
              prerelease: false
         | 
| 62 77 | 
             
            description: Ruby tracing gem
         | 
| 63 78 | 
             
            email: s.pankevich@gmail.com
         | 
| 64 79 | 
             
            executables: []
         | 
| 80 | 
            +
             | 
| 65 81 | 
             
            extensions: []
         | 
| 66 | 
            -
             | 
| 82 | 
            +
             | 
| 83 | 
            +
            extra_rdoc_files: 
         | 
| 67 84 | 
             
            - LICENSE.txt
         | 
| 68 85 | 
             
            - README.md
         | 
| 69 | 
            -
            files:
         | 
| 86 | 
            +
            files: 
         | 
| 70 87 | 
             
            - lib/cutter.rb
         | 
| 71 88 | 
             
            - lib/cutter/colored_outputs.rb
         | 
| 72 89 | 
             
            - lib/cutter/inspection.rb
         | 
| @@ -75,31 +92,37 @@ files: | |
| 75 92 | 
             
            - LICENSE.txt
         | 
| 76 93 | 
             
            - README.md
         | 
| 77 94 | 
             
            homepage: http://github.com/stanislaw/cutter
         | 
| 78 | 
            -
            licenses:
         | 
| 95 | 
            +
            licenses: 
         | 
| 79 96 | 
             
            - MIT
         | 
| 80 97 | 
             
            post_install_message: 
         | 
| 81 98 | 
             
            rdoc_options: []
         | 
| 82 | 
            -
             | 
| 99 | 
            +
             | 
| 100 | 
            +
            require_paths: 
         | 
| 83 101 | 
             
            - lib
         | 
| 84 | 
            -
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 102 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 85 103 | 
             
              none: false
         | 
| 86 | 
            -
              requirements:
         | 
| 87 | 
            -
              - -  | 
| 88 | 
            -
                - !ruby/object:Gem::Version
         | 
| 89 | 
            -
                   | 
| 90 | 
            -
                  segments:
         | 
| 104 | 
            +
              requirements: 
         | 
| 105 | 
            +
              - - ">="
         | 
| 106 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 107 | 
            +
                  hash: 3
         | 
| 108 | 
            +
                  segments: 
         | 
| 91 109 | 
             
                  - 0
         | 
| 92 | 
            -
                   | 
| 93 | 
            -
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 110 | 
            +
                  version: "0"
         | 
| 111 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 94 112 | 
             
              none: false
         | 
| 95 | 
            -
              requirements:
         | 
| 96 | 
            -
              - -  | 
| 97 | 
            -
                - !ruby/object:Gem::Version
         | 
| 98 | 
            -
                   | 
| 113 | 
            +
              requirements: 
         | 
| 114 | 
            +
              - - ">="
         | 
| 115 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 116 | 
            +
                  hash: 3
         | 
| 117 | 
            +
                  segments: 
         | 
| 118 | 
            +
                  - 0
         | 
| 119 | 
            +
                  version: "0"
         | 
| 99 120 | 
             
            requirements: []
         | 
| 121 | 
            +
             | 
| 100 122 | 
             
            rubyforge_project: 
         | 
| 101 123 | 
             
            rubygems_version: 1.8.19
         | 
| 102 124 | 
             
            signing_key: 
         | 
| 103 125 | 
             
            specification_version: 3
         | 
| 104 126 | 
             
            summary: Ruby tracing gem
         | 
| 105 127 | 
             
            test_files: []
         | 
| 128 | 
            +
             |