myrrha 1.2.2 → 2.0.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.
- data/CHANGELOG.md +62 -29
- data/README.md +117 -121
- data/Rakefile +0 -12
- data/examples/sbyc_domain.rb +1 -1
- data/lib/myrrha.rb +11 -364
- data/lib/myrrha/coerce.rb +22 -25
- data/lib/myrrha/coercions.rb +265 -0
- data/lib/myrrha/domain.rb +18 -0
- data/lib/myrrha/domain/coercion_methods.rb +17 -0
- data/lib/myrrha/domain/impl.rb +50 -0
- data/lib/myrrha/domain/sbyc.rb +78 -0
- data/lib/myrrha/domain/value_methods.rb +60 -0
- data/lib/myrrha/errors.rb +12 -0
- data/lib/myrrha/loader.rb +0 -1
- data/lib/myrrha/to_ruby_literal.rb +1 -1
- data/lib/myrrha/version.rb +3 -3
- data/myrrha.noespec +3 -3
- data/spec/coercions/test_append.rb +3 -3
- data/spec/coercions/test_belongs_to.rb +12 -6
- data/spec/coercions/test_convert.rb +5 -5
- data/spec/coercions/test_delegate.rb +35 -0
- data/spec/coercions/test_subdomain.rb +9 -3
- data/spec/domain/impl/test_behavior.rb +41 -0
- data/spec/domain/impl/test_value_methods.rb +101 -0
- data/spec/domain/sbyc/test_behavior.rb +46 -0
- data/spec/domain/test_sbyc.rb +81 -0
- data/spec/myrrha/test_coercions.rb +1 -1
- data/spec/test_myrrha.rb +0 -3
- data/tasks/examples.rake +2 -1
- data/tasks/gem.rake +9 -4
- metadata +83 -43
- data/spec/myrrha/test_domain.rb +0 -116
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
describe "Myrrha.coercions" do
|
3
3
|
|
4
4
|
it "should support using user-defined domains" do
|
5
|
-
name = Myrrha.
|
5
|
+
name = Myrrha::Domain.sbyc{|s| s.is_a?(Symbol)}
|
6
6
|
rules = Myrrha.coercions do |r|
|
7
7
|
r.coercion String, name, lambda{|s,t| s.to_sym}
|
8
8
|
r.coercion name, String, lambda{|s,t| s.to_s}
|
data/spec/test_myrrha.rb
CHANGED
@@ -19,9 +19,6 @@ describe Myrrha do
|
|
19
19
|
lambda{
|
20
20
|
rules.coerce(true, Integer)
|
21
21
|
}.should raise_error(Myrrha::Error, "Unable to coerce `true` to Integer")
|
22
|
-
lambda{
|
23
|
-
rules.coerce("12.2", Integer)
|
24
|
-
}.should raise_error(Myrrha::Error, /^Unable to coerce `12.2` to Integer \(invalid value /)
|
25
22
|
end
|
26
23
|
|
27
24
|
it "should support upon rules" do
|
data/tasks/examples.rake
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
task :examples do
|
1
|
+
task :examples => :spec_test do
|
2
2
|
lib = File.expand_path('../../lib', __FILE__)
|
3
3
|
dir = File.expand_path('../../examples', __FILE__)
|
4
4
|
Dir["#{dir}/*.rb"].each do |file|
|
@@ -10,6 +10,7 @@ task :examples do
|
|
10
10
|
raise "Example #{file} failed."
|
11
11
|
end
|
12
12
|
end
|
13
|
+
puts
|
13
14
|
end
|
14
15
|
task :spec => :examples
|
15
16
|
task :test => :examples
|
data/tasks/gem.rake
CHANGED
@@ -25,13 +25,18 @@
|
|
25
25
|
#
|
26
26
|
begin
|
27
27
|
require 'rubygems/package_task'
|
28
|
-
|
28
|
+
|
29
|
+
# Dynamically load the gem spec
|
30
|
+
gemspec_file = File.expand_path('../../myrrha.gemspec', __FILE__)
|
31
|
+
gemspec = Kernel.eval(File.read(gemspec_file))
|
32
|
+
|
33
|
+
Gem::PackageTask.new(gemspec) do |t|
|
29
34
|
|
30
35
|
# Name of the package
|
31
|
-
t.name =
|
36
|
+
t.name = gemspec.name
|
32
37
|
|
33
38
|
# Version of the package
|
34
|
-
t.version =
|
39
|
+
t.version = gemspec.version
|
35
40
|
|
36
41
|
# Directory used to store the package files
|
37
42
|
t.package_dir = "pkg"
|
@@ -49,7 +54,7 @@ begin
|
|
49
54
|
t.need_zip = false
|
50
55
|
|
51
56
|
# List of files to be included in the package.
|
52
|
-
t.package_files =
|
57
|
+
t.package_files = gemspec.files
|
53
58
|
|
54
59
|
# Tar command for gzipped or bzip2ed archives.
|
55
60
|
t.tar_command = "tar"
|
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:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 0.9.2
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.9.2
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rspec
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: 2.8.0
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.8.0
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: yard
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: 0.7.4
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.7.4
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: bluecloth
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ~>
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: 2.2.0
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.2.0
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: wlang
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ~>
|
@@ -65,7 +85,12 @@ dependencies:
|
|
65
85
|
version: 0.10.2
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.10.2
|
69
94
|
description: ! "Myrrha provides the coercion framework which is missing to Ruby. Coercions\nare
|
70
95
|
simply defined as a set of rules for converting values from source to target\ndomains
|
71
96
|
(in an abstract sense). As a typical and useful example, it comes with \na coerce()
|
@@ -80,48 +105,59 @@ extra_rdoc_files:
|
|
80
105
|
- CHANGELOG.md
|
81
106
|
- LICENCE.md
|
82
107
|
files:
|
83
|
-
- examples/to_ruby_literal_foo.rb
|
84
|
-
- examples/coerce_foo.rb
|
85
|
-
- examples/coerce_noext.rb
|
86
108
|
- examples/coerce.rb
|
87
|
-
- examples/
|
109
|
+
- examples/coerce_foo.rb
|
110
|
+
- examples/coerce_foo2.rb
|
111
|
+
- examples/coerce_foo3.rb
|
88
112
|
- examples/coerce_intro.rb
|
89
|
-
- examples/
|
90
|
-
- examples/to_ruby_literal.rb
|
91
|
-
- examples/String#toXXX.rb
|
113
|
+
- examples/coerce_noext.rb
|
92
114
|
- examples/examples_helper.rb
|
93
|
-
- examples/
|
115
|
+
- examples/friendly_but_safe_api.rb
|
94
116
|
- examples/sbyc_domain.rb
|
117
|
+
- examples/String#toXXX.rb
|
118
|
+
- examples/to_ruby_literal.rb
|
119
|
+
- examples/to_ruby_literal_foo.rb
|
120
|
+
- examples/to_ruby_literal_foo2.rb
|
95
121
|
- examples/to_ruby_literal_foo3.rb
|
96
122
|
- examples/to_ruby_literal_noext.rb
|
97
|
-
- examples/coerce_foo3.rb
|
98
123
|
- lib/myrrha/coerce.rb
|
99
|
-
- lib/myrrha/
|
124
|
+
- lib/myrrha/coercions.rb
|
125
|
+
- lib/myrrha/domain/coercion_methods.rb
|
126
|
+
- lib/myrrha/domain/impl.rb
|
127
|
+
- lib/myrrha/domain/sbyc.rb
|
128
|
+
- lib/myrrha/domain/value_methods.rb
|
129
|
+
- lib/myrrha/domain.rb
|
130
|
+
- lib/myrrha/errors.rb
|
100
131
|
- lib/myrrha/loader.rb
|
101
|
-
- lib/myrrha/
|
132
|
+
- lib/myrrha/to_ruby_literal.rb
|
102
133
|
- lib/myrrha/version.rb
|
134
|
+
- lib/myrrha/with_core_ext.rb
|
103
135
|
- lib/myrrha.rb
|
104
|
-
- spec/spec_helper.rb
|
105
|
-
- spec/myrrha/test_coercions.rb
|
106
|
-
- spec/myrrha/test_domain.rb
|
107
|
-
- spec/test_myrrha.rb
|
108
|
-
- spec/test_to_ruby_literal.rb
|
109
|
-
- spec/test_value.rb
|
110
|
-
- spec/coercions/test_convert.rb
|
111
136
|
- spec/coercions/test_append.rb
|
112
137
|
- spec/coercions/test_belongs_to.rb
|
138
|
+
- spec/coercions/test_convert.rb
|
139
|
+
- spec/coercions/test_delegate.rb
|
113
140
|
- spec/coercions/test_dup.rb
|
114
141
|
- spec/coercions/test_subdomain.rb
|
115
|
-
- spec/
|
142
|
+
- spec/domain/impl/test_behavior.rb
|
143
|
+
- spec/domain/impl/test_value_methods.rb
|
144
|
+
- spec/domain/sbyc/test_behavior.rb
|
145
|
+
- spec/domain/test_sbyc.rb
|
146
|
+
- spec/myrrha/test_coercions.rb
|
116
147
|
- spec/shared/a_value.rb
|
148
|
+
- spec/spec_helper.rb
|
117
149
|
- spec/test_assumptions.rb
|
150
|
+
- spec/test_coerce.rb
|
151
|
+
- spec/test_myrrha.rb
|
152
|
+
- spec/test_to_ruby_literal.rb
|
153
|
+
- spec/test_value.rb
|
118
154
|
- tasks/debug_mail.rake
|
119
|
-
- tasks/
|
155
|
+
- tasks/debug_mail.txt
|
120
156
|
- tasks/examples.rake
|
121
157
|
- tasks/gem.rake
|
122
158
|
- tasks/spec_test.rake
|
123
159
|
- tasks/unit_test.rake
|
124
|
-
- tasks/
|
160
|
+
- tasks/yard.rake
|
125
161
|
- Rakefile
|
126
162
|
- CHANGELOG.md
|
127
163
|
- Gemfile
|
@@ -145,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
181
|
version: '0'
|
146
182
|
segments:
|
147
183
|
- 0
|
148
|
-
hash:
|
184
|
+
hash: -1652815196407861424
|
149
185
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
186
|
none: false
|
151
187
|
requirements:
|
@@ -154,22 +190,26 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
190
|
version: '0'
|
155
191
|
requirements: []
|
156
192
|
rubyforge_project:
|
157
|
-
rubygems_version: 1.8.
|
193
|
+
rubygems_version: 1.8.24
|
158
194
|
signing_key:
|
159
195
|
specification_version: 3
|
160
196
|
summary: Myrrha provides the coercion framework which is missing to Ruby.
|
161
197
|
test_files:
|
162
|
-
- spec/spec_helper.rb
|
163
|
-
- spec/myrrha/test_coercions.rb
|
164
|
-
- spec/myrrha/test_domain.rb
|
165
|
-
- spec/test_myrrha.rb
|
166
|
-
- spec/test_to_ruby_literal.rb
|
167
|
-
- spec/test_value.rb
|
168
|
-
- spec/coercions/test_convert.rb
|
169
198
|
- spec/coercions/test_append.rb
|
170
199
|
- spec/coercions/test_belongs_to.rb
|
200
|
+
- spec/coercions/test_convert.rb
|
201
|
+
- spec/coercions/test_delegate.rb
|
171
202
|
- spec/coercions/test_dup.rb
|
172
203
|
- spec/coercions/test_subdomain.rb
|
173
|
-
- spec/
|
204
|
+
- spec/domain/impl/test_behavior.rb
|
205
|
+
- spec/domain/impl/test_value_methods.rb
|
206
|
+
- spec/domain/sbyc/test_behavior.rb
|
207
|
+
- spec/domain/test_sbyc.rb
|
208
|
+
- spec/myrrha/test_coercions.rb
|
174
209
|
- spec/shared/a_value.rb
|
210
|
+
- spec/spec_helper.rb
|
175
211
|
- spec/test_assumptions.rb
|
212
|
+
- spec/test_coerce.rb
|
213
|
+
- spec/test_myrrha.rb
|
214
|
+
- spec/test_to_ruby_literal.rb
|
215
|
+
- spec/test_value.rb
|
data/spec/myrrha/test_domain.rb
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
module Myrrha
|
3
|
-
describe "#domain" do
|
4
|
-
|
5
|
-
specify "the basic contract" do
|
6
|
-
subject = Myrrha.domain{|s| s == 12}
|
7
|
-
subject.should be_a(Class)
|
8
|
-
subject.superclass.should eq(Object)
|
9
|
-
(subject === 12).should be_true
|
10
|
-
(subject === 13).should be_false
|
11
|
-
end
|
12
|
-
|
13
|
-
specify "with a ruby superclass" do
|
14
|
-
subject = Myrrha.domain(Integer){|i| i > 0}
|
15
|
-
subject.should be_a(Class)
|
16
|
-
subject.superclass.should eq(Integer)
|
17
|
-
(subject === 12).should be_true
|
18
|
-
(subject === 0).should be_false
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "A factored sub domain of Integer" do
|
22
|
-
PosInt = Myrrha.domain(Integer){|i| i > 0}
|
23
|
-
specify("#name") {
|
24
|
-
PosInt.name.should eq("Myrrha::PosInt")
|
25
|
-
}
|
26
|
-
specify("#new") {
|
27
|
-
PosInt.new(12).should eq(12)
|
28
|
-
lambda {
|
29
|
-
PosInt.new(0)
|
30
|
-
}.should raise_error(ArgumentError)
|
31
|
-
}
|
32
|
-
specify("#superclass"){
|
33
|
-
PosInt.superclass.should eql(Integer)
|
34
|
-
}
|
35
|
-
specify("#superdomain_of?"){
|
36
|
-
PosInt.superdomain_of?(Object).should be_false
|
37
|
-
PosInt.superdomain_of?(Integer).should be_false
|
38
|
-
}
|
39
|
-
it "should be usable in a case" do
|
40
|
-
[-12, 12].collect{|i|
|
41
|
-
case i
|
42
|
-
when PosInt
|
43
|
-
:posint
|
44
|
-
when Integer
|
45
|
-
:integer
|
46
|
-
end
|
47
|
-
}.should eq([:integer, :posint])
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "A factored domain by module inclusion" do
|
52
|
-
class NegInt < Integer
|
53
|
-
extend Myrrha::Domain
|
54
|
-
|
55
|
-
def self.predicate
|
56
|
-
@predicate ||= lambda{|i| i<0}
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
specify("#name") {
|
61
|
-
NegInt.name.should eq("Myrrha::NegInt")
|
62
|
-
}
|
63
|
-
specify("#new") {
|
64
|
-
NegInt.new(-12).should eq(-12)
|
65
|
-
lambda {
|
66
|
-
NegInt.new(12)
|
67
|
-
}.should raise_error(ArgumentError)
|
68
|
-
}
|
69
|
-
specify("#superclass"){
|
70
|
-
NegInt.superclass.should eql(Integer)
|
71
|
-
}
|
72
|
-
specify("#superdomain_of?"){
|
73
|
-
NegInt.superdomain_of?(Object).should be_false
|
74
|
-
NegInt.superdomain_of?(Integer).should be_false
|
75
|
-
}
|
76
|
-
it "should be usable in a case" do
|
77
|
-
[-12, 12].collect{|i|
|
78
|
-
case i
|
79
|
-
when NegInt
|
80
|
-
:negint
|
81
|
-
when Integer
|
82
|
-
:integer
|
83
|
-
end
|
84
|
-
}.should eq([:negint, :integer])
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe "A factored sub domain of a user-defined Class" do
|
89
|
-
class Color
|
90
|
-
attr_reader :r
|
91
|
-
attr_reader :g
|
92
|
-
attr_reader :b
|
93
|
-
def initialize(r,g,b)
|
94
|
-
raise ArgumentError unless [r,g,b].all?{|i| i.is_a?(Integer)}
|
95
|
-
@r, @g, @b = r, g, b
|
96
|
-
end
|
97
|
-
end
|
98
|
-
RedToZero = Myrrha.domain(Color){|c| c.r == 0}
|
99
|
-
specify("#===") {
|
100
|
-
(RedToZero === Color.new(0,1,1)).should be_true
|
101
|
-
(RedToZero === Color.new(1,1,1)).should be_false
|
102
|
-
}
|
103
|
-
specify("#new") {
|
104
|
-
RedToZero.new(Color.new(0,1,1)).should be_a(Color)
|
105
|
-
RedToZero.new(0, 1, 1).should be_a(Color)
|
106
|
-
lambda{
|
107
|
-
RedToZero.new(Color.new(1,1,1))
|
108
|
-
}.should raise_error(ArgumentError)
|
109
|
-
lambda{
|
110
|
-
RedToZero.new(1, 1, 1)
|
111
|
-
}.should raise_error(ArgumentError)
|
112
|
-
}
|
113
|
-
end
|
114
|
-
|
115
|
-
end
|
116
|
-
end
|