nifty-variants 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/nifty/variants/version.rb +1 -1
- data/nifty-variants.gemspec +1 -0
- data/spec/lib/nifty/order_spec.rb +5 -7
- data/spec/lib/nifty/variants_spec.rb +5 -7
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8c0f1e4f41c20c0380c0d7f3860e34ee5448aa2
|
4
|
+
data.tar.gz: 678cc9e9c638aad57a41a65762f00cdc8b0c5ed8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed773a89261f29e7a01022e1e0adc3a1f13280d06f6b090cff09872e02ebc96cbd4c172d650a1dfa88619555e3266f098a0fb645ea437cecf1ace73098dd4a8e
|
7
|
+
data.tar.gz: f921755d3db4e7147687888bca107eab034d9341585e0f4cc7bff019fecdcac813ac7f1ad54eeb338a07e045ab129ba2a7bd3be2056c20d3cde4a6c5e8280a53
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Nifty::Variants
|
2
2
|
|
3
|
+
[ ![Codeship Status for niftyn8/nifty-variants](https://codeship.com/projects/9585a190-5b48-0132-5f60-022e5ac315ca/status)](https://codeship.com/projects/50484)
|
4
|
+
|
3
5
|
If you are familiar with variants from a nice language like Haskell try this.
|
4
6
|
|
5
7
|
If you don't know what variants are [start here](http://youtu.be/ZQkIWWTygio)
|
@@ -32,7 +34,7 @@ class OrderDispatch
|
|
32
34
|
def shipit!(order)
|
33
35
|
cases order,
|
34
36
|
digital: ->(o) { o.email! },
|
35
|
-
delivery: ->(o) { o.deliver! }
|
37
|
+
delivery: ->(o) { o.deliver! },
|
36
38
|
else: ->(o) { move_to_error_queue(o) }
|
37
39
|
end
|
38
40
|
end
|
data/nifty-variants.gemspec
CHANGED
@@ -6,6 +6,7 @@ require 'nifty/variants/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "nifty-variants"
|
8
8
|
spec.version = Nifty::Variants::VERSION
|
9
|
+
spec.required_ruby_version = '~> 2.1.0'
|
9
10
|
spec.authors = ["Nate West"]
|
10
11
|
spec.email = ["natescott.west@gmail.com"]
|
11
12
|
spec.summary = %q{Variants in Ruby}
|
@@ -6,10 +6,9 @@ RSpec.describe Order do
|
|
6
6
|
for_every(:order) { generate(:order) }
|
7
7
|
|
8
8
|
it "returns a tuple-like variant" do
|
9
|
-
|
10
|
-
variant
|
11
|
-
expect(
|
12
|
-
expect(*obj).to eq o
|
9
|
+
variant, *obj = order.to_variant
|
10
|
+
expect(variant).to eq order.type
|
11
|
+
expect(*obj).to eq order
|
13
12
|
end
|
14
13
|
end
|
15
14
|
end
|
@@ -29,10 +28,9 @@ RSpec.describe OrderDispatch do
|
|
29
28
|
}
|
30
29
|
|
31
30
|
it "returns the proper place" do
|
32
|
-
|
33
|
-
expected_place = o.send(method_for[o.type])
|
31
|
+
expected_place = order.send(method_for[order.type])
|
34
32
|
|
35
|
-
expect(OrderDispatch.dispatch(
|
33
|
+
expect(OrderDispatch.dispatch(order.to_variant)).to eq expected_place
|
36
34
|
end
|
37
35
|
|
38
36
|
it "raises an exception for unknown order types" do
|
@@ -15,20 +15,18 @@ RSpec.describe Nifty::Variants do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "can take advantage of an else" do
|
18
|
-
v = variant
|
19
18
|
expect(
|
20
|
-
cases
|
21
|
-
else: ->(_) {
|
22
|
-
).to eq
|
19
|
+
cases variant,
|
20
|
+
else: ->(_) { variant.first }
|
21
|
+
).to eq variant.first
|
23
22
|
end
|
24
23
|
|
25
24
|
it "selects the correct variant match" do
|
26
|
-
v = variant
|
27
25
|
expect(
|
28
|
-
cases
|
26
|
+
cases variant,
|
29
27
|
generate(:key) => ->(*_) { false },
|
30
28
|
generate(:key) => ->(*_) { false },
|
31
|
-
|
29
|
+
variant.first => ->(*_) { true }
|
32
30
|
).to be true
|
33
31
|
end
|
34
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nifty-variants
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nate West
|
@@ -123,9 +123,9 @@ require_paths:
|
|
123
123
|
- lib
|
124
124
|
required_ruby_version: !ruby/object:Gem::Requirement
|
125
125
|
requirements:
|
126
|
-
- - "
|
126
|
+
- - "~>"
|
127
127
|
- !ruby/object:Gem::Version
|
128
|
-
version:
|
128
|
+
version: 2.1.0
|
129
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
130
|
requirements:
|
131
131
|
- - ">="
|