okuribito 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3763c8c0fbdd9746f7e5d50595cb3c07d27e2eb5
4
- data.tar.gz: b16c90b7bc3cee2fa02bf79983fa7b960a0c0f4c
3
+ metadata.gz: d7493f6fcde494c7876664a9e9f08bd7ead6f424
4
+ data.tar.gz: 457a6555c87a74574bcd5e9876522116af76659c
5
5
  SHA512:
6
- metadata.gz: ad61526fedb01ab3b98455ff22bfa06d22c3b2ed7e09496f17df83683915c6b9ee2794a99ee4b26d63702038dd876aabf2d1ebfbe9f027b2aee589846dc6be43
7
- data.tar.gz: ae050960f27604a7e1a91cda18a808f99db126030e734e39b1738c471fa8c63ca0123a83fc655ec14aedc7461da3a8d1f614c4e6e474377d19c3ee54a890e5be
6
+ metadata.gz: 7a2b5d71abdf9659e15a197e4a2dcb4f3eef06609ef5b1a823c2f04cf7d5fc9e7fd0f86fb1e05a7c63d7114fbbd1886b8f59b01a4c3d7c84722d043e38f6e966
7
+ data.tar.gz: 36048f58088c47ee0598c0cdb1cbd7737de7e119a62ca4c72a78f012db7a7a4caadf9da8158509d81928f96fd27df43d4ab1ca72a1e219ff6c663243f5f3045d
data/.rubocop.yml ADDED
@@ -0,0 +1,29 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'okuribito.gemspec'
4
+ - 'spec/spec_helper.rb'
5
+
6
+ Documentation:
7
+ Enabled: false
8
+
9
+ LineLength:
10
+ Max: 100
11
+ Exclude:
12
+ - "spec/**/*"
13
+
14
+ Style/StringLiterals:
15
+ EnforcedStyle: double_quotes
16
+ SupportedStyles:
17
+ - double_quotes
18
+
19
+ Metrics/CyclomaticComplexity:
20
+ Max: 10
21
+
22
+ Metrics/PerceivedComplexity:
23
+ Max: 10
24
+
25
+ Metrics/MethodLength:
26
+ Max: 20
27
+
28
+ Metrics/AbcSize:
29
+ Max: 30
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
  gemspec
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
+ [![CircleCI](https://circleci.com/gh/muramurasan/okuribito/tree/master.svg?style=svg)](https://circleci.com/gh/muramurasan/okuribito/tree/master)
2
+
1
3
  # Okuribito
2
4
 
3
5
  ![okuribito](okuribito_logo.png)
4
6
 
5
7
  Okuribito is a gem to judge whether methods should be sent to the heaven :innocent:.
8
+ In other words, it can be used in order to extract the obsolete method.
6
9
  Okuribito was named after a japanese movie.
7
10
 
8
11
  ## Installation
@@ -32,6 +35,28 @@ Micropost:
32
35
  - '.from_users_followed_by'
33
36
  ```
34
37
 
38
+ By writing the following code to start the monitoring of the method.
39
+
40
+ ```ruby
41
+ okuribito = Okuribito::OkuribitoPatch.new do |method_name, obj_name, caller_info|
42
+ # TODO: do something as you like!
43
+ end
44
+ okuribito.apply("okuribito.yml")
45
+ ```
46
+
47
+ You can also give the option.
48
+
49
+ `once_detect`: When it detects a method call, and run only once the code that has been set.
50
+
51
+ ```ruby
52
+ okuribito = Okuribito::OkuribitoPatch.new(once_detect: true) do |method_name, obj_name, caller_info|
53
+ # TODO: do something as you like!
54
+ end
55
+ okuribito.apply("okuribito.yml")
56
+ ```
57
+
58
+ ### ex: Ruby On Rails
59
+
35
60
  Edit `application.rb`
36
61
 
37
62
  ```ruby
@@ -103,7 +128,7 @@ end
103
128
  okuribito = Okuribito::OkuribitoPatch.new do |method_name, obj_name, caller_info|
104
129
  uri = URI.parse("https://hooks.slack.com/services/xxx...")
105
130
  params = {
106
- text: "OKURIBITO detected a method call.",
131
+ text: "OKURIBITO detect a method call.",
107
132
  username: "OKURIBITO",
108
133
  icon_emoji: ":innocent:",
109
134
  attachments: [{
@@ -125,7 +150,7 @@ end
125
150
  ```
126
151
 
127
152
  ### Other ideas
128
- - Send to Fluentd, TreasureData
153
+ - Send to Fluentd, TreasureData, Slack...
129
154
 
130
155
  ## License
131
156
 
data/Rakefile CHANGED
@@ -3,4 +3,4 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/lib/okuribito.rb CHANGED
@@ -9,14 +9,28 @@ module Okuribito
9
9
  INSTANCE_METHOD_SYMBOL = "#".freeze
10
10
  PATTERN = /\A(?<symbol>[#{CLASS_METHOD_SYMBOL}#{INSTANCE_METHOD_SYMBOL}])(?<method_name>.+)\z/
11
11
 
12
- def initialize(&callback)
12
+ def initialize(opt = {}, &callback)
13
13
  @callback = callback
14
+ @opt ||= opt
14
15
  end
15
16
 
16
- module PatchModule
17
- def define_okuribito_patch(method_name)
17
+ module SimplePatchModule
18
+ def define_okuribito_patch(method_name, _opt = {})
18
19
  define_method(method_name) do |*args|
19
- yield(self.to_s, caller) if block_given?
20
+ yield(to_s, caller) if block_given?
21
+ super(*args)
22
+ end
23
+ end
24
+ end
25
+
26
+ module FunctionalPatchModule
27
+ def define_okuribito_patch(method_name, opt = {})
28
+ instance_variable_set("@#{method_name}_called", false)
29
+ define_method(method_name) do |*args|
30
+ if block_given? && !instance_variable_get("@#{method_name}_called")
31
+ yield(to_s, caller)
32
+ instance_variable_set("@#{method_name}_called", true) if opt[:once_detect]
33
+ end
20
34
  super(*args)
21
35
  end
22
36
  end
@@ -30,36 +44,43 @@ module Okuribito
30
44
  end
31
45
 
32
46
  def patch_okuribito(class_name, observe_methods)
33
- callback = @callback # スコープを乗り越えるために使用.
47
+ callback = @callback
48
+ opt ||= @opt
34
49
  klass = class_name.constantize
35
50
 
36
51
  klass.class_eval do
37
- instance_method_patch = Module.new.extend(PatchModule)
38
- class_method_patch = Module.new.extend(PatchModule)
52
+ if opt.present?
53
+ instance_method_patch = Module.new.extend(FunctionalPatchModule)
54
+ class_method_patch = Module.new.extend(FunctionalPatchModule)
55
+ else
56
+ instance_method_patch = Module.new.extend(SimplePatchModule)
57
+ class_method_patch = Module.new.extend(SimplePatchModule)
58
+ end
39
59
  instance_method_patched = 0
40
60
  class_method_patched = 0
41
61
 
42
62
  observe_methods.each do |observe_method|
43
63
  next unless md = PATTERN.match(observe_method)
44
- symbol, method_name = md[:symbol], md[:method_name].to_sym
64
+ symbol = md[:symbol]
65
+ method_name = md[:method_name].to_sym
45
66
 
46
67
  case symbol
47
- when INSTANCE_METHOD_SYMBOL
48
- next unless klass.instance_methods.include?(method_name)
49
- instance_method_patch.module_eval do
50
- define_okuribito_patch(method_name) do |obj_name, caller_info|
51
- callback.call(method_name, obj_name, caller_info)
52
- end
68
+ when INSTANCE_METHOD_SYMBOL
69
+ next unless klass.instance_methods.include?(method_name)
70
+ instance_method_patch.module_eval do
71
+ define_okuribito_patch(method_name, opt) do |obj_name, caller_info|
72
+ callback.call(method_name, obj_name, caller_info)
53
73
  end
54
- instance_method_patched += 1
55
- when CLASS_METHOD_SYMBOL
56
- next unless klass.respond_to?(method_name)
57
- class_method_patch.module_eval do
58
- define_okuribito_patch(method_name) do |obj_name, caller_info|
59
- callback.call(method_name, obj_name, caller_info)
60
- end
74
+ end
75
+ instance_method_patched += 1
76
+ when CLASS_METHOD_SYMBOL
77
+ next unless klass.respond_to?(method_name)
78
+ class_method_patch.module_eval do
79
+ define_okuribito_patch(method_name, opt) do |obj_name, caller_info|
80
+ callback.call(method_name, obj_name, caller_info)
61
81
  end
62
- class_method_patched += 1
82
+ end
83
+ class_method_patched += 1
63
84
  end
64
85
  end
65
86
  prepend instance_method_patch if instance_method_patched > 0
@@ -1,3 +1,3 @@
1
1
  module Okuribito
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3".freeze
3
3
  end
data/okuribito.gemspec CHANGED
@@ -35,4 +35,5 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency "bundler", "~> 1.12"
36
36
  spec.add_development_dependency "rake", "~> 10.0"
37
37
  spec.add_development_dependency "rspec", "~> 3.0"
38
+ spec.add_development_dependency "rubocop"
38
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: okuribito
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - muramurasan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-04 00:00:00.000000000 Z
11
+ date: 2016-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: Okuribito monitors the method call by the yaml.
84
98
  email:
85
99
  - ym.works1985@gmail.com
@@ -89,6 +103,7 @@ extra_rdoc_files: []
89
103
  files:
90
104
  - .gitignore
91
105
  - .rspec
106
+ - .rubocop.yml
92
107
  - CODE_OF_CONDUCT.md
93
108
  - Gemfile
94
109
  - LICENSE.txt