interrobang 1.1.0 → 1.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9712141ae193c892d33886ad593382b6be6074d6
4
- data.tar.gz: 0f4f1cf059e7626d5ecbfc19ec8e65e0582d1a21
3
+ metadata.gz: 0ceec7459be5080517cd7fb86a34a82d298a4566
4
+ data.tar.gz: 786219e05a0eb05f8ce748145847dfd993a25831
5
5
  SHA512:
6
- metadata.gz: 8592a7b828d2494581650bd18d475f907411c98530bbf359204c07a2f64637d4bb888dc7009bcbb716353725d437e4674fad7778b5b5e3a67f073aaec5d024ea
7
- data.tar.gz: 89518dacacc502943491ea52a5a69b812f68ac87f7a6bcedb78f943b8b17075350f305a88805dcf6f75f62cbc00671d9be929b26a051c0c2ccc9b8c17be77b92
6
+ metadata.gz: f0a2e2f65b003c5e1d5af6ac61634d284d502f44c45708f92715babd30e258f2ffea92d192d557a1340eb22e41039a54e12350799bb75fb75f12a7c4fc9b4767
7
+ data.tar.gz: 47ed4dfbe582b2151a7666430c910b1bbd7e3fb9243d47d3f8f01275175a6a9f47d04749186126fecaea8cbdde632eae65b75c44b4c1272660e9217cd67329f3
data/README.md CHANGED
@@ -69,8 +69,17 @@ Interrobang(Answer, :correct?, prefix: 'ensure_', suffix: '_on_saturday') do
69
69
  true
70
70
  end
71
71
  end # => :ensure_correct_on_saturday!
72
+ ```
72
73
 
74
+ Beware! `Interrobang` will bangify undefined methods too that classes driven by `method_missing` can be converted too.
73
75
 
76
+ ```ruby
77
+ class NaySayer
78
+ def method_missing(method, *args, &block)
79
+ false
80
+ end
81
+ end
82
+ Interrobang(NaySayer, :correct?) # => :correct!
74
83
  ```
75
84
 
76
85
  ### Filters
@@ -114,6 +123,8 @@ class Answer
114
123
  end
115
124
  ```
116
125
 
126
+ ### Details
127
+
117
128
  See `lib/interrobang.rb` for complete documentation and the tests for details.
118
129
 
119
130
  ## Installation
@@ -132,7 +143,6 @@ Or install it yourself as:
132
143
 
133
144
  $ gem install interrobang
134
145
 
135
-
136
146
  ## Example Use Case with Rails
137
147
 
138
148
  `Interrobang` works wonderfully with permission-related objects. Say we have a bangified `Protector` class that defines user permissions in our application:
@@ -1,3 +1,3 @@
1
1
  module Interrobang
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
data/lib/interrobang.rb CHANGED
@@ -43,34 +43,23 @@ module Interrobang
43
43
  # inlcude_super - The Boolean specifying whether to bangify parent methods
44
44
  #
45
45
  # Returns the Symbol Array of bangified method names.
46
- def bangify_class(klass, matching: DEFAULT_PATTERN, only: [], except: [], prefix: '', suffix: '', include_super: false)
46
+ def bangify_class(klass, matching: DEFAULT_PATTERN, only: [], except: [], prefix: '', suffix: '', include_super: false, &block)
47
47
  method_keys = klass.instance_methods(include_super)
48
48
  only = [only] unless only.is_a?(Array)
49
49
  except = [except] unless except.is_a?(Array)
50
- if only.empty?
51
- method_keys.map do |method_key|
52
- if method_key.to_s =~ matching && !except.include?(method_key)
53
- if block_given?
54
- bangify_method(klass, method_key, prefix: prefix, suffix: suffix, &Proc.new)
55
- else
56
- bangify_method(klass, method_key, prefix: prefix, suffix: suffix)
57
- end
58
- end
59
- end.compact
60
- else
61
- method_keys.map do |method_key|
62
- if only.include?(method_key)
63
- if block_given?
64
- bangify_method(klass, method_key, prefix: prefix, suffix: suffix, &Proc.new)
65
- else
66
- bangify_method(klass, method_key, prefix: prefix, suffix: suffix)
67
- end
68
- end
69
- end.compact
50
+ methods_to_bangify =
51
+ if only.empty?
52
+ (method_keys - except).select { |method_key| method_key.to_s =~ matching }
53
+ else
54
+ method_keys & only
55
+ end
56
+ methods_to_bangify.map do |method_key|
57
+ bangify_method(klass, method_key, prefix: prefix, suffix: suffix, &block)
70
58
  end
71
59
  end
72
60
 
73
- # Converts the specified predicate method to a bang method.
61
+ # Converts the specified predicate method to a bang method. Beware: bang
62
+ # methods will be created for undefined methods too.
74
63
  #
75
64
  # klass - The Class to target for bangification
76
65
  # predicate_method - The Symbol of the predicate method
@@ -17,6 +17,11 @@ def test_class
17
17
  end
18
18
 
19
19
  describe Interrobang do
20
+
21
+ #
22
+ # Bangify Class
23
+ #
24
+
20
25
  bangify_class_signatures = {
21
26
  '#Interrobang' =>
22
27
  -> (*args, &block) { Interrobang(*args, &block) },
@@ -113,6 +118,10 @@ describe Interrobang do
113
118
  end
114
119
  end
115
120
 
121
+ #
122
+ # Bangify Method
123
+ #
124
+
116
125
  bangify_method_signatures = {
117
126
  '#Interrobang' =>
118
127
  -> (*args, &block) { Interrobang(*args, &block) },
@@ -129,6 +138,7 @@ describe Interrobang do
129
138
  method_block.call(klass, :true?)
130
139
  assert klass.new.true!
131
140
  end
141
+
132
142
  it "has no method missing shenanigans" do
133
143
  klass = test_class
134
144
  method_block.call(klass, :true?)
@@ -167,6 +177,12 @@ describe Interrobang do
167
177
  assert_equal klass.new.bang!, '!'
168
178
  end
169
179
 
180
+ it "converts undefined methods" do
181
+ klass = test_class
182
+ method_block.call(klass, :is_not_defined)
183
+ assert klass.new.respond_to?(:is_not_defined!)
184
+ end
185
+
170
186
  describe "options" do
171
187
  it "adds any provided prefix or suffix to the bang method" do
172
188
  klass = test_class
@@ -207,6 +223,10 @@ describe Interrobang do
207
223
  end
208
224
  end
209
225
 
226
+ #
227
+ # Everything Else
228
+ #
229
+
210
230
  it "is extendable" do
211
231
  class Answer
212
232
  extend Interrobang
data/test/test_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
- require 'codeclimate-test-reporter'
2
- CodeClimate::TestReporter.start
1
+ if ENV['CODECLIMATE_REPO_TOKEN']
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+ end
3
5
 
4
6
  require 'minitest/autorun'
5
7
  require 'minitest/pride'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interrobang
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Faraz Yashar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-29 00:00:00.000000000 Z
11
+ date: 2015-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,7 +71,7 @@ files:
71
71
  - interrobang.gemspec
72
72
  - lib/interrobang.rb
73
73
  - lib/interrobang/version.rb
74
- - test/lib/predicate_bang_test.rb
74
+ - test/lib/interrobang_test.rb
75
75
  - test/test_helper.rb
76
76
  homepage: https://github.com/fny/interrobang
77
77
  licenses:
@@ -98,6 +98,6 @@ signing_key:
98
98
  specification_version: 4
99
99
  summary: Convert your predicate_methods? into bang_methods! without abusing method_missing
100
100
  test_files:
101
- - test/lib/predicate_bang_test.rb
101
+ - test/lib/interrobang_test.rb
102
102
  - test/test_helper.rb
103
103
  has_rdoc: