abstractivator 0.16.0 → 0.17.0

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: 26f878ae4109bef8680cc85a6b0d903b97778871
4
- data.tar.gz: ce8833f063703cdba55a4c7367cc66143f19c622
3
+ metadata.gz: 8929bafe047d7ee344331b015c9408ba151b27b5
4
+ data.tar.gz: cbaa2ac79d3581202fc89adeecdfd5a488df91b7
5
5
  SHA512:
6
- metadata.gz: d45dc88be70f404b5449d61cc8684bf2b45c2deb2a07503d5586d75a1ab3295b15fde8fc5c2e180a266f1e7602832c82b2e409d94b8270b5b1d1b32445eafc30
7
- data.tar.gz: 96b27bef0776b6c25c5ea7bc0c1aff4f0801439e53f866938e6c4e02db8e14efda2f7bc2203352066b75b2c9a17a493d8e6cdd227c7909df702245beb8b30a1b
6
+ metadata.gz: 8e938f5a2e3cbb2ae6e672accdde64dd4fd3b35f87923babbc49163dc4c1dc54b569ef696eea944d08db74643aedff81d6811583f8cf282715228a6e30ab2ca0
7
+ data.tar.gz: ccde9bcc6996de8d961056a6db883c4801e875a2e3ea069b379636f92c299055d2f95d0daced4d6f4214f54c7a587e2d788249f69dd560d05b58ebaaf815a0bd
@@ -1,4 +1,5 @@
1
1
  class Enumerator
2
+ # Enumerate values produced from an initial state. The enumerator terminates when the next state is nil.
2
3
  # @param state [Object] The initial state
3
4
  # @yieldparam state [Object] the current state
4
5
  # @yieldreturn [Array] a 2-element array containing the next value and the next state
@@ -161,6 +161,14 @@ class Array
161
161
  end
162
162
  end
163
163
 
164
+ class Symbol
165
+ def to_safe_proc
166
+ proc do |x|
167
+ x&.send(self)
168
+ end
169
+ end
170
+ end
171
+
164
172
  class Object
165
173
  def callable?
166
174
  respond_to?(:call)
@@ -1,3 +1,3 @@
1
1
  module Abstractivator
2
- VERSION = '0.16.0'
2
+ VERSION = '0.17.0'
3
3
  end
@@ -245,6 +245,20 @@ describe 'Array#to_proc' do
245
245
  end
246
246
  end
247
247
 
248
+ describe 'Symbol#to_safe_proc' do
249
+ it 'returns a "safe operator" proc' do
250
+ upcase = :upcase.to_safe_proc
251
+ expect(upcase.call('a')).to eql 'A'
252
+ expect(upcase.call(nil)).to eql nil
253
+ end
254
+ it 'handles booleans properly' do
255
+ to_s = :to_s.to_safe_proc
256
+ expect(to_s.call(nil)).to eql nil
257
+ expect(to_s.call(false)).to eql 'false'
258
+ expect(to_s.call(true)).to eql 'true'
259
+ end
260
+ end
261
+
248
262
  describe 'Object#callable?' do
249
263
  it 'determines whether or not the object has a public :call method' do
250
264
  expect(1.callable?).to be_falsey
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abstractivator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Winton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-04 00:00:00.000000000 Z
11
+ date: 2017-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler