myrrha 3.0.0.rc3 → 3.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,21 +9,11 @@ module Domain
9
9
 
10
10
  def coerce(arg)
11
11
  coercions.coerce(arg, self)
12
- rescue Myrrha::Error
12
+ rescue Myrrha::Error => ex
13
13
  domain_error!(arg)
14
14
  end
15
+ alias_method :[], :coerce
15
16
 
16
- def [](first = NOT_PROVIDED, *args)
17
- if first == NOT_PROVIDED
18
- coerce([])
19
- elsif args.empty?
20
- coerce(first)
21
- else
22
- coerce(args.unshift(first))
23
- end
24
- end
25
-
26
- NOT_PROVIDED = Object.new
27
17
  end # module CoercionMethods
28
18
  include CoercionMethods
29
19
  end # module Domain
@@ -3,7 +3,7 @@ module Myrrha
3
3
 
4
4
  MAJOR = 3
5
5
  MINOR = 0
6
- TINY = "0.rc3"
6
+ TINY = '0.rc4'
7
7
 
8
8
  def self.to_s
9
9
  [ MAJOR, MINOR, TINY ].join('.')
data/myrrha.noespec CHANGED
@@ -10,7 +10,7 @@ variables:
10
10
  upper:
11
11
  Myrrha
12
12
  version:
13
- 3.0.0.rc3
13
+ 3.0.0.rc4
14
14
  summary: |-
15
15
  Myrrha provides the coercion framework which is missing to Ruby.
16
16
  description: |-
@@ -1,39 +1,46 @@
1
1
  require 'spec_helper'
2
2
  describe Domain, "coerce" do
3
3
 
4
- let(:domain){ Domain.scalar(:x, :y) }
4
+ class Point
5
+ extend Domain::Scalar.new(:x, :y)
5
6
 
6
- let(:expected){ domain.new(1, 2) }
7
-
8
- before do
9
- domain.coercions do |c|
10
- c.coercion(String){|v,_| expected }
11
- c.coercion(Array) {|v,_| expected }
7
+ coercions do |c|
8
+ c.coercion(String){|v,_| Point.new(*v.split(',').map(&:to_i)) }
9
+ c.coercion(Array) {|v,_| Point.new(*v) }
12
10
  end
11
+
12
+ EMPTY = Point.new(0, 0)
13
13
  end
14
14
 
15
+ let(:point_1_1){ Point.new(1, 1) }
16
+ let(:point_2_2){ Point.new(2, 2) }
17
+
15
18
  it 'should delegate to coercions' do
16
- domain.coerce("blah").should be(expected)
19
+ Point.coerce("1, 1").should eq(point_1_1)
17
20
  end
18
21
 
19
22
  it 'raises a TypeError if something goes wrong' do
20
23
  lambda{
21
- domain.coerce(12)
24
+ Point.coerce(12)
22
25
  }.should raise_error(TypeError, /Can't convert `12`/)
23
26
  end
24
27
 
25
28
  describe "the [] alias" do
26
29
 
27
30
  it 'delegates to coerce when one argument' do
28
- domain["12"].should be(expected)
31
+ Point["1,1"].should eq(point_1_1)
32
+ end
33
+
34
+ it 'supports Array' do
35
+ Point[[2, 2]].should eq(point_2_2)
29
36
  end
30
37
 
31
38
  it 'supports Array literals' do
32
- domain[1, 3].should eq(expected)
39
+ Point[2, 2].should eq(point_2_2)
33
40
  end
34
41
 
35
42
  it 'supports empty Array literals' do
36
- domain[].should eq(expected)
43
+ Point[].should be(Point::EMPTY)
37
44
  end
38
45
  end
39
46
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myrrha
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.rc3
4
+ version: 3.0.0.rc4
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors: