abstractivator 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +101 -0
- data/abstractivator.gemspec +2 -1
- data/build.yml +2 -0
- data/lib/abstractivator/lazy.rb +91 -0
- data/lib/abstractivator/proc_ext.rb +26 -0
- data/lib/abstractivator/version.rb +1 -1
- data/spec/lib/abstractivator/array_ext_spec.rb +4 -4
- data/spec/lib/abstractivator/enum_spec.rb +1 -1
- data/spec/lib/abstractivator/enumerable_ext_spec.rb +2 -2
- data/spec/lib/abstractivator/enumerator_ext_spec.rb +1 -1
- data/spec/lib/abstractivator/lazy_spec.rb +78 -0
- data/spec/lib/abstractivator/proc_ext_spec.rb +37 -0
- data/spec/lib/abstractivator/schedule/schedule_spec.rb +1 -1
- data/update_version.sh +47 -0
- metadata +33 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98bd10f35bc275138d6a9510a6a53cbd99bddab8
|
4
|
+
data.tar.gz: df501bfa7335e0a9b6743a7697690cbdcd3ae77a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb9f24962f7a84d91d309d1fbbe5e118f922a111dbc877c3f066744befdcfef05b596de9b0015657fd65462ec4b064940b51911e807e47713a50e164a9c4f335
|
7
|
+
data.tar.gz: e6f42fc405be407eeb1f72b5c360df98d2d83e5008b701396f913c4030076e421f7863ad534bf47f11463c5a937f3cd7ed6443b87d5ccc59db84573ef47413f9
|
data/CHANGES.md
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
## [0.6.0](https://github.com/indigobio/abstractivator/compare/v0.5.0...indigobio:v0.6.0) (2016-04-19)
|
2
|
+
|
3
|
+
- Added fiber_defer guards for increased flexibility in managing thread-local variables.
|
4
|
+
([1b9226d](https://github.com/indigobio/abstractivator/commit/1b9226d3d525c4293bd90804edb621f967f7d836))
|
5
|
+
|
6
|
+
|
7
|
+
## [0.5.0](https://github.com/indigobio/abstractivator/compare/v0.4.1...indigobio:v0.5.0) (2016-03-30)
|
8
|
+
|
9
|
+
- Removed dependency on the 'sourcify' gem.
|
10
|
+
([837ce21](https://github.com/indigobio/abstractivator/commit/837ce2186c157766cc6b9fefc95c03e3c0f34a5a))
|
11
|
+
|
12
|
+
|
13
|
+
## [0.4.1](https://github.com/indigobio/abstractivator/compare/v0.4.0...indigobio:v0.4.1) (2015-11-17)
|
14
|
+
|
15
|
+
- Proc.loose_call keyword support
|
16
|
+
([3f93d6a](https://github.com/indigobio/abstractivator/commit/3f93d6a75f06c282a88dfa8926b086d37d0b2294))
|
17
|
+
|
18
|
+
|
19
|
+
## [0.4.0](https://github.com/indigobio/abstractivator/compare/v0.3.1...indigobio:v0.4.0) (2015-11-05)
|
20
|
+
|
21
|
+
- Added `Enumerator::unfold` and `Enumerator#memoize`, which memoizes items in a (lazy) `Enumerable`
|
22
|
+
([bb98303](https://github.com/indigobio/abstractivator/commit/bb983037186265a7bf926ca1e347f35927b1401a))
|
23
|
+
|
24
|
+
|
25
|
+
## [0.3.1](https://github.com/indigobio/abstractivator/compare/v0.3.0...indigobio:v0.3.1) (2015-10-16)
|
26
|
+
|
27
|
+
- Fixed mongoid_fiber_defer to return the value of the block
|
28
|
+
([f5bfbdd](https://github.com/indigobio/abstractivator/commit/f5bfbdd45a4b31983a03b2f4056064307540844d))
|
29
|
+
|
30
|
+
|
31
|
+
## [0.3.0](https://github.com/indigobio/abstractivator/compare/v0.2.0...indigobio:v0.3.0) (2015-10-15)
|
32
|
+
|
33
|
+
- Added mongoid_fiber_defer
|
34
|
+
([c713ddd](https://github.com/indigobio/abstractivator/commit/c713ddd4aa60e4b56465a7d25c89918f0b612610))
|
35
|
+
|
36
|
+
|
37
|
+
## [0.2.0](https://github.com/indigobio/abstractivator/compare/v0.1.1...indigobio:v0.2.0) (2015-10-14)
|
38
|
+
|
39
|
+
- Added Abstractivator::FiberDefer. It calls [`EventMachine::defer`](http://www.rubydoc.info/github/eventmachine/eventmachine/EventMachine.defer)
|
40
|
+
under the hood and uses fibers to hide asynchrony.
|
41
|
+
([faa83ab](https://github.com/indigobio/abstractivator/commit/faa83abdfb1ecc937183bed5b698d09673ae85ca))
|
42
|
+
|
43
|
+
|
44
|
+
## [0.1.1](https://github.com/indigobio/abstractivator/compare/076419fdadf74dc398e638c8ac7e72d78279457b...indigobio:v0.1.1) (2015-10-14)
|
45
|
+
|
46
|
+
- Abstractivator::Event
|
47
|
+
([db10f6c](https://github.com/indigobio/abstractivator/commit/db10f6c3777e01719ec5189a06038f87702c36b0))
|
48
|
+
- schedule
|
49
|
+
([255bdf0](https://github.com/indigobio/abstractivator/commit/255bdf04817b5892b7cc7cd9b62547aeabee0fed))
|
50
|
+
- as_json/to_json for Enum
|
51
|
+
([3649cb4](https://github.com/indigobio/abstractivator/commit/3649cb409df4a9aa92ff0a6d7a4a940c862ebd69))
|
52
|
+
- Simplified Enum implementation
|
53
|
+
([f733588](https://github.com/indigobio/abstractivator/commit/f733588e817f88d8ba79718f65b9ce46a143d51e))
|
54
|
+
- Fixed bug in Enum.from
|
55
|
+
([76c443d](https://github.com/indigobio/abstractivator/commit/76c443d9df079942d1a953e508e8af1004c4ec87))
|
56
|
+
- Wrap enum values instead of using SimpleDelegator; adding a value to a hash caused it to lose its enumness
|
57
|
+
([61072a2](https://github.com/indigobio/abstractivator/commit/61072a277f7aba12b1d001f9c82bdf323c69b0e3))
|
58
|
+
- Improved top level enum implementation
|
59
|
+
([5494244](https://github.com/indigobio/abstractivator/commit/54942448a3a9f243d73829007595ca519a683382))
|
60
|
+
- define_enum at top-level
|
61
|
+
([0e54d29](https://github.com/indigobio/abstractivator/commit/0e54d295044c865fd1338b6c7dbed4a7f5e89fa4))
|
62
|
+
- Proc::pipe
|
63
|
+
([6dba7f0](https://github.com/indigobio/abstractivator/commit/6dba7f0349fe5202631f32d6309d4d9e289b1a3c))
|
64
|
+
- Object#callable?
|
65
|
+
([182a8d5](https://github.com/indigobio/abstractivator/commit/182a8d5d4ed5e561051a3b409bb4d90df6980954))
|
66
|
+
- When transforming hash and array members, raise a more helpful error if the value is of an unexpected type
|
67
|
+
([f6e78a9](https://github.com/indigobio/abstractivator/commit/f6e78a96f1eeaf3c7d0888f339140a9b847b298b))
|
68
|
+
- When transforming hash and array members, make the key/index available to the transformer
|
69
|
+
([74e674c](https://github.com/indigobio/abstractivator/commit/74e674c984d3f2066435b0cc05cce8a472b86448))
|
70
|
+
- tree_map can now delete values
|
71
|
+
([dc48e1b](https://github.com/indigobio/abstractivator/commit/dc48e1bd0ce2dd5a24e32cfaf58a195da2d7547d))
|
72
|
+
- bugfix: don't add missing keys
|
73
|
+
([f3a4330](https://github.com/indigobio/abstractivator/commit/f3a4330e52db38c3a449abefeb5d51b47cb67532))
|
74
|
+
- Improved Enumerable#hash_map and Proc::loose_call
|
75
|
+
([151d096](https://github.com/indigobio/abstractivator/commit/151d0960de43d00914d2a3fb0e03301d8c44be9a))
|
76
|
+
- Added Enum.from
|
77
|
+
([74582e7](https://github.com/indigobio/abstractivator/commit/74582e7f4fb0328fdc4c06a53427061d39d35773))
|
78
|
+
- Enum values know which enum they belong to
|
79
|
+
([5a6772f](https://github.com/indigobio/abstractivator/commit/5a6772f76cd0153a9226987b797b5b1a49134d54))
|
80
|
+
- Added array_ext
|
81
|
+
([adcdbc7](https://github.com/indigobio/abstractivator/commit/adcdbc72ef5b8dda2f0a803cecfe0ce2dc3bdeff))
|
82
|
+
- Proc::compose to_proc's its arguments
|
83
|
+
([94682dd](https://github.com/indigobio/abstractivator/commit/94682dd5883819a47159d52f384aedd5846ad728))
|
84
|
+
- enum
|
85
|
+
([4eb05b5](https://github.com/indigobio/abstractivator/commit/4eb05b5197ddea782e95558d591b48ba1c626be3))
|
86
|
+
- proc_ext and enumerable_ext
|
87
|
+
([c2fac9e](https://github.com/indigobio/abstractivator/commit/c2fac9eb1cfc5021f5f466b767cfdd5583ac3650))
|
88
|
+
- stable_sort
|
89
|
+
([90a24ce](https://github.com/indigobio/abstractivator/commit/90a24ce00007f2e9626ab494dc3c4bfcbbaa720a))
|
90
|
+
- refactor tweak
|
91
|
+
([b1ff161](https://github.com/indigobio/abstractivator/commit/b1ff161af192d4f64352b15dde84eb815248beae))
|
92
|
+
- Don't mutate the tree_compare mask when removing :* from set masks
|
93
|
+
([b1484e0](https://github.com/indigobio/abstractivator/commit/b1484e058e77d79c61b519a861dfaf9651044f4a))
|
94
|
+
- Expanded 'set' use cases for tree_compare
|
95
|
+
([dcc70d0](https://github.com/indigobio/abstractivator/commit/dcc70d05ffd3afc88da0ffb9d426afe6e7c01df9))
|
96
|
+
- Added a set comparator, SetMask
|
97
|
+
([af394e0](https://github.com/indigobio/abstractivator/commit/af394e0ddff9a9e3431d5c7b852e249d2e57e06b))
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
data/abstractivator.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency 'rake'
|
23
23
|
spec.add_development_dependency 'eventmachine'
|
24
24
|
spec.add_development_dependency 'mongoid'
|
25
|
+
spec.add_development_dependency 'rspec_junit_formatter'
|
25
26
|
|
26
|
-
spec.add_runtime_dependency 'activesupport', '
|
27
|
+
spec.add_runtime_dependency 'activesupport', '> 4', '< 6'
|
27
28
|
end
|
data/build.yml
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'abstractivator/proc_ext'
|
2
|
+
|
3
|
+
module Abstractivator
|
4
|
+
# A transparent wrapper for delaying evaluation.
|
5
|
+
# Usage: v = lazy { 1 + 2 }
|
6
|
+
# This delays the addition until the value is actually needed,
|
7
|
+
# i.e., a method is called on it.
|
8
|
+
# The wrapper is "transparent" in that it acts as much as possible
|
9
|
+
# like the wrapped object itself. For example:
|
10
|
+
# lazy { 42 }.class ==> Fixnum
|
11
|
+
# Don't use this for mission critical code.
|
12
|
+
# Don't pass lazy objects across API boundaries.
|
13
|
+
class Lazy < BasicObject
|
14
|
+
def initialize(&make)
|
15
|
+
@make = make
|
16
|
+
end
|
17
|
+
|
18
|
+
def __lazy_ensure_obj
|
19
|
+
if @make
|
20
|
+
@obj = @make.call
|
21
|
+
@make = nil
|
22
|
+
end
|
23
|
+
@obj
|
24
|
+
end
|
25
|
+
private :__lazy_ensure_obj
|
26
|
+
|
27
|
+
def method_missing(method, *args, **kws, &block)
|
28
|
+
__lazy_ensure_obj.proxy_send(method, *args, **kws, &block)
|
29
|
+
end
|
30
|
+
|
31
|
+
def ==(other)
|
32
|
+
__lazy_ensure_obj == other
|
33
|
+
end
|
34
|
+
|
35
|
+
def !=(other)
|
36
|
+
__lazy_ensure_obj != other
|
37
|
+
end
|
38
|
+
|
39
|
+
def !
|
40
|
+
!__lazy_ensure_obj
|
41
|
+
end
|
42
|
+
|
43
|
+
# Force ruby to delegate to wrapped object.
|
44
|
+
# Ruby's C implementation makes assumptions about object type.
|
45
|
+
# This is required for implicit array coercion:
|
46
|
+
# a = [1, 2]
|
47
|
+
# x, y = a
|
48
|
+
def to_ary
|
49
|
+
__lazy_ensure_obj
|
50
|
+
if @obj.respond_to?(:to_ary)
|
51
|
+
@obj.to_ary
|
52
|
+
else
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Force ruby to delegate to wrapped object.
|
58
|
+
# Ruby's C implementation makes assumptions about object type.
|
59
|
+
# This is required for explicit array coercion:
|
60
|
+
# x = 1
|
61
|
+
# a = *x
|
62
|
+
# (a == [1])
|
63
|
+
def to_a
|
64
|
+
__lazy_ensure_obj
|
65
|
+
if @obj.respond_to?(:to_a)
|
66
|
+
@obj.to_a
|
67
|
+
else
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def inspect
|
73
|
+
"#<Abstractivator::Lazy:#{@make ? '' : @obj.class.name + ':'}0x#{__id__.to_s(16).rjust(8, '0')}>"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
module Kernel
|
79
|
+
def lazy(&block)
|
80
|
+
Abstractivator::Lazy.new(&block)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class Module
|
85
|
+
# To enable case/when support, reimplement Module#===
|
86
|
+
# so it goes through our method_missing mechanism.
|
87
|
+
# See https://github.com/ruby/ruby/blob/v2_3_0/object.c#L1534
|
88
|
+
def ===(obj)
|
89
|
+
obj.is_a?(self)
|
90
|
+
end
|
91
|
+
end
|
@@ -8,6 +8,12 @@ module MethodAndProcExtensions
|
|
8
8
|
Proc.loose_call(self, args, kws, &block)
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
12
|
+
KEYWORD_PARAMETER_TYPES = %i(key keyreq keyrest).freeze
|
13
|
+
|
14
|
+
def accepts_keywords
|
15
|
+
@accepts_keywords ||= parameters.any?{|param| KEYWORD_PARAMETER_TYPES.include?(param.first)}
|
16
|
+
end
|
11
17
|
end
|
12
18
|
|
13
19
|
class Proc
|
@@ -52,6 +58,16 @@ class Proc
|
|
52
58
|
end
|
53
59
|
end
|
54
60
|
|
61
|
+
def proxy_call(*args, **kws, &block)
|
62
|
+
if accepts_keywords
|
63
|
+
call(*args, **kws, &block)
|
64
|
+
elsif kws.any?
|
65
|
+
call(*(args + [kws]), &block)
|
66
|
+
else
|
67
|
+
call(*args, &block)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
55
71
|
# tries to coerce x into a procedure, then calls it with
|
56
72
|
# the given argument list.
|
57
73
|
# If x cannot be coerced into a procedure, returns x.
|
@@ -113,4 +129,14 @@ class Object
|
|
113
129
|
def callable?
|
114
130
|
respond_to?(:call)
|
115
131
|
end
|
132
|
+
|
133
|
+
def proxy_send(method_name, *args, **kws, &block)
|
134
|
+
if method(method_name).accepts_keywords
|
135
|
+
send(method_name, *args, **kws, &block)
|
136
|
+
elsif kws.any?
|
137
|
+
send(method_name, *(args + [kws]), &block)
|
138
|
+
else
|
139
|
+
send(method_name, *args, &block)
|
140
|
+
end
|
141
|
+
end
|
116
142
|
end
|
@@ -7,8 +7,8 @@ describe Array do
|
|
7
7
|
expect([:k, :v].key).to eql :k
|
8
8
|
end
|
9
9
|
it 'raises an error if the array is not of size 2' do
|
10
|
-
expect{[:k].key}.to raise_error
|
11
|
-
expect{[:k, :v, :z].key}.to raise_error
|
10
|
+
expect{[:k].key}.to raise_error RuntimeError
|
11
|
+
expect{[:k, :v, :z].key}.to raise_error RuntimeError
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -17,8 +17,8 @@ describe Array do
|
|
17
17
|
expect([:k, :v].value).to eql :v
|
18
18
|
end
|
19
19
|
it 'raises an error if the array is not of size 2' do
|
20
|
-
expect{[:k].value}.to raise_error
|
21
|
-
expect{[:k, :v, :z].value}.to raise_error
|
20
|
+
expect{[:k].value}.to raise_error RuntimeError
|
21
|
+
expect{[:k, :v, :z].value}.to raise_error RuntimeError
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -33,7 +33,7 @@ describe Enum do
|
|
33
33
|
expect(Container::Traditional.from_symbol(:bar)).to eql 'bar'
|
34
34
|
end
|
35
35
|
it 'raises an error if no such value exists in the enumeration' do
|
36
|
-
expect{Container::Traditional.from_symbol(:baz)}.to raise_error
|
36
|
+
expect{Container::Traditional.from_symbol(:baz)}.to raise_error RuntimeError
|
37
37
|
end
|
38
38
|
end
|
39
39
|
describe '::from' do
|
@@ -68,12 +68,12 @@ describe Enumerable do
|
|
68
68
|
|
69
69
|
it 'throws an exception when left values have overlapping keys' do
|
70
70
|
x.push({ a: 8, b: 5, c: 'oops' })
|
71
|
-
expect { Enumerable.outer_join(x, y, get_key, get_key, -1, -100) }.to raise_error
|
71
|
+
expect { Enumerable.outer_join(x, y, get_key, get_key, -1, -100) }.to raise_error RuntimeError
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'throws an exception when right values have overlapping keys' do
|
75
75
|
y.push({ a: 5, b: 6, c: 'oops' })
|
76
|
-
expect { Enumerable.outer_join(x, y, get_key, get_key, -1, -100) }.to raise_error
|
76
|
+
expect { Enumerable.outer_join(x, y, get_key, get_key, -1, -100) }.to raise_error RuntimeError
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -16,7 +16,7 @@ describe 'Enumerator' do
|
|
16
16
|
expect(Enumerator.unfold(nil){}.to_a).to eql []
|
17
17
|
end
|
18
18
|
it 'raises an error if no block is provided' do
|
19
|
-
expect{Enumerator.unfold(nil)}.to raise_error
|
19
|
+
expect{Enumerator.unfold(nil)}.to raise_error RuntimeError
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'abstractivator/lazy'
|
3
|
+
|
4
|
+
describe Abstractivator::Lazy do
|
5
|
+
|
6
|
+
it 'delays a value' do
|
7
|
+
log = []
|
8
|
+
value = lazy { log << 'did work'; 42}
|
9
|
+
expect(log).to eql []
|
10
|
+
expect(value).to eql 42
|
11
|
+
expect(log).to eql ['did work']
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'the value is mutable' do
|
15
|
+
value = lazy { [1] }
|
16
|
+
expect(value).to eql [1]
|
17
|
+
value << 2
|
18
|
+
expect(value).to eql [1, 2]
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'stringifies like a normal object' do
|
22
|
+
value = lazy { 42 }
|
23
|
+
expect(value.to_s).to eql '42'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'equality works like normal' do
|
27
|
+
expect(lazy { 42 } == 42).to be true
|
28
|
+
expect(lazy { 42 } == 99).to be false
|
29
|
+
expect(lazy { 42 } != 42).to be false
|
30
|
+
expect(lazy { 42 } != 99).to be true
|
31
|
+
expect(lazy { 42 } === 42).to be true
|
32
|
+
expect(Fixnum === lazy { 42 }).to be true
|
33
|
+
expect(Array === lazy { 42 }).to be false
|
34
|
+
expect(!(lazy { true })).to be false
|
35
|
+
expect(!(lazy { false })).to be true
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'methods work' do
|
39
|
+
value = lazy { 1..5 }
|
40
|
+
expect(value.size).to eql 5
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#inspect' do
|
44
|
+
it 'does not force the value' do
|
45
|
+
log = []
|
46
|
+
value = lazy { log << 'did work'; 42}
|
47
|
+
value.inspect
|
48
|
+
expect(log).to eql []
|
49
|
+
end
|
50
|
+
it 'reveals the wrapper' do
|
51
|
+
value = lazy { 42 }
|
52
|
+
expect(value.inspect).to match /#<Abstractivator::Lazy:0x[0-9a-f]+>/
|
53
|
+
end
|
54
|
+
it 'reveals the value type if the value has already been forced' do
|
55
|
+
value = lazy { 42 }
|
56
|
+
value.to_s
|
57
|
+
expect(value.inspect).to match /#<Abstractivator::Lazy:Fixnum:0x[0-9a-f]+>/
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when the block raises an error' do
|
62
|
+
let!(:value) { lazy { raise 'oops' } }
|
63
|
+
it 'accessors raise the error' do
|
64
|
+
expect { value.to_s }.to raise_error 'oops'
|
65
|
+
end
|
66
|
+
it 'subsequent accesses also raise the error' do
|
67
|
+
expect { value.to_s }.to raise_error 'oops'
|
68
|
+
expect { value.to_s }.to raise_error 'oops'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'reflects through the wrapper' do
|
73
|
+
value = lazy { [] }
|
74
|
+
expect(value.class).to eql Array
|
75
|
+
expect(value.is_a?(Array)).to be true
|
76
|
+
expect(value.methods).to include :reverse
|
77
|
+
end
|
78
|
+
end
|
@@ -150,6 +150,28 @@ context 'in the world of functional programming' do
|
|
150
150
|
p.loosen_args.call(*args, **kws, &block)
|
151
151
|
end
|
152
152
|
end
|
153
|
+
|
154
|
+
describe 'Proc#accepts_keywords' do
|
155
|
+
it 'indicates if the proc accepts keywords' do
|
156
|
+
expect(proc{}.accepts_keywords).to be false
|
157
|
+
expect(proc{|**kws|}.accepts_keywords).to be true
|
158
|
+
expect(proc{|a: 1|}.accepts_keywords).to be true
|
159
|
+
expect(proc{|a:|}.accepts_keywords).to be true
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe 'Proc#proxy_call' do
|
164
|
+
it 'calls the proc with the given args, block, and keywords (if accepted)' do
|
165
|
+
with_kws = proc { |x, y, a:, b:, &block| [x, y, a, b, block] }
|
166
|
+
without_kws = proc { |x, y, z, &block| [x, y, z, block] }
|
167
|
+
args = [1, 2]
|
168
|
+
kws = {a: 3, b: 4}
|
169
|
+
block = proc{}
|
170
|
+
expect(with_kws.proxy_call(*args, **kws, &block)).to eql [1, 2, 3, 4, block]
|
171
|
+
expect(without_kws.proxy_call(*args, &block)).to eql [1, 2, nil, block]
|
172
|
+
expect(without_kws.proxy_call(1, a: 2, &block)).to eql [1, {a: 2}, nil, block]
|
173
|
+
end
|
174
|
+
end
|
153
175
|
end
|
154
176
|
|
155
177
|
describe 'UnboundMethod#explicit_receiver' do
|
@@ -179,3 +201,18 @@ describe 'Object#callable?' do
|
|
179
201
|
expect(double(call: 1)).to be_truthy
|
180
202
|
end
|
181
203
|
end
|
204
|
+
|
205
|
+
describe 'Object#proxy_send' do
|
206
|
+
class Spy
|
207
|
+
def with_kws(x, y, a:, b:, &block); [x, y, a, b, block]; end
|
208
|
+
def without_kws(x, y, &block); [x, y, block]; end
|
209
|
+
end
|
210
|
+
it 'calls the method with the given args, block, and keywords (if accepted)' do
|
211
|
+
args = [1, 2]
|
212
|
+
kws = {a: 3, b: 4}
|
213
|
+
block = proc{}
|
214
|
+
expect(Spy.new.proxy_send(:with_kws, *args, **kws, &block)).to eql [1, 2, 3, 4, block]
|
215
|
+
expect(Spy.new.proxy_send(:without_kws, *args, &block)).to eql [1, 2, block]
|
216
|
+
expect(Spy.new.proxy_send(:without_kws, 1, a: 2, &block)).to eql [1, {a: 2}, block]
|
217
|
+
end
|
218
|
+
end
|
@@ -48,7 +48,7 @@ describe Schedule do
|
|
48
48
|
end
|
49
49
|
bad = %w(- : . 4 M) + [' ']
|
50
50
|
bad.each do |delimiter|
|
51
|
-
expect { Schedule.new("1:00-2:00#{delimiter}MWF") }.to raise_error
|
51
|
+
expect { Schedule.new("1:00-2:00#{delimiter}MWF") }.to raise_error RuntimeError
|
52
52
|
end
|
53
53
|
end
|
54
54
|
it 'raises an exception when a bad day-of-week specifier is provided' do
|
data/update_version.sh
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/bin/bash -e
|
2
|
+
|
3
|
+
#This script is used during the release process. It is not intended to be ran manually.
|
4
|
+
|
5
|
+
VERSION="$1"
|
6
|
+
VERSION="${VERSION:?"must provide version as first parameter"}"
|
7
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")"; pwd)"
|
8
|
+
|
9
|
+
updateVersion(){
|
10
|
+
updateGemspec
|
11
|
+
commitStagedFiles "Update version to ${VERSION}"
|
12
|
+
}
|
13
|
+
|
14
|
+
updateGemspec(){
|
15
|
+
echo -e "\nUpdating version file"
|
16
|
+
local versionPath="${SCRIPT_DIR}/lib/abstractivator/version.rb"
|
17
|
+
sed -i 's:\(\s*VERSION\s*=\).*:\1 '"'${VERSION}'"':' "${versionPath}"
|
18
|
+
stageFiles "${versionPath}"
|
19
|
+
}
|
20
|
+
|
21
|
+
updateLockfile(){
|
22
|
+
echo -e "\nUpdating lockfile"
|
23
|
+
bundle package --no-install > /dev/null
|
24
|
+
rm -rf .bundle/ vendor/
|
25
|
+
stageFiles "${SCRIPT_DIR}/Gemfile.lock"
|
26
|
+
}
|
27
|
+
|
28
|
+
stageFiles(){
|
29
|
+
local files=( "$@" )
|
30
|
+
git add "${files[@]}"
|
31
|
+
}
|
32
|
+
|
33
|
+
commitStagedFiles(){
|
34
|
+
local msg="$1"
|
35
|
+
if thereAreStagedFiles; then
|
36
|
+
git commit -m "${msg}"
|
37
|
+
else
|
38
|
+
echo "No changes to commit"
|
39
|
+
fi
|
40
|
+
}
|
41
|
+
|
42
|
+
thereAreStagedFiles(){
|
43
|
+
git update-index -q --ignore-submodules --refresh
|
44
|
+
! git diff-index --cached --quiet HEAD --ignore-submodules --
|
45
|
+
}
|
46
|
+
|
47
|
+
updateVersion
|
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.
|
4
|
+
version: 0.7.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: 2016-
|
11
|
+
date: 2016-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,20 +66,40 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec_junit_formatter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: activesupport
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- - "
|
87
|
+
- - ">"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4'
|
90
|
+
- - "<"
|
74
91
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
92
|
+
version: '6'
|
76
93
|
type: :runtime
|
77
94
|
prerelease: false
|
78
95
|
version_requirements: !ruby/object:Gem::Requirement
|
79
96
|
requirements:
|
80
|
-
- - "
|
97
|
+
- - ">"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '4'
|
100
|
+
- - "<"
|
81
101
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
102
|
+
version: '6'
|
83
103
|
description: Utilities
|
84
104
|
email:
|
85
105
|
- pwinton@indigobio.com
|
@@ -89,11 +109,13 @@ extra_rdoc_files: []
|
|
89
109
|
files:
|
90
110
|
- ".gitignore"
|
91
111
|
- ".rspec"
|
112
|
+
- CHANGES.md
|
92
113
|
- Gemfile
|
93
114
|
- LICENSE.txt
|
94
115
|
- README.md
|
95
116
|
- Rakefile
|
96
117
|
- abstractivator.gemspec
|
118
|
+
- build.yml
|
97
119
|
- lib/abstractivator.rb
|
98
120
|
- lib/abstractivator/array_ext.rb
|
99
121
|
- lib/abstractivator/collections.rb
|
@@ -103,6 +125,7 @@ files:
|
|
103
125
|
- lib/abstractivator/enumerator_ext.rb
|
104
126
|
- lib/abstractivator/event.rb
|
105
127
|
- lib/abstractivator/fiber_defer.rb
|
128
|
+
- lib/abstractivator/lazy.rb
|
106
129
|
- lib/abstractivator/numbers.rb
|
107
130
|
- lib/abstractivator/proc_ext.rb
|
108
131
|
- lib/abstractivator/schedule.rb
|
@@ -123,6 +146,7 @@ files:
|
|
123
146
|
- spec/lib/abstractivator/enumerator_ext_spec.rb
|
124
147
|
- spec/lib/abstractivator/event_spec.rb
|
125
148
|
- spec/lib/abstractivator/fiber_defer_spec.rb
|
149
|
+
- spec/lib/abstractivator/lazy_spec.rb
|
126
150
|
- spec/lib/abstractivator/numbers_spec.rb
|
127
151
|
- spec/lib/abstractivator/proc_ext_spec.rb
|
128
152
|
- spec/lib/abstractivator/schedule/em_util.rb
|
@@ -132,6 +156,7 @@ files:
|
|
132
156
|
- spec/lib/abstractivator/trees/tree_compare_spec.rb
|
133
157
|
- spec/lib/abstractivator/trees/tree_map_spec.rb
|
134
158
|
- spec/lib/enumerable_ext_spec.rb
|
159
|
+
- update_version.sh
|
135
160
|
homepage: ''
|
136
161
|
licenses:
|
137
162
|
- MIT
|
@@ -152,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
177
|
version: '0'
|
153
178
|
requirements: []
|
154
179
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
180
|
+
rubygems_version: 2.6.2
|
156
181
|
signing_key:
|
157
182
|
specification_version: 4
|
158
183
|
summary: Utilities
|
@@ -165,6 +190,7 @@ test_files:
|
|
165
190
|
- spec/lib/abstractivator/enumerator_ext_spec.rb
|
166
191
|
- spec/lib/abstractivator/event_spec.rb
|
167
192
|
- spec/lib/abstractivator/fiber_defer_spec.rb
|
193
|
+
- spec/lib/abstractivator/lazy_spec.rb
|
168
194
|
- spec/lib/abstractivator/numbers_spec.rb
|
169
195
|
- spec/lib/abstractivator/proc_ext_spec.rb
|
170
196
|
- spec/lib/abstractivator/schedule/em_util.rb
|