after_do-logging 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 127b1d540e43144825a3dfff1977b1c5dd25e866
4
+ data.tar.gz: 7d00f828f88e4e97be6042a08a535cb567dee51a
5
+ SHA512:
6
+ metadata.gz: e5722d78d4b5a1c17c6ddcc543196519ffcc635d619229b2628f47194ad30204cedca402ca85237335772dc058f128f4b6bdc40d7c6bba9e437ce6b957066614
7
+ data.tar.gz: 12056a9b8b3dac271c557e02c103eba3c2d1c55b56747956be1358953f0b144392d7cfddca611c8d61000b1f9cb108cf775a3af0b52107397d8fc4c6b50d469b
data/.git_hooks.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ pre_commits:
3
+ - GitHooks::PreCommit::TrailingWhitespace
4
+ - GitHooks::PreCommit::PreventDebugger
5
+ - GitHooks::PreCommit::PreventMaster
6
+ - GitHooks::PreCommit::Rubocop
7
+ - GitHooks::PreCommit::Rspec
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ Documentation:
2
+ Enabled: false
3
+
4
+ ClassAndModuleChildren:
5
+ Enabled: false
6
+
7
+ AllCops:
8
+ # Include gemspec and Rakefile
9
+ Include:
10
+ - '**/*.gemspec'
11
+ - '**/Rakefile'
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in after_do-logging.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Rafael da Silva Almeida
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # AfterDo::Logging
2
+
3
+ After do aspect for logging method start and finish
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'after_do-logging'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install after_do-logging
18
+
19
+ ## Usage
20
+
21
+ Configure your aspect to use AfterDo::Logging.
22
+
23
+ ### Set your logger
24
+
25
+ ```ruby
26
+ AfterDo::Logging.logger = logger
27
+ ```
28
+
29
+ PS: Is advisable to use [after-do-loader][after_do-loader] to load your aspects.
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/stupied4ever/after_do-logging/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
38
+
39
+ [after-do-loader]: https://github.com/rranelli/after_do-loader
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'after_do/logging/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'after_do-logging'
7
+ spec.version = AfterDo::Logging::VERSION
8
+ spec.authors = ['Rafael da Silva', 'Renan Ranelli']
9
+ spec.email = ['rubygems@rafaelalmeida.net', 'renanranelli@gmail.com']
10
+ spec.summary = 'After do aspect for logging method start and finish.'
11
+ spec.description = 'After do aspect for logging method start and finish.'
12
+ spec.homepage = ''
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'after_do', '~> 0.3'
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+ spec.add_development_dependency 'git-hooks', '~> 0.2'
25
+ end
@@ -0,0 +1,40 @@
1
+ module AfterDo
2
+ module Logging
3
+ class Aspect
4
+ def initialize(target_class, logger = AfterDo::Logging.logger)
5
+ @target_class = target_class
6
+ @logger = logger
7
+ end
8
+
9
+ def log_start(target_method)
10
+ target_class.before target_method do |*args, _|
11
+ start_time = Time.now
12
+ method = "#{target_class}##{target_method}"
13
+
14
+ log_step(method, start_time, args)
15
+ end
16
+ end
17
+
18
+ def log_finish(target_method)
19
+ target_class.after target_method do |*args, _|
20
+ finish_time = Time.now
21
+ method = "#{target_class}##{target_method}"
22
+
23
+ log_step(method, finish_time, args)
24
+ end
25
+ end
26
+
27
+ protected
28
+
29
+ attr_reader :target_class, :logger
30
+
31
+ private
32
+
33
+ def log_step(method, time, args)
34
+ arg_text = args.map(&:inspect).join(', ')
35
+ msg = "Finished: Method=#{method} Time=#{time} Args='#{arg_text}'"
36
+ logger.info(msg)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ module AfterDo
2
+ module Logging
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ require 'after_do'
2
+ require 'logger'
3
+ require_relative 'logging/version'
4
+ require_relative 'logging/aspect'
5
+
6
+ module AfterDo
7
+ module Logging
8
+ @logger = Logger.new(STDOUT)
9
+
10
+ class << self
11
+ attr_accessor :logger
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,43 @@
1
+ module AfterDo::Logging
2
+ describe Aspect do
3
+ subject(:aspect) { described_class.new(klass, logger) }
4
+
5
+ let(:klass) { Class.new.extend(AfterDo) }
6
+ let(:method) { :inspect }
7
+ let(:logger) { double(:logger, info: nil) }
8
+
9
+ describe '#log_start' do
10
+ subject(:log_start) { aspect.log_start(method) }
11
+
12
+ it 'applies the advice before target method invocation' do
13
+ expect(klass).to receive(:before).with(method)
14
+
15
+ log_start
16
+ end
17
+
18
+ it 'calls logger when instance invokes advised method' do
19
+ expect(logger).to receive(:info)
20
+
21
+ log_start
22
+ klass.new.inspect
23
+ end
24
+ end
25
+
26
+ describe '#log_finish' do
27
+ subject(:log_finish) { aspect.log_finish(method) }
28
+
29
+ it 'applies the advice after target method invocation' do
30
+ expect(klass).to receive(:after).with(method)
31
+
32
+ log_finish
33
+ end
34
+
35
+ it 'calls logger when instance invokes advised method' do
36
+ expect(logger).to receive(:info)
37
+
38
+ log_finish
39
+ klass.new.inspect
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,21 @@
1
+ module AfterDo::Logging
2
+ describe AfterDo::Logging do
3
+ describe '.logger' do
4
+ subject(:logger) { described_class.logger }
5
+
6
+ it { is_expected.to be_a(Logger) }
7
+ end
8
+
9
+ describe '.logger=(value)' do
10
+ subject(:update_logger) { described_class.logger = new_logger }
11
+
12
+ let(:new_logger) { double(:new_logger) }
13
+
14
+ it do
15
+ expect { update_logger }.to change {
16
+ AfterDo::Logging.logger
17
+ }.to(new_logger)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ require 'git-hooks'
2
+
3
+ GitHooks.validate_hooks!
4
+
5
+ require_relative '../lib/after_do/logging'
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: after_do-logging
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rafael da Silva
8
+ - Renan Ranelli
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-09-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: after_do
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.3'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.6'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.6'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: git-hooks
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '0.2'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '0.2'
84
+ description: After do aspect for logging method start and finish.
85
+ email:
86
+ - rubygems@rafaelalmeida.net
87
+ - renanranelli@gmail.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".git_hooks.yml"
93
+ - ".gitignore"
94
+ - ".rspec"
95
+ - ".rubocop.yml"
96
+ - Gemfile
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - after_do-logging.gemspec
101
+ - lib/after_do/logging.rb
102
+ - lib/after_do/logging/aspect.rb
103
+ - lib/after_do/logging/version.rb
104
+ - spec/after_do/logging/aspect_spec.rb
105
+ - spec/after_do/logging_spec.rb
106
+ - spec/spec_helper.rb
107
+ homepage: ''
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.2.2
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: After do aspect for logging method start and finish.
131
+ test_files:
132
+ - spec/after_do/logging/aspect_spec.rb
133
+ - spec/after_do/logging_spec.rb
134
+ - spec/spec_helper.rb
135
+ has_rdoc: