tbpgr_utils 0.0.130 → 0.0.131

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: 1eb04c565481f5ab296a1c437ca8a6726cf0d323
4
- data.tar.gz: e830aa0554fbbfff121de0c298308d5abe06bb5c
3
+ metadata.gz: 4b7e402e0ba1ee0fe2e78603df0a90e3b97aaaf0
4
+ data.tar.gz: 2a7db9c42c304d6a8a16f8c615d3a73d0ba2d5ff
5
5
  SHA512:
6
- metadata.gz: bd3b83a7a389fb208c032f7e142d39fe99398410b378777efe39cbdcd4e1b047de1cc47681d3f3c28b0bf749fe8eeac054aafa4103e04f3a0cf6ecac4547ed9f
7
- data.tar.gz: bd5f37724aa036a7e1f8ae46a86c234b86b6f84fc5c627ef26673ae3e7b71f26529b6edbf72c2904b4977b95bce7d37f955c361f9922b7209184fa336747022f
6
+ metadata.gz: f2973367c239dbfb2f29945d8580c8603935708fff1fe91cb5a8165230da5b253e961542e0e3c774b268bd515dc5f09b37dc2fac89fa5ccc008e5cb3887f43dc
7
+ data.tar.gz: 4289ec765b20ee6463475794c5579b9ed85e079f870c8cf803990c2588b8896104e3bf8a0042bf513d893199e324efa3689f5f13515d860a8771ba5abec6d6b6
data/README.md CHANGED
@@ -132,6 +132,8 @@ Or install it yourself as:
132
132
  |[TbpgrUtils Object#any_of?](#objectany_of) |if self match any one of items, return true |
133
133
  |[TbpgrUtils Object#boolean?](#objectboolean) |data type check for boolean |
134
134
  |[TbpgrUtils Object#grep_method](#objectgrep_method) |grep class method |
135
+ |[TbpgrUtils Object#grep_private_instance_method](#objectgrep_private_instance_method) |grep private instance method |
136
+ |[TbpgrUtils Object#grep_protected_instance_method](#objectgrep_protected_instance_method) |grep protected instance method |
135
137
  |[TbpgrUtils Object#grep_public_instance_method](#objectgrep_public_instance_method) |grep public instance method |
136
138
  |[TbpgrUtils Object#guard](#objectguard) |data type check for guard |
137
139
  |[TbpgrUtils Object#method_nameable?](#objectmethod_nameable) |object can use method name or not |
@@ -2943,7 +2945,7 @@ hoge false # => "not guard"
2943
2945
  target class
2944
2946
 
2945
2947
  ~~~ruby
2946
- require 'tbpbr_utils'
2948
+ require 'tbpgr_utils'
2947
2949
 
2948
2950
  class GrepMethod
2949
2951
  def self.public_method1;end
@@ -2971,12 +2973,68 @@ GrepMethod.grep_method :__send__, true # => [:__send__]
2971
2973
 
2972
2974
  [back to list](#list)
2973
2975
 
2976
+ ### Object#grep_private_instance_method
2977
+ ~~~ruby
2978
+ require 'tbpgr_utils'
2979
+
2980
+ # target class
2981
+ class GrepInstanceMethod
2982
+ def public_method1;end
2983
+ def public_method2;end
2984
+ def public_method11;end
2985
+ protected
2986
+ def protected_method1;end
2987
+ def protected_method2;end
2988
+ def protected_method11;end
2989
+ private
2990
+ def private_method1;end
2991
+ def private_method2;end
2992
+ def private_method11;end
2993
+ end
2994
+
2995
+ # method call
2996
+ GrepInstanceMethod.new.grep_private_instance_method :private_method1, false # => [:private_method1]
2997
+ GrepInstanceMethod.new.grep_private_instance_method /private_method1/, false # => [:private_method1, :private_method11]
2998
+ GrepInstanceMethod.new.grep_private_instance_method /private_method3/, false # => []
2999
+ GrepInstanceMethod.new.grep_private_instance_method :equal?, true # => [:equal?]
3000
+ ~~~
3001
+
3002
+ [back to list](#list)
3003
+
3004
+ ### Object#grep_protected_instance_method
3005
+ ~~~ruby
3006
+ require 'tbpgr_utils'
3007
+
3008
+ # target class
3009
+ class GrepInstanceMethod
3010
+ def public_method1;end
3011
+ def public_method2;end
3012
+ def public_method11;end
3013
+ protected
3014
+ def protected_method1;end
3015
+ def protected_method2;end
3016
+ def protected_method11;end
3017
+ private
3018
+ def private_method1;end
3019
+ def private_method2;end
3020
+ def private_method11;end
3021
+ end
3022
+
3023
+ # method call
3024
+ GrepInstanceMethod.new.grep_protected_instance_method :protected_method1, false # => [:protected_method1]
3025
+ GrepInstanceMethod.new.grep_protected_instance_method /protected_method1/, false # => [:protected_method1, :protected_method11]
3026
+ GrepInstanceMethod.new.grep_protected_instance_method /protected_method3/, false # => []
3027
+ GrepInstanceMethod.new.grep_protected_instance_method :equal?, true # => [:equal?]
3028
+ ~~~
3029
+
3030
+ [back to list](#list)
3031
+
2974
3032
  ### Object#grep_public_instance_method
2975
3033
  ~~~ruby
2976
- require 'tbpbr_utils'
3034
+ require 'tbpgr_utils'
2977
3035
 
2978
3036
  # target class
2979
- class GrepPublicInstanceMethod
3037
+ class GrepInstanceMethod
2980
3038
  def public_method1;end
2981
3039
  def public_method2;end
2982
3040
  def public_method11;end
@@ -2991,17 +3049,17 @@ class GrepPublicInstanceMethod
2991
3049
  end
2992
3050
 
2993
3051
  # method call
2994
- GrepPublicInstanceMethod.new.grep_public_instance_method :public_method1, false # => [:public_method1]
2995
- GrepPublicInstanceMethod.new.grep_public_instance_method /public_method1/, false # => [:public_method1, :public_method11]
2996
- GrepPublicInstanceMethod.new.grep_public_instance_method /public_method3/, false # => []
2997
- GrepPublicInstanceMethod.new.grep_public_instance_method :equal?, true # => [:equal?]
3052
+ GrepInstanceMethod.new.grep_public_instance_method :public_method1, false # => [:public_method1]
3053
+ GrepInstanceMethod.new.grep_public_instance_method /public_method1/, false # => [:public_method1, :public_method11]
3054
+ GrepInstanceMethod.new.grep_public_instance_method /public_method3/, false # => []
3055
+ GrepInstanceMethod.new.grep_public_instance_method :equal?, true # => [:equal?]
2998
3056
  ~~~
2999
3057
 
3000
3058
  [back to list](#list)
3001
3059
 
3002
3060
  ### Object#method_nameable?
3003
3061
  ~~~ruby
3004
- require 'tbpbr_utils'
3062
+ require 'tbpgr_utils'
3005
3063
  "string".method_nameable? # => true
3006
3064
  :symbol.method_nameable? # => true
3007
3065
  1.method_nameable? # => false
@@ -3711,6 +3769,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
3711
3769
  https://github.com/tbpgr/tbpgr_utils_snippets
3712
3770
 
3713
3771
  ## History
3772
+ * version 0.0.131 : add Object#grep_protected_instance_method, Object#grep_private_instance_method
3714
3773
  * version 0.0.130 : add Object#grep_method
3715
3774
  * version 0.0.129 : add Object#grep_public_instance_method
3716
3775
  * version 0.0.128 : add Array#exchange, change Kernel#bulk_puts_eval output format(justify)
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ # Object
4
+ class Object
5
+ # grep public instance method
6
+ #
7
+ # === Example
8
+ #
9
+ # target class
10
+ #
11
+ # class GrepInstanceMethod
12
+ # def public_method1;end
13
+ # def public_method2;end
14
+ # def public_method11;end
15
+ # protected
16
+ # def protected_method1;end
17
+ # def protected_method2;end
18
+ # def protected_method11;end
19
+ # private
20
+ # def private_method1;end
21
+ # def private_method2;end
22
+ # def private_method11;end
23
+ # end
24
+ #
25
+ # method call
26
+ #
27
+ # GrepInstanceMethod.new.grep_public_instance_method :public_method1, false # => [:public_method1]
28
+ # GrepInstanceMethod.new.grep_public_instance_method /public_method1/, false # => [:public_method1, :public_method11]
29
+ # GrepInstanceMethod.new.grep_public_instance_method /public_method3/, false # => []
30
+ # GrepInstanceMethod.new.grep_public_instance_method :equal?, true # => [:equal?]
31
+ #
32
+
33
+ %w(public protected private).each do |scope|
34
+ define_method :"grep_#{scope}_instance_method" do |search, all = true|
35
+ search = search.to_sym unless search.is_a? Regexp
36
+ each_methods = send :"#{scope}_methods", all
37
+ each_methods.grep search
38
+ end
39
+ end
40
+ end
@@ -3,7 +3,7 @@
3
3
  require 'open_classes/object/any_of'
4
4
  require 'open_classes/object/boolean'
5
5
  require 'open_classes/object/grep_method'
6
- require 'open_classes/object/grep_public_instance_method'
6
+ require 'open_classes/object/grep_instance_method'
7
7
  require 'open_classes/object/guard'
8
8
  require 'open_classes/object/method_nameable'
9
9
  require 'open_classes/object/my_methods'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.130'
5
+ VERSION = '0.0.131'
6
6
  end
@@ -0,0 +1,199 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'tbpgr_utils'
4
+
5
+ describe Object do
6
+ class GrepInstanceMethod
7
+ def public_method1; end
8
+ def public_method2; end
9
+ def public_method11; end
10
+ protected
11
+ def protected_method1; end
12
+ def protected_method2; end
13
+ def protected_method11; end
14
+ private
15
+ def private_method1; end
16
+ def private_method2; end
17
+ def private_method11; end
18
+ end
19
+
20
+ context :grep_public_instance_method do
21
+ cases = [
22
+ {
23
+ case_no: 1,
24
+ case_title: 'String case',
25
+ search: 'public_method1',
26
+ all: false,
27
+ expected: [:public_method1],
28
+ },
29
+ {
30
+ case_no: 2,
31
+ case_title: 'Symbol case',
32
+ search: :public_method1,
33
+ all: false,
34
+ expected: [:public_method1],
35
+ },
36
+ {
37
+ case_no: 3,
38
+ case_title: 'Regexp case',
39
+ search: /public_method1/,
40
+ all: false,
41
+ expected: [:public_method1, :public_method11],
42
+ },
43
+ {
44
+ case_no: 4,
45
+ case_title: 'not hit case',
46
+ search: /public_method3/,
47
+ all: false,
48
+ expected: [],
49
+ },
50
+ ]
51
+
52
+ cases.each do |c|
53
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
54
+ begin
55
+ case_before c
56
+
57
+ # -- given --
58
+ # nothing
59
+
60
+ # -- when --
61
+ actual = GrepInstanceMethod.new.grep_public_instance_method c[:search], c[:all]
62
+
63
+ # -- then --
64
+ expect(actual).to eq(c[:expected])
65
+ ensure
66
+ case_after c
67
+ end
68
+ end
69
+
70
+ def case_before(c)
71
+ # implement each case before
72
+ end
73
+
74
+ def case_after(c)
75
+ # implement each case after
76
+ end
77
+ end
78
+ end
79
+
80
+ context :grep_protected_instance_method do
81
+ cases = [
82
+ {
83
+ case_no: 1,
84
+ case_title: 'String case',
85
+ search: 'protected_method1',
86
+ all: false,
87
+ expected: [:protected_method1],
88
+ },
89
+ {
90
+ case_no: 2,
91
+ case_title: 'Symbol case',
92
+ search: :protected_method1,
93
+ all: false,
94
+ expected: [:protected_method1],
95
+ },
96
+ {
97
+ case_no: 3,
98
+ case_title: 'Regexp case',
99
+ search: /protected_method1/,
100
+ all: false,
101
+ expected: [:protected_method1, :protected_method11],
102
+ },
103
+ {
104
+ case_no: 4,
105
+ case_title: 'not hit case',
106
+ search: /public_method3/,
107
+ all: false,
108
+ expected: [],
109
+ },
110
+ ]
111
+
112
+ cases.each do |c|
113
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
114
+ begin
115
+ case_before c
116
+
117
+ # -- given --
118
+ # nothing
119
+
120
+ # -- when --
121
+ actual = GrepInstanceMethod.new.grep_protected_instance_method c[:search], c[:all]
122
+
123
+ # -- then --
124
+ expect(actual).to eq(c[:expected])
125
+ ensure
126
+ case_after c
127
+ end
128
+ end
129
+
130
+ def case_before(c)
131
+ # implement each case before
132
+ end
133
+
134
+ def case_after(c)
135
+ # implement each case after
136
+ end
137
+ end
138
+ end
139
+
140
+ context :grep_private_instance_method do
141
+ cases = [
142
+ {
143
+ case_no: 1,
144
+ case_title: 'String case',
145
+ search: 'private_method1',
146
+ all: false,
147
+ expected: [:private_method1],
148
+ },
149
+ {
150
+ case_no: 2,
151
+ case_title: 'Symbol case',
152
+ search: :private_method1,
153
+ all: false,
154
+ expected: [:private_method1],
155
+ },
156
+ {
157
+ case_no: 3,
158
+ case_title: 'Regexp case',
159
+ search: /private_method1/,
160
+ all: false,
161
+ expected: [:private_method1, :private_method11],
162
+ },
163
+ {
164
+ case_no: 4,
165
+ case_title: 'not hit case',
166
+ search: /public_method3/,
167
+ all: false,
168
+ expected: [],
169
+ },
170
+ ]
171
+
172
+ cases.each do |c|
173
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
174
+ begin
175
+ case_before c
176
+
177
+ # -- given --
178
+ # nothing
179
+
180
+ # -- when --
181
+ actual = GrepInstanceMethod.new.grep_private_instance_method c[:search], c[:all]
182
+
183
+ # -- then --
184
+ expect(actual).to eq(c[:expected])
185
+ ensure
186
+ case_after c
187
+ end
188
+ end
189
+
190
+ def case_before(c)
191
+ # implement each case before
192
+ end
193
+
194
+ def case_after(c)
195
+ # implement each case after
196
+ end
197
+ end
198
+ end
199
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tbpgr_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.130
4
+ version: 0.0.131
5
5
  platform: ruby
6
6
  authors:
7
7
  - tbpgr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-17 00:00:00.000000000 Z
11
+ date: 2014-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -203,8 +203,8 @@ files:
203
203
  - lib/open_classes/object.rb
204
204
  - lib/open_classes/object/any_of.rb
205
205
  - lib/open_classes/object/boolean.rb
206
+ - lib/open_classes/object/grep_instance_method.rb
206
207
  - lib/open_classes/object/grep_method.rb
207
- - lib/open_classes/object/grep_public_instance_method.rb
208
208
  - lib/open_classes/object/guard.rb
209
209
  - lib/open_classes/object/method_nameable.rb
210
210
  - lib/open_classes/object/my_methods.rb
@@ -342,8 +342,8 @@ files:
342
342
  - spec/open_classes/numeric/to_oct_table_spec.rb
343
343
  - spec/open_classes/object/any_of_spec.rb
344
344
  - spec/open_classes/object/boolean_spec.rb
345
+ - spec/open_classes/object/grep_instance_method_spec.rb
345
346
  - spec/open_classes/object/grep_method_spec.rb
346
- - spec/open_classes/object/grep_public_instance_method_spec.rb
347
347
  - spec/open_classes/object/guard_spec.rb
348
348
  - spec/open_classes/object/method_nameable_spec.rb
349
349
  - spec/open_classes/object/my_methods_spec.rb
@@ -502,8 +502,8 @@ test_files:
502
502
  - spec/open_classes/numeric/to_oct_table_spec.rb
503
503
  - spec/open_classes/object/any_of_spec.rb
504
504
  - spec/open_classes/object/boolean_spec.rb
505
+ - spec/open_classes/object/grep_instance_method_spec.rb
505
506
  - spec/open_classes/object/grep_method_spec.rb
506
- - spec/open_classes/object/grep_public_instance_method_spec.rb
507
507
  - spec/open_classes/object/guard_spec.rb
508
508
  - spec/open_classes/object/method_nameable_spec.rb
509
509
  - spec/open_classes/object/my_methods_spec.rb
@@ -1,36 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # Object
4
- class Object
5
- # grep public instance method
6
- #
7
- # === Example
8
- #
9
- # target class
10
- #
11
- # class GrepPublicInstanceMethod
12
- # def public_method1;end
13
- # def public_method2;end
14
- # def public_method11;end
15
- # protected
16
- # def protected_method1;end
17
- # def protected_method2;end
18
- # def protected_method11;end
19
- # private
20
- # def private_method1;end
21
- # def private_method2;end
22
- # def private_method11;end
23
- # end
24
- #
25
- # method call
26
- #
27
- # GrepPublicInstanceMethod.new.grep_public_instance_method :public_method1, false # => [:public_method1]
28
- # GrepPublicInstanceMethod.new.grep_public_instance_method /public_method1/, false # => [:public_method1, :public_method11]
29
- # GrepPublicInstanceMethod.new.grep_public_instance_method /public_method3/, false # => []
30
- # GrepPublicInstanceMethod.new.grep_public_instance_method :equal?, true # => [:equal?]
31
- #
32
- def grep_public_instance_method(search, all = true)
33
- search = search.to_sym unless search.is_a? Regexp
34
- public_methods(all).grep search
35
- end
36
- end
@@ -1,86 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require 'tbpgr_utils'
4
-
5
- describe Object do
6
- class GrepPublicInstanceMethod
7
- def public_method1; end
8
- def public_method2; end
9
- def public_method11; end
10
- protected
11
- def protected_method1; end
12
- def protected_method2; end
13
- def protected_method11; end
14
- private
15
- def private_method1; end
16
- def private_method2; end
17
- def private_method11; end
18
- end
19
-
20
- context :grep_public_instance_method do
21
- cases = [
22
- {
23
- case_no: 1,
24
- case_title: 'String case',
25
- search: 'public_method1',
26
- all: false,
27
- expected: [:public_method1],
28
- },
29
- {
30
- case_no: 2,
31
- case_title: 'Symbol case',
32
- search: :public_method1,
33
- all: false,
34
- expected: [:public_method1],
35
- },
36
- {
37
- case_no: 3,
38
- case_title: 'Regexp case',
39
- search: /public_method1/,
40
- all: false,
41
- expected: [:public_method1, :public_method11],
42
- },
43
- {
44
- case_no: 4,
45
- case_title: 'not hit case',
46
- search: /public_method3/,
47
- all: false,
48
- expected: [],
49
- },
50
- {
51
- case_no: 5,
52
- case_title: 'all case',
53
- search: :equal?,
54
- all: true,
55
- expected: [:equal?],
56
- },
57
- ]
58
-
59
- cases.each do |c|
60
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
61
- begin
62
- case_before c
63
-
64
- # -- given --
65
- # nothing
66
-
67
- # -- when --
68
- actual = GrepPublicInstanceMethod.new.grep_public_instance_method c[:search], c[:all]
69
-
70
- # -- then --
71
- expect(actual).to eq(c[:expected])
72
- ensure
73
- case_after c
74
- end
75
- end
76
-
77
- def case_before(c)
78
- # implement each case before
79
- end
80
-
81
- def case_after(c)
82
- # implement each case after
83
- end
84
- end
85
- end
86
- end