okuribito 0.1.3 → 0.1.4

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: d7493f6fcde494c7876664a9e9f08bd7ead6f424
4
- data.tar.gz: 457a6555c87a74574bcd5e9876522116af76659c
3
+ metadata.gz: 546ff74e85424ffdd61c223346d05db2df28232c
4
+ data.tar.gz: 3972e942e590bc37402de3ffcdc7ead2bcaad654
5
5
  SHA512:
6
- metadata.gz: 7a2b5d71abdf9659e15a197e4a2dcb4f3eef06609ef5b1a823c2f04cf7d5fc9e7fd0f86fb1e05a7c63d7114fbbd1886b8f59b01a4c3d7c84722d043e38f6e966
7
- data.tar.gz: 36048f58088c47ee0598c0cdb1cbd7737de7e119a62ca4c72a78f012db7a7a4caadf9da8158509d81928f96fd27df43d4ab1ca72a1e219ff6c663243f5f3045d
6
+ metadata.gz: 1a52c32a171b6a7f6fddfe0f4c181d7b6e6bd7bdba80c1597a63bf3e06c1d5ebc7d76c127ced27aa4b65bdf0b6299a48a36dc0e46ef05cc09bea9b08e1795f2a
7
+ data.tar.gz: def1c5cba98bfbd1d0a6549712e7497f91da83a162e61a8a506923def5460b2aed7796f8abe505a65cd5d0b822ba31482812f33956d2df31fdbd9c92e6e27aee
data/.rubocop.yml CHANGED
@@ -20,7 +20,7 @@ Metrics/CyclomaticComplexity:
20
20
  Max: 10
21
21
 
22
22
  Metrics/PerceivedComplexity:
23
- Max: 10
23
+ Max: 9
24
24
 
25
25
  Metrics/MethodLength:
26
26
  Max: 20
data/README.md CHANGED
@@ -2,10 +2,14 @@
2
2
 
3
3
  # Okuribito
4
4
 
5
+ https://rubygems.org/gems/okuribito
6
+
5
7
  ![okuribito](okuribito_logo.png)
6
8
 
7
9
  Okuribito is a gem to judge whether methods should be sent to the heaven :innocent:.
10
+
8
11
  In other words, it can be used in order to extract the obsolete method.
12
+
9
13
  Okuribito was named after a japanese movie.
10
14
 
11
15
  ## Installation
@@ -122,33 +126,6 @@ okuribito = Okuribito::OkuribitoPatch.new do |method_name, obj_name, caller_info
122
126
  end
123
127
  ```
124
128
 
125
- ### Send to slack
126
-
127
- ```ruby
128
- okuribito = Okuribito::OkuribitoPatch.new do |method_name, obj_name, caller_info|
129
- uri = URI.parse("https://hooks.slack.com/services/xxx...")
130
- params = {
131
- text: "OKURIBITO detect a method call.",
132
- username: "OKURIBITO",
133
- icon_emoji: ":innocent:",
134
- attachments: [{
135
- fields: [{
136
- title: "#{obj_name}::#{method_name}",
137
- value: "#{caller_info[0]}",
138
- short: false
139
- }]
140
- }]
141
- }
142
- http = Net::HTTP.new(uri.host, uri.port)
143
- http.use_ssl = true
144
- http.start do
145
- request = Net::HTTP::Post.new(uri.path)
146
- request.set_form_data(payload: params.to_json)
147
- http.request(request)
148
- end
149
- end
150
- ```
151
-
152
129
  ### Other ideas
153
130
  - Send to Fluentd, TreasureData, Slack...
154
131
 
data/lib/okuribito.rb CHANGED
@@ -15,7 +15,7 @@ module Okuribito
15
15
  end
16
16
 
17
17
  module SimplePatchModule
18
- def define_okuribito_patch(method_name, _opt = {})
18
+ def define_patch(method_name, _patch, _id, _opt = {})
19
19
  define_method(method_name) do |*args|
20
20
  yield(to_s, caller) if block_given?
21
21
  super(*args)
@@ -24,12 +24,12 @@ module Okuribito
24
24
  end
25
25
 
26
26
  module FunctionalPatchModule
27
- def define_okuribito_patch(method_name, opt = {})
28
- instance_variable_set("@#{method_name}_called", false)
27
+ def define_patch(method_name, patch, id, opt = {})
28
+ patch.instance_variable_set("@#{method_name}_#{id}_called", false)
29
29
  define_method(method_name) do |*args|
30
- if block_given? && !instance_variable_get("@#{method_name}_called")
30
+ if block_given? && !patch.instance_variable_get("@#{method_name}_#{id}_called")
31
31
  yield(to_s, caller)
32
- instance_variable_set("@#{method_name}_called", true) if opt[:once_detect]
32
+ patch.instance_variable_set("@#{method_name}_#{id}_called", true) if opt[:once_detect]
33
33
  end
34
34
  super(*args)
35
35
  end
@@ -50,14 +50,26 @@ module Okuribito
50
50
 
51
51
  klass.class_eval do
52
52
  if opt.present?
53
- instance_method_patch = Module.new.extend(FunctionalPatchModule)
54
- class_method_patch = Module.new.extend(FunctionalPatchModule)
53
+ i_patch_name = "#{class_name}InstancePatch"
54
+ c_patch_name = "#{class_name}ClassPatch"
55
+ if FunctionalPatchModule.const_defined?(i_patch_name.to_sym)
56
+ i_method_patch = Module.new.extend(FunctionalPatchModule)
57
+ else
58
+ i_method_patch = FunctionalPatchModule
59
+ .const_set(i_patch_name, Module.new.extend(FunctionalPatchModule))
60
+ end
61
+ if FunctionalPatchModule.const_defined?(c_patch_name.to_sym)
62
+ c_method_patch = Module.new.extend(FunctionalPatchModule)
63
+ else
64
+ c_method_patch = FunctionalPatchModule
65
+ .const_set(c_patch_name, Module.new.extend(FunctionalPatchModule))
66
+ end
55
67
  else
56
- instance_method_patch = Module.new.extend(SimplePatchModule)
57
- class_method_patch = Module.new.extend(SimplePatchModule)
68
+ i_method_patch = Module.new.extend(SimplePatchModule)
69
+ c_method_patch = Module.new.extend(SimplePatchModule)
58
70
  end
59
- instance_method_patched = 0
60
- class_method_patched = 0
71
+ i_method_patched = 0
72
+ c_method_patched = 0
61
73
 
62
74
  observe_methods.each do |observe_method|
63
75
  next unless md = PATTERN.match(observe_method)
@@ -67,24 +79,24 @@ module Okuribito
67
79
  case symbol
68
80
  when INSTANCE_METHOD_SYMBOL
69
81
  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|
82
+ i_method_patch.module_eval do
83
+ define_patch(method_name, i_method_patch, "i", opt) do |obj_name, caller_info|
72
84
  callback.call(method_name, obj_name, caller_info)
73
85
  end
74
86
  end
75
- instance_method_patched += 1
87
+ i_method_patched += 1
76
88
  when CLASS_METHOD_SYMBOL
77
89
  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|
90
+ c_method_patch.module_eval do
91
+ define_patch(method_name, c_method_patch, "c", opt) do |obj_name, caller_info|
80
92
  callback.call(method_name, obj_name, caller_info)
81
93
  end
82
94
  end
83
- class_method_patched += 1
95
+ c_method_patched += 1
84
96
  end
85
97
  end
86
- prepend instance_method_patch if instance_method_patched > 0
87
- singleton_class.send(:prepend, class_method_patch) if class_method_patched > 0
98
+ prepend i_method_patch if i_method_patched > 0
99
+ singleton_class.send(:prepend, c_method_patch) if c_method_patched > 0
88
100
  end
89
101
  end
90
102
  end
@@ -1,3 +1,3 @@
1
1
  module Okuribito
2
- VERSION = "0.1.3".freeze
2
+ VERSION = "0.1.4".freeze
3
3
  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.3
4
+ version: 0.1.4
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-08 00:00:00.000000000 Z
11
+ date: 2016-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport