trace_location 0.1.0
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +5 -0
- data/.travis.yml +7 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/README.md +96 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/trace_location.rb +26 -0
- data/lib/trace_location/config.rb +12 -0
- data/lib/trace_location/railtie.rb +12 -0
- data/lib/trace_location/tracer.rb +72 -0
- data/lib/trace_location/version.rb +5 -0
- data/trace_location.gemspec +29 -0
- metadata +103 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: bfb14ac437de0918b84efe14862be77d28176b7475d1b033bf914ae8f6e54e0d
         | 
| 4 | 
            +
              data.tar.gz: ef716fc6e91843c70c19604b578dc6ad018446c61af963e7b13c9517619afe60
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: cb20ffc9c0988b9462abf62a0d4ca52c65c6226a21d3519c330dfd216da6b46326607b070f4a2fd242990e39a67514f91ed2a7841c363743861bb08e83f2b83f
         | 
| 7 | 
            +
              data.tar.gz: 553834e64150421138a7302b03c11ad1f3b4c5f2c64256eb056df8cd9f10a4457b4da2608002543e7fafd7f71b8cbfed0dbc59a618d68e8038266c8da2003a5a
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.rspec
    ADDED
    
    
    
        data/.rubocop.yml
    ADDED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/Gemfile.lock
    ADDED
    
    | @@ -0,0 +1,51 @@ | |
| 1 | 
            +
            PATH
         | 
| 2 | 
            +
              remote: .
         | 
| 3 | 
            +
              specs:
         | 
| 4 | 
            +
                trace_location (0.1.0)
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            GEM
         | 
| 7 | 
            +
              remote: https://rubygems.org/
         | 
| 8 | 
            +
              specs:
         | 
| 9 | 
            +
                ast (2.4.0)
         | 
| 10 | 
            +
                diff-lcs (1.3)
         | 
| 11 | 
            +
                jaro_winkler (1.5.2)
         | 
| 12 | 
            +
                parallel (1.17.0)
         | 
| 13 | 
            +
                parser (2.6.3.0)
         | 
| 14 | 
            +
                  ast (~> 2.4.0)
         | 
| 15 | 
            +
                rainbow (3.0.0)
         | 
| 16 | 
            +
                rake (10.5.0)
         | 
| 17 | 
            +
                rspec (3.8.0)
         | 
| 18 | 
            +
                  rspec-core (~> 3.8.0)
         | 
| 19 | 
            +
                  rspec-expectations (~> 3.8.0)
         | 
| 20 | 
            +
                  rspec-mocks (~> 3.8.0)
         | 
| 21 | 
            +
                rspec-core (3.8.0)
         | 
| 22 | 
            +
                  rspec-support (~> 3.8.0)
         | 
| 23 | 
            +
                rspec-expectations (3.8.3)
         | 
| 24 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 25 | 
            +
                  rspec-support (~> 3.8.0)
         | 
| 26 | 
            +
                rspec-mocks (3.8.0)
         | 
| 27 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 28 | 
            +
                  rspec-support (~> 3.8.0)
         | 
| 29 | 
            +
                rspec-support (3.8.0)
         | 
| 30 | 
            +
                rubocop (0.68.1)
         | 
| 31 | 
            +
                  jaro_winkler (~> 1.5.1)
         | 
| 32 | 
            +
                  parallel (~> 1.10)
         | 
| 33 | 
            +
                  parser (>= 2.5, != 2.5.1.1)
         | 
| 34 | 
            +
                  rainbow (>= 2.2.2, < 4.0)
         | 
| 35 | 
            +
                  ruby-progressbar (~> 1.7)
         | 
| 36 | 
            +
                  unicode-display_width (>= 1.4.0, < 1.6)
         | 
| 37 | 
            +
                ruby-progressbar (1.10.0)
         | 
| 38 | 
            +
                unicode-display_width (1.5.0)
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            PLATFORMS
         | 
| 41 | 
            +
              ruby
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            DEPENDENCIES
         | 
| 44 | 
            +
              bundler (~> 2.0)
         | 
| 45 | 
            +
              rake (~> 10.0)
         | 
| 46 | 
            +
              rspec (~> 3.0)
         | 
| 47 | 
            +
              rubocop
         | 
| 48 | 
            +
              trace_location!
         | 
| 49 | 
            +
             | 
| 50 | 
            +
            BUNDLED WITH
         | 
| 51 | 
            +
               2.0.1
         | 
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            The MIT License (MIT)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Copyright (c) 2019 Yoshiyuki Hirano
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy
         | 
| 6 | 
            +
            of this software and associated documentation files (the "Software"), to deal
         | 
| 7 | 
            +
            in the Software without restriction, including without limitation the rights
         | 
| 8 | 
            +
            to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         | 
| 9 | 
            +
            copies of the Software, and to permit persons to whom the Software is
         | 
| 10 | 
            +
            furnished to do so, subject to the following conditions:
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            The above copyright notice and this permission notice shall be included in
         | 
| 13 | 
            +
            all copies or substantial portions of the Software.
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         | 
| 16 | 
            +
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         | 
| 17 | 
            +
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         | 
| 18 | 
            +
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         | 
| 19 | 
            +
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         | 
| 20 | 
            +
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
         | 
| 21 | 
            +
            THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,96 @@ | |
| 1 | 
            +
            # TraceLocation
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            TraceLocation gem provides logs a tracing result of `:call` and `:return`. It's useful for reading the huge codes (e.g. Ruby on Rails) and tracing its process.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Installation
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Add this line to your application's Gemfile:
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            ```ruby
         | 
| 10 | 
            +
            gem 'trace_location'
         | 
| 11 | 
            +
            ```
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            And then execute:
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                $ bundle
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            Or install it yourself as:
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                $ gem install trace_location
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            ## Usage
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            You just surround the code which you want to track the process.
         | 
| 24 | 
            +
            For example, when you want to track the process of Rails application request/response:
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            ```
         | 
| 27 | 
            +
            % bin/rails c
         | 
| 28 | 
            +
            Running via Spring preloader in process 40741
         | 
| 29 | 
            +
            Loading development environment (Rails 5.2.3)
         | 
| 30 | 
            +
            irb(main):001:0> env = Rack::MockRequest.env_for('http://localhost:3000/api/stories')
         | 
| 31 | 
            +
            irb(main):002:0> TraceLocation.trace { status, headers, body = Rails.application.call(env) }
         | 
| 32 | 
            +
            Created at /path/to/sampleapp/log/trace_location-2019050105051556706139.log
         | 
| 33 | 
            +
            => true
         | 
| 34 | 
            +
            ```
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            Then you can get a log like this:
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            ```
         | 
| 39 | 
            +
            Logged by TraceLocation gem at 2019-05-01 05:22:19 -0500
         | 
| 40 | 
            +
            https://github.com/yhirano55/trace_location
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            [Tracing events] C: Call, R: Return
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            R <internal:prelude>:138#enable
         | 
| 45 | 
            +
            C /vendor/bundle/gems/railties-5.2.3/lib/rails.rb:39#application
         | 
| 46 | 
            +
            R /vendor/bundle/gems/railties-5.2.3/lib/rails.rb:41#application
         | 
| 47 | 
            +
            C /vendor/bundle/gems/railties-5.2.3/lib/rails/engine.rb:522#call
         | 
| 48 | 
            +
              C /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:607#build_request
         | 
| 49 | 
            +
                C /vendor/bundle/gems/railties-5.2.3/lib/rails/engine.rb:705#build_request
         | 
| 50 | 
            +
                  C /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:247#env_config
         | 
| 51 | 
            +
                  R /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:275#env_config
         | 
| 52 | 
            +
                  C /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/request.rb:59#initialize
         | 
| 53 | 
            +
                    C /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:40#initialize
         | 
| 54 | 
            +
                      C /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/url.rb:186#initialize
         | 
| 55 | 
            +
                        C /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/filter_parameters.rb:34#initialize
         | 
| 56 | 
            +
                        R /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/filter_parameters.rb:39#initialize
         | 
| 57 | 
            +
                      R /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/url.rb:190#initialize
         | 
| 58 | 
            +
                    R /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:43#initialize
         | 
| 59 | 
            +
                  R /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/request.rb:67#initialize
         | 
| 60 | 
            +
                  C /vendor/bundle/gems/railties-5.2.3/lib/rails/engine.rb:534#routes
         | 
| 61 | 
            +
                  R /vendor/bundle/gems/railties-5.2.3/lib/rails/engine.rb:538#routes
         | 
| 62 | 
            +
                  C /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/request.rb:142#routes=
         | 
| 63 | 
            +
                    C /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:68#set_header
         | 
| 64 | 
            +
                    R /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:70#set_header
         | 
| 65 | 
            +
                  R /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/request.rb:144#routes=
         | 
| 66 | 
            +
                  C /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:129#script_name
         | 
| 67 | 
            +
                    C /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:52#get_header
         | 
| 68 | 
            +
                    R /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:54#get_header
         | 
| 69 | 
            +
                  R /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:129#script_name
         | 
| 70 | 
            +
                  C /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/request.rb:150#engine_script_name=
         | 
| 71 | 
            +
                    C /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/request.rb:138#routes
         | 
| 72 | 
            +
                      C /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:52#get_header
         | 
| 73 | 
            +
                      R /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:54#get_header
         | 
| 74 | 
            +
            ..................
         | 
| 75 | 
            +
            (an omission)
         | 
| 76 | 
            +
            ..................
         | 
| 77 | 
            +
                            R /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/middleware/static.rb:128#call
         | 
| 78 | 
            +
                            C /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:9#respond_to?
         | 
| 79 | 
            +
                              C /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:9#respond_to?
         | 
| 80 | 
            +
                                C /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:9#respond_to?
         | 
| 81 | 
            +
                                  C /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:9#respond_to?
         | 
| 82 | 
            +
                                    C /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:9#respond_to?
         | 
| 83 | 
            +
                                    R /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:15#respond_to?
         | 
| 84 | 
            +
                                  R /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:15#respond_to?
         | 
| 85 | 
            +
                                R /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:15#respond_to?
         | 
| 86 | 
            +
                              R /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:15#respond_to?
         | 
| 87 | 
            +
                            R /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:15#respond_to?
         | 
| 88 | 
            +
                          R /vendor/bundle/gems/rack-2.0.7/lib/rack/sendfile.rb:140#call
         | 
| 89 | 
            +
                        R /vendor/bundle/gems/railties-5.2.3/lib/rails/engine.rb:525#call
         | 
| 90 | 
            +
             | 
| 91 | 
            +
            Result: [200, {"Content-Type"=>"application/json; charset=utf-8", "ETag"=>"W/\"42334f8fba25471804e2cfa66fa989a7\"", "Cache-Control"=>"max-age=0, private, must-revalidate", "X-Request-Id"=>"f30153ff-3446-453a-a547-34c4b3766bfc", "X-Runtime"=>"0.455604"}, #<Rack::BodyProxy:0x00007f957960a430 @body=#<Rack::BodyProxy:0x00007f957f1c1f08 @body=#<Rack::BodyProxy:0x00007f957f1a8c10 @body=#<Rack::BodyProxy:0x00007f957f198040 @body=#<Rack::BodyProxy:0x00007f957f17bf58 @body=["[{\"id\":1,\"title\":\"The boy who cried 'wolf!'\",\"parentId\":1},{\"id\":2,\"title\":\"story 2\",\"parentId\":4},{\"id\":3,\"title\":\"story 3\",\"parentId\":null},{\"id\":4,\"title\":\"story 4\",\"parentId\":null},{\"id\":5,\"title\":\"story 1\",\"parentId\":null},{\"id\":6,\"title\":\"story 6\",\"parentId\":null},{\"id\":7,\"title\":\"story 7\",\"parentId\":null},{\"id\":8,\"title\":\"story 8\",\"parentId\":null},{\"id\":9,\"title\":\"story 9\",\"parentId\":null},{\"id\":10,\"title\":\"story 10\",\"parentId\":null},{\"id\":11,\"title\":\"story 11\",\"parentId\":null},{\"id\":12,\"title\":\"story 12\",\"parentId\":null},{\"id\":13,\"title\":\"story 13\",\"parentId\":null}]"], @block=#<Proc:0x00007f957f17ae78@/path/to/sampleapp/vendor/bundle/gems/rack-2.0.7/lib/rack/etag.rb:30>, @closed=false>, @block=#<Proc:0x00007f957f1a2d38@/path/to/sampleapp/vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/middleware/executor.rb:15>, @closed=false>, @block=#<Proc:0x00007f957f1b3728@/path/to/sampleapp/vendor/bundle/gems/railties-5.2.3/lib/rails/rack/logger.rb:39>, @closed=false>, @block=#<Proc:0x00007f957f1c07c0@/path/to/sampleapp/vendor/bundle/gems/activesupport-5.2.3/lib/active_support/cache/strategy/local_cache_middleware.rb:30>, @closed=false>, @block=#<Proc:0x00007f95796096c0@/path/to/sampleapp/vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/middleware/executor.rb:15>, @closed=false>]
         | 
| 92 | 
            +
            ```
         | 
| 93 | 
            +
             | 
| 94 | 
            +
            ## License
         | 
| 95 | 
            +
             | 
| 96 | 
            +
            The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
         | 
    
        data/Rakefile
    ADDED
    
    
    
        data/bin/console
    ADDED
    
    | @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
            # frozen_string_literal: true
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            require 'bundler/setup'
         | 
| 5 | 
            +
            require 'trace_location'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            # You can add fixtures and/or initialization code here to make experimenting
         | 
| 8 | 
            +
            # with your gem easier. You can also use a different console, if you like.
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            # (If you use this, don't forget to add pry to your Gemfile!)
         | 
| 11 | 
            +
            # require "pry"
         | 
| 12 | 
            +
            # Pry.start
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            require 'irb'
         | 
| 15 | 
            +
            IRB.start(__FILE__)
         | 
    
        data/bin/setup
    ADDED
    
    
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require_relative 'trace_location/version'
         | 
| 4 | 
            +
            require_relative 'trace_location/config'
         | 
| 5 | 
            +
            require_relative 'trace_location/tracer'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            begin
         | 
| 8 | 
            +
              require 'rails'
         | 
| 9 | 
            +
              require_relative 'trace_location/railtie'
         | 
| 10 | 
            +
            rescue LoadError
         | 
| 11 | 
            +
              nil
         | 
| 12 | 
            +
            end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            module TraceLocation # :nodoc:
         | 
| 15 | 
            +
              def self.trace(options = {}, &block)
         | 
| 16 | 
            +
                Tracer.new(options).call(&block)
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              def self.configure
         | 
| 20 | 
            +
                yield config
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              def self.config
         | 
| 24 | 
            +
                @config ||= Config.new
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
            end
         | 
| @@ -0,0 +1,12 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module TraceLocation
         | 
| 4 | 
            +
              class Railtie < ::Rails::Railtie # :nodoc:
         | 
| 5 | 
            +
                config.after_initialize do
         | 
| 6 | 
            +
                  ::TraceLocation.configure do |config|
         | 
| 7 | 
            +
                    config.root_dir = Rails.root
         | 
| 8 | 
            +
                    config.dest_dir = Rails.root.join('log')
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
            end
         | 
| @@ -0,0 +1,72 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module TraceLocation
         | 
| 4 | 
            +
              class Tracer # :nodoc:
         | 
| 5 | 
            +
                EVENTS = { call: 'C', return: 'R' }.freeze
         | 
| 6 | 
            +
                INDENT_SPACES = 2
         | 
| 7 | 
            +
                INDENT_STRING = ' '
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def initialize(options = {})
         | 
| 10 | 
            +
                  @root_dir = options.fetch(:root_dir) { TraceLocation.config.root_dir }
         | 
| 11 | 
            +
                  @dest_dir = options.fetch(:dest_dir) { TraceLocation.config.dest_dir }
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def call(&block)
         | 
| 15 | 
            +
                  logs = []
         | 
| 16 | 
            +
                  nest = 0
         | 
| 17 | 
            +
                  trace_point = TracePoint.new(:call, :return) do |tp|
         | 
| 18 | 
            +
                    case tp.event
         | 
| 19 | 
            +
                    when :call
         | 
| 20 | 
            +
                      logs << build_log(trace_point: tp, nest: nest, root_dir: root_dir)
         | 
| 21 | 
            +
                      nest += 1
         | 
| 22 | 
            +
                    when :return
         | 
| 23 | 
            +
                      nest = nest.positive? ? nest - 1 : 0
         | 
| 24 | 
            +
                      logs << build_log(trace_point: tp, nest: nest, root_dir: root_dir)
         | 
| 25 | 
            +
                    end
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  trace_point.enable
         | 
| 29 | 
            +
                  result = block.call
         | 
| 30 | 
            +
                  trace_point.disable
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  current = Time.now
         | 
| 33 | 
            +
                  filename = "trace_location-#{current.strftime('%Y%m%d%H%m%s')}.log"
         | 
| 34 | 
            +
                  file_path = File.join(dest_dir, filename)
         | 
| 35 | 
            +
                  File.open(file_path, 'w+') do |io|
         | 
| 36 | 
            +
                    io.puts "Logged by TraceLocation gem at #{current}"
         | 
| 37 | 
            +
                    io.puts 'https://github.com/yhirano55/trace_location'
         | 
| 38 | 
            +
                    io.puts
         | 
| 39 | 
            +
                    io.puts '[Tracing events] C: Call, R: Return'
         | 
| 40 | 
            +
                    io.puts
         | 
| 41 | 
            +
                    io.puts logs.join("\n")
         | 
| 42 | 
            +
                    io.puts
         | 
| 43 | 
            +
                    io.puts "Result: #{result.inspect}"
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
                  $stdout.puts "Created at #{file_path}"
         | 
| 46 | 
            +
                  true
         | 
| 47 | 
            +
                rescue StandardError => e
         | 
| 48 | 
            +
                  $stdout.puts "Failure: #{e.message}"
         | 
| 49 | 
            +
                  false
         | 
| 50 | 
            +
                ensure
         | 
| 51 | 
            +
                  trace_point.disable if trace_point.enabled?
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                private
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                attr_reader :root_dir, :dest_dir, :block
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                def build_log(trace_point:, nest:, root_dir:)
         | 
| 59 | 
            +
                  indent    = indent(nest)
         | 
| 60 | 
            +
                  event     = EVENTS[trace_point.event]
         | 
| 61 | 
            +
                  path      = trace_point.path.to_s.gsub(/#{root_dir}/, '')
         | 
| 62 | 
            +
                  lineno    = trace_point.lineno
         | 
| 63 | 
            +
                  method_id = trace_point.method_id
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                  %(#{indent}#{event} #{path}:#{lineno}##{method_id})
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                def indent(nest)
         | 
| 69 | 
            +
                  INDENT_STRING * (nest * INDENT_SPACES)
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
              end
         | 
| 72 | 
            +
            end
         | 
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            lib = File.expand_path('lib', __dir__)
         | 
| 4 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 5 | 
            +
            require 'trace_location/version'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Gem::Specification.new do |s|
         | 
| 8 | 
            +
              s.name          = 'trace_location'
         | 
| 9 | 
            +
              s.version       = TraceLocation::VERSION
         | 
| 10 | 
            +
              s.authors       = ['Yoshiyuki Hirano']
         | 
| 11 | 
            +
              s.email         = ['yhirano@me.com']
         | 
| 12 | 
            +
              s.homepage      = 'https://github.com/yhirano55/trace_location'
         | 
| 13 | 
            +
              s.summary       = 'logs a tracing result of :call and :return'
         | 
| 14 | 
            +
              s.description   = %(TraceLocation gem provides logs a tracing result of `:call` and `:return`. It's useful for reading the huge codes (e.g. Ruby on Rails) and tracing its process.)
         | 
| 15 | 
            +
              s.license       = 'MIT'
         | 
| 16 | 
            +
              s.files         = Dir.chdir(File.expand_path('.', __dir__)) do
         | 
| 17 | 
            +
                `git ls-files -z`.split("\x0").reject do |f|
         | 
| 18 | 
            +
                  f.match(%r{^(test|spec|features)/})
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
              s.bindir        = 'exe'
         | 
| 22 | 
            +
              s.executables   = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
| 23 | 
            +
              s.require_paths = ['lib']
         | 
| 24 | 
            +
              s.required_ruby_version = '>= 2.5.0'
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              s.add_development_dependency 'bundler', '~> 2.0'
         | 
| 27 | 
            +
              s.add_development_dependency 'rake', '~> 10.0'
         | 
| 28 | 
            +
              s.add_development_dependency 'rspec', '~> 3.0'
         | 
| 29 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,103 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: trace_location
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Yoshiyuki Hirano
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: exe
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2019-05-01 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: bundler
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '2.0'
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '2.0'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: rake
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '10.0'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '10.0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: rspec
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - "~>"
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '3.0'
         | 
| 48 | 
            +
              type: :development
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - "~>"
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '3.0'
         | 
| 55 | 
            +
            description: TraceLocation gem provides logs a tracing result of `:call` and `:return`.
         | 
| 56 | 
            +
              It's useful for reading the huge codes (e.g. Ruby on Rails) and tracing its process.
         | 
| 57 | 
            +
            email:
         | 
| 58 | 
            +
            - yhirano@me.com
         | 
| 59 | 
            +
            executables: []
         | 
| 60 | 
            +
            extensions: []
         | 
| 61 | 
            +
            extra_rdoc_files: []
         | 
| 62 | 
            +
            files:
         | 
| 63 | 
            +
            - ".gitignore"
         | 
| 64 | 
            +
            - ".rspec"
         | 
| 65 | 
            +
            - ".rubocop.yml"
         | 
| 66 | 
            +
            - ".travis.yml"
         | 
| 67 | 
            +
            - Gemfile
         | 
| 68 | 
            +
            - Gemfile.lock
         | 
| 69 | 
            +
            - LICENSE.txt
         | 
| 70 | 
            +
            - README.md
         | 
| 71 | 
            +
            - Rakefile
         | 
| 72 | 
            +
            - bin/console
         | 
| 73 | 
            +
            - bin/setup
         | 
| 74 | 
            +
            - lib/trace_location.rb
         | 
| 75 | 
            +
            - lib/trace_location/config.rb
         | 
| 76 | 
            +
            - lib/trace_location/railtie.rb
         | 
| 77 | 
            +
            - lib/trace_location/tracer.rb
         | 
| 78 | 
            +
            - lib/trace_location/version.rb
         | 
| 79 | 
            +
            - trace_location.gemspec
         | 
| 80 | 
            +
            homepage: https://github.com/yhirano55/trace_location
         | 
| 81 | 
            +
            licenses:
         | 
| 82 | 
            +
            - MIT
         | 
| 83 | 
            +
            metadata: {}
         | 
| 84 | 
            +
            post_install_message: 
         | 
| 85 | 
            +
            rdoc_options: []
         | 
| 86 | 
            +
            require_paths:
         | 
| 87 | 
            +
            - lib
         | 
| 88 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 89 | 
            +
              requirements:
         | 
| 90 | 
            +
              - - ">="
         | 
| 91 | 
            +
                - !ruby/object:Gem::Version
         | 
| 92 | 
            +
                  version: 2.5.0
         | 
| 93 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 94 | 
            +
              requirements:
         | 
| 95 | 
            +
              - - ">="
         | 
| 96 | 
            +
                - !ruby/object:Gem::Version
         | 
| 97 | 
            +
                  version: '0'
         | 
| 98 | 
            +
            requirements: []
         | 
| 99 | 
            +
            rubygems_version: 3.0.3
         | 
| 100 | 
            +
            signing_key: 
         | 
| 101 | 
            +
            specification_version: 4
         | 
| 102 | 
            +
            summary: logs a tracing result of :call and :return
         | 
| 103 | 
            +
            test_files: []
         |