call_logger 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 613db64e5b8ff52a92392341f19cc625aa28ced3f27c15a38da75096eadf5d48
4
+ data.tar.gz: f459c45b112209952385bf5b5a2b554cb36743d894b8af784a34c128dac501cf
5
+ SHA512:
6
+ metadata.gz: 335789e5630e506a0b3619714b5b94dbb67d94b8239c3208804cc070d0b1a5caf08178f4085e351110d2c84429fc9534bd929754757b37cedeb1cd0d923afcea
7
+ data.tar.gz: f16262c8c53c6e572f7dcb2ca1db6d99a39ccaf781c77fb39d91abe3f66c0a9876376f862f3bebd5e6486b05109adc41aa7e3e187199d1c8be8a853169512634
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in call_logger.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ call_logger (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ diff-lcs (1.3)
11
+ method_source (0.9.2)
12
+ pry (0.12.2)
13
+ coderay (~> 1.1.0)
14
+ method_source (~> 0.9.0)
15
+ pry-doc (0.13.5)
16
+ pry (~> 0.11)
17
+ yard (~> 0.9.11)
18
+ rake (10.5.0)
19
+ rspec (3.8.0)
20
+ rspec-core (~> 3.8.0)
21
+ rspec-expectations (~> 3.8.0)
22
+ rspec-mocks (~> 3.8.0)
23
+ rspec-core (3.8.0)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-expectations (3.8.2)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-mocks (3.8.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.8.0)
31
+ rspec-support (3.8.0)
32
+ yard (0.9.16)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ bundler (~> 1.16)
39
+ call_logger!
40
+ pry
41
+ pry-doc
42
+ rake (~> 10.0)
43
+ rspec (~> 3.0)
44
+
45
+ BUNDLED WITH
46
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Maciej Rzasa
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,101 @@
1
+ # CallLogger
2
+
3
+ A debugging tool that let you log method usage.
4
+
5
+ ```
6
+ class Calculator
7
+ include CallLogger
8
+
9
+ log def times(a, b)
10
+ a*b
11
+ end
12
+ end
13
+
14
+ Calculator.new.times(3,4)
15
+ # times(2, 3)
16
+ # times => 6
17
+ # => 7
18
+ ```
19
+
20
+ ## Installation
21
+
22
+ Add this line to your application's Gemfile:
23
+
24
+ ```ruby
25
+ gem 'call_logger'
26
+ ```
27
+
28
+ And then execute:
29
+
30
+ $ bundle
31
+
32
+ Or install it yourself as:
33
+
34
+ $ gem install call_logger
35
+
36
+ ## Usage
37
+
38
+ Include it to a class being debugged and the prepend a method definition with `log`:
39
+
40
+ ```
41
+ class Calculator
42
+ include CallLogger
43
+
44
+ log def times(a, b)
45
+ a*b
46
+ end
47
+ end
48
+ ```
49
+
50
+ `.log` accepts method name, so you can pass it explicitly:
51
+
52
+ ```
53
+ class Calculator
54
+ include CallLogger
55
+
56
+ def times(a, b)
57
+ a*b
58
+ end
59
+
60
+ log :times
61
+ end
62
+ ```
63
+
64
+ ### Configuration
65
+
66
+ There are two pluggable components: `Logger` and `Formatter`. `Formatter` preperes messages to be printed and `Logger` sents them to the
67
+ output stream (whatever it is). This documentation uses default ones, but they can be easily configured:
68
+
69
+ ```
70
+ ::CallLogger.configure do |config|
71
+ config.logger = CustomLogger.new
72
+ config.formatter = CustomFormatter.new
73
+ end
74
+ ```
75
+
76
+ * `Logger` should provide a `#call` method accepting a single paramter.
77
+ * `Formatter` should provide two methods:
78
+ * `#begin_message(method, args)` - accepting method name and it's arguments; called before method execution
79
+ * `#end_message(method, result)` - accepting method name and it's result; called after method execution
80
+
81
+ ## TODO
82
+
83
+ * [] class methods
84
+ * [] multiple method names
85
+ * [] handle blocks
86
+ * [] logging all methods defined in the class
87
+ * [] doc: Rails integration
88
+
89
+ ## Development
90
+
91
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
92
+
93
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
94
+
95
+ ## Contributing
96
+
97
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/call_logger.
98
+
99
+ ## License
100
+
101
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "call_logger"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "call_logger/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "call_logger"
8
+ spec.version = CallLogger::VERSION
9
+ spec.authors = ["Maciej Rzasa"]
10
+ spec.email = ["maciejrzasa@gmail.com"]
11
+
12
+ spec.summary = %q{Debugging tool that logs parameters and results of calling bloks and methods.}
13
+ spec.description = %q{Decorate a method or wrap a code block to see in logs when they're called.}
14
+ spec.homepage = "https://github.com/mrzasa/call_logger"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "pry"
30
+ spec.add_development_dependency "pry-doc"
31
+ end
@@ -0,0 +1,17 @@
1
+ module CallLogger
2
+ class CallLogger
3
+ attr_reader :formatter, :logger
4
+
5
+ def initialize(formatter:, logger: )
6
+ @formatter = formatter
7
+ @logger = logger
8
+ end
9
+
10
+ def log(method, args)
11
+ logger.call(formatter.begin_message(method, args))
12
+ result = yield
13
+ logger.call(formatter.end_message(method, result))
14
+ result
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ module CallLogger
2
+ class Configuration
3
+ attr_accessor :logger, :formatter
4
+
5
+ def logger
6
+ @logger || ::CallLogger::Logger.new
7
+ end
8
+
9
+ def formatter
10
+ @formatter || ::CallLogger::Formatter.new
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module CallLogger
2
+ class Formatter
3
+ def begin_message(method, args)
4
+ "#{method}(#{args.join(', ')})"
5
+ end
6
+
7
+ # args?
8
+ def end_message(method, result)
9
+ "#{method} => #{result}"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ module CallLogger
2
+ # Simple puts logger
3
+ class Logger
4
+ def call(message)
5
+ puts message
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module CallLogger
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,37 @@
1
+ require "call_logger/version"
2
+
3
+ require 'call_logger/formatter'
4
+ require 'call_logger/logger'
5
+ require 'call_logger/configuration'
6
+ require 'call_logger/call_logger'
7
+
8
+ module CallLogger
9
+ def self.included(base)
10
+ base.extend(ClassMethods)
11
+ end
12
+
13
+ class << self
14
+ attr_accessor :configuration
15
+ end
16
+
17
+ def self.configure
18
+ self.configuration ||= Configuration.new
19
+ yield(configuration)
20
+ end
21
+
22
+ def log(method, args, &block)
23
+ call_logger = ::CallLogger::CallLogger.new(logger: ::CallLogger.configuration.logger, formatter: ::CallLogger.configuration.formatter)
24
+ call_logger.log(method, args, &block)
25
+ end
26
+
27
+ module ClassMethods
28
+ def log(method)
29
+ alias_method "#{method}_without_log", method
30
+ define_method method do |*args|
31
+ log(method, args) do
32
+ send("#{method}_without_log", *args)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: call_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Maciej Rzasa
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-22 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: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-doc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Decorate a method or wrap a code block to see in logs when they're called.
84
+ email:
85
+ - maciejrzasa@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - call_logger.gemspec
101
+ - lib/call_logger.rb
102
+ - lib/call_logger/call_logger.rb
103
+ - lib/call_logger/configuration.rb
104
+ - lib/call_logger/formatter.rb
105
+ - lib/call_logger/logger.rb
106
+ - lib/call_logger/version.rb
107
+ homepage: https://github.com/mrzasa/call_logger
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.7.7
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Debugging tool that logs parameters and results of calling bloks and methods.
131
+ test_files: []