save_chain_inspector 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/lib/save_chain_inspector/version.rb +1 -1
- data/lib/save_chain_inspector.rb +38 -28
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 24d9d01dd7b99d009b463ea942a213bd50bb6c056d580b08192526b1b35dc830
         | 
| 4 | 
            +
              data.tar.gz: a0c2e7d89d672935e0942e5da70fa1d81fe6a955b62b6d48e7ecf9bece02523f
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 8db4e2cef5fd9b5fe56d59ff2188c8b9d5f9675ea1a071e8f63f048f388eee79547aa11c82cff6476eeb1734a4185dea17383623d8aa81502b73083ad2cdc8e6
         | 
| 7 | 
            +
              data.tar.gz: 912fa4cb6ad19f39389fc06fdbab418a80f2ba120915b218ce10bd14cca4d9d3f4d85101fcf7c186a9efdb084b3838e664d943b11d0065411ace6a59766f9c6c
         | 
    
        data/lib/save_chain_inspector.rb
    CHANGED
    
    | @@ -4,17 +4,27 @@ require_relative 'save_chain_inspector/version' | |
| 4 4 |  | 
| 5 5 | 
             
            class SaveChainInspector # rubocop:disable Metrics/ClassLength, Style/Documentation
         | 
| 6 6 | 
             
              class << self
         | 
| 7 | 
            -
                attr_accessor : | 
| 8 | 
            -
             | 
| 7 | 
            +
                attr_accessor :indent_count, :enable
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def start(&block)
         | 
| 10 | 
            +
                  self.indent_count = 0
         | 
| 11 | 
            +
                  self.enable = true
         | 
| 12 | 
            +
                  new.call(&block)
         | 
| 13 | 
            +
                ensure
         | 
| 14 | 
            +
                  self.enable = false
         | 
| 15 | 
            +
                end
         | 
| 9 16 |  | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
                 | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 17 | 
            +
                def indent
         | 
| 18 | 
            +
                  ' ' * (indent_count * 2)
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def increment_indent
         | 
| 22 | 
            +
                  self.indent_count += 1
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def decrement_indent
         | 
| 26 | 
            +
                  self.indent_count -= 1 if indent_count.positive?
         | 
| 27 | 
            +
                end
         | 
| 18 28 | 
             
              end
         | 
| 19 29 |  | 
| 20 30 | 
             
              def initialize
         | 
| @@ -33,38 +43,38 @@ class SaveChainInspector # rubocop:disable Metrics/ClassLength, Style/Documentat | |
| 33 43 | 
             
                klass.before_save(prepend: true) do |model|
         | 
| 34 44 | 
             
                  next unless SaveChainInspector.enable
         | 
| 35 45 |  | 
| 36 | 
            -
                  puts "#{ | 
| 37 | 
            -
                  SaveChainInspector. | 
| 46 | 
            +
                  puts "#{SaveChainInspector.indent}#{model.class}#before_save start"
         | 
| 47 | 
            +
                  SaveChainInspector.increment_indent
         | 
| 38 48 | 
             
                end
         | 
| 39 49 | 
             
                klass.before_save do |model|
         | 
| 40 50 | 
             
                  next unless SaveChainInspector.enable
         | 
| 41 51 |  | 
| 42 | 
            -
                  SaveChainInspector. | 
| 43 | 
            -
                  puts "#{ | 
| 52 | 
            +
                  SaveChainInspector.decrement_indent
         | 
| 53 | 
            +
                  puts "#{SaveChainInspector.indent}#{model.class}#before_save end"
         | 
| 44 54 | 
             
                end
         | 
| 45 55 | 
             
                klass.set_callback(:create, :after) do |model|
         | 
| 46 56 | 
             
                  next unless SaveChainInspector.enable
         | 
| 47 57 |  | 
| 48 | 
            -
                  puts "#{ | 
| 49 | 
            -
                  SaveChainInspector. | 
| 58 | 
            +
                  puts "#{SaveChainInspector.indent}#{model.class}#after_create start"
         | 
| 59 | 
            +
                  SaveChainInspector.increment_indent
         | 
| 50 60 | 
             
                end
         | 
| 51 61 | 
             
                klass.after_create do |model|
         | 
| 52 62 | 
             
                  next unless SaveChainInspector.enable
         | 
| 53 63 |  | 
| 54 | 
            -
                  SaveChainInspector. | 
| 55 | 
            -
                  puts "#{ | 
| 64 | 
            +
                  SaveChainInspector.decrement_indent
         | 
| 65 | 
            +
                  puts "#{SaveChainInspector.indent}#{model.class}#after_create end"
         | 
| 56 66 | 
             
                end
         | 
| 57 67 | 
             
                klass.set_callback(:update, :after) do |model|
         | 
| 58 68 | 
             
                  next unless SaveChainInspector.enable
         | 
| 59 69 |  | 
| 60 | 
            -
                  puts "#{ | 
| 61 | 
            -
                  SaveChainInspector. | 
| 70 | 
            +
                  puts "#{SaveChainInspector.indent}#{model.class}#after_update start"
         | 
| 71 | 
            +
                  SaveChainInspector.increment_indent
         | 
| 62 72 | 
             
                end
         | 
| 63 73 | 
             
                klass.after_update do |model|
         | 
| 64 74 | 
             
                  next unless SaveChainInspector.enable
         | 
| 65 75 |  | 
| 66 | 
            -
                  SaveChainInspector. | 
| 67 | 
            -
                  puts "#{ | 
| 76 | 
            +
                  SaveChainInspector.decrement_indent
         | 
| 77 | 
            +
                  puts "#{SaveChainInspector.indent}#{model.class}#after_update end"
         | 
| 68 78 | 
             
                end
         | 
| 69 79 | 
             
              end
         | 
| 70 80 |  | 
| @@ -111,19 +121,19 @@ class SaveChainInspector # rubocop:disable Metrics/ClassLength, Style/Documentat | |
| 111 121 | 
             
                  if trace_point.event == :call
         | 
| 112 122 | 
             
                    if autosave_method?(trace_point) || (save_method?(trace_point) && !duplicate_save_method_call?(trace_point))
         | 
| 113 123 | 
             
                      update_last_call(trace_point)
         | 
| 114 | 
            -
                      puts "#{ | 
| 115 | 
            -
                      self.class. | 
| 124 | 
            +
                      puts "#{self.class.indent}#{trace_point.self.class.name}##{trace_point.method_id} start"
         | 
| 125 | 
            +
                      self.class.increment_indent
         | 
| 116 126 | 
             
                    end
         | 
| 117 127 | 
             
                  else # :return
         | 
| 118 128 | 
             
                    if save_method?(trace_point) && !duplicate_save_method_return?(trace_point)
         | 
| 119 | 
            -
                      self.class. | 
| 129 | 
            +
                      self.class.decrement_indent
         | 
| 120 130 | 
             
                      update_last_return(trace_point)
         | 
| 121 | 
            -
                      puts "#{ | 
| 131 | 
            +
                      puts "#{self.class.indent}#{trace_point.self.class.name}##{trace_point.method_id} end"
         | 
| 122 132 | 
             
                    end
         | 
| 123 133 |  | 
| 124 134 | 
             
                    if autosave_method?(trace_point)
         | 
| 125 | 
            -
                      self.class. | 
| 126 | 
            -
                      puts "#{ | 
| 135 | 
            +
                      self.class.decrement_indent
         | 
| 136 | 
            +
                      puts "#{self.class.indent}#{trace_point.self.class.name}##{trace_point.method_id} end"
         | 
| 127 137 | 
             
                    end
         | 
| 128 138 | 
             
                  end
         | 
| 129 139 | 
             
                end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: save_chain_inspector
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Shinichi Maeshima
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2024- | 
| 11 | 
            +
            date: 2024-09-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activerecord
         |