domain 0.0.1 → 1.0.0.rc1

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.
Files changed (50) hide show
  1. data/README.md +75 -2
  2. data/domain.noespec +1 -1
  3. data/lib/domain.rb +7 -2
  4. data/lib/domain/api.rb +48 -0
  5. data/lib/domain/factory.rb +52 -0
  6. data/lib/domain/factory/reuse.rb +53 -0
  7. data/lib/domain/factory/sbyc.rb +9 -0
  8. data/lib/domain/factory/scalar.rb +30 -0
  9. data/lib/domain/factory/union.rb +11 -0
  10. data/lib/domain/support.rb +3 -0
  11. data/lib/domain/support/equalizer.rb +74 -0
  12. data/lib/domain/support/fake_domain.rb +38 -0
  13. data/lib/domain/support/impl_domain.rb +17 -0
  14. data/lib/domain/version.rb +2 -2
  15. data/spec/factory/reuse_domain/test_new.rb +26 -0
  16. data/spec/factory/reuse_domain/test_predicate.rb +10 -0
  17. data/spec/factory/reuse_domain/test_recoat.rb +22 -0
  18. data/spec/factory/reuse_domain/test_reuse.rb +20 -0
  19. data/spec/factory/reuse_domain/test_values.rb +11 -0
  20. data/spec/factory/sbyc_domain/test_new.rb +22 -0
  21. data/spec/factory/sbyc_domain/test_predicate.rb +10 -0
  22. data/spec/factory/sbyc_domain/test_sub_domains.rb +14 -0
  23. data/spec/factory/sbyc_domain/test_super_domain.rb +10 -0
  24. data/spec/factory/sbyc_domain/test_super_domain_of.rb +18 -0
  25. data/spec/factory/sbyc_domain/test_triple_equal.rb +23 -0
  26. data/spec/factory/scalar_domain/test_component_reader.rb +16 -0
  27. data/spec/factory/scalar_domain/test_hash.rb +14 -0
  28. data/spec/factory/scalar_domain/test_to_hash.rb +14 -0
  29. data/spec/factory/scalar_domain/test_values.rb +11 -0
  30. data/spec/factory/test_sbyc.rb +16 -0
  31. data/spec/factory/test_scalar.rb +14 -0
  32. data/spec/factory/test_union.rb +17 -0
  33. data/spec/factory/union_domain/test_new.rb +17 -0
  34. data/spec/factory/union_domain/test_predicate.rb +18 -0
  35. data/spec/factory/union_domain/test_sub_domains.rb +10 -0
  36. data/spec/factory/union_domain/test_super_domain.rb +10 -0
  37. data/spec/factory/union_domain/test_super_domain_of.rb +18 -0
  38. data/spec/factory/union_domain/test_triple_equal.rb +15 -0
  39. data/spec/fixtures/boolean.rb +3 -0
  40. data/spec/fixtures/list.rb +6 -0
  41. data/spec/fixtures/neg_int.rb +3 -0
  42. data/spec/fixtures/point.rb +3 -0
  43. data/spec/fixtures/tuple.rb +3 -0
  44. data/spec/shared/a_domain_class.rb +11 -0
  45. data/spec/shared/a_value_object.rb +58 -0
  46. data/spec/spec_helper.rb +17 -0
  47. data/spec/support/equalizer/test_new.rb +37 -0
  48. data/spec/support/test_equalizer.rb +95 -0
  49. data/spec/test_fixtures.rb +21 -0
  50. metadata +82 -4
@@ -0,0 +1,3 @@
1
+ class NegInt < Integer
2
+ extend Domain::SByC.new(Integer){|i| i<0}
3
+ end
@@ -0,0 +1,3 @@
1
+ class Point
2
+ extend Domain::Scalar.new(:x, :y)
3
+ end
@@ -0,0 +1,3 @@
1
+ class Tuple
2
+ extend Domain::Reuse.new(Hash){|h| h.keys.all?{|k| Symbol===k} }
3
+ end
@@ -0,0 +1,11 @@
1
+ shared_examples_for 'a domain class' do
2
+
3
+ it{ should be_a(Class) }
4
+
5
+ it{ should respond_to(:predicate) }
6
+ it{ should respond_to(:sub_domains) }
7
+ it{ should respond_to(:super_domain) }
8
+
9
+ it{ should respond_to(:third_party_extension) }
10
+
11
+ end
@@ -0,0 +1,58 @@
1
+ shared_examples_for "a value object" do
2
+
3
+ describe "==" do
4
+ subject{ object == other }
5
+
6
+ context 'with itself' do
7
+ let(:other){ object }
8
+
9
+ it{ should be_true }
10
+ end
11
+
12
+ context 'with an equivalent' do
13
+ let(:other){ object.dup }
14
+
15
+ it{ should be_true }
16
+ end
17
+
18
+ context 'with a different' do
19
+ let(:other){ another_object }
20
+
21
+ it{ should be_false }
22
+ end
23
+ end
24
+
25
+ describe "eql?" do
26
+ subject{ object.eql?(other) }
27
+
28
+ context 'with itself' do
29
+ let(:other){ object }
30
+
31
+ it{ should be_true }
32
+ end
33
+
34
+ context 'with an equivalent dup' do
35
+ let(:other){ object.dup }
36
+
37
+ it{ should be_true }
38
+ end
39
+
40
+ context 'with a different' do
41
+ let(:other){ another_object }
42
+
43
+ it{ should be_false }
44
+ end
45
+ end
46
+
47
+ describe "hash" do
48
+
49
+ it 'stays the same when dupped' do
50
+ object.hash.should eq(object.dup.hash)
51
+ end
52
+
53
+ it 'is not equal to the other one' do
54
+ object.hash.should_not eq(another_object.hash)
55
+ end
56
+ end
57
+
58
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,23 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'domain'
3
3
 
4
+ require_relative 'shared/a_domain_class'
5
+ require_relative 'shared/a_value_object'
6
+
7
+ require_relative 'fixtures/neg_int'
8
+ require_relative 'fixtures/boolean'
9
+ require_relative 'fixtures/point'
10
+ require_relative 'fixtures/list'
11
+ require_relative 'fixtures/tuple'
12
+
13
+ module Domain
14
+
15
+ def third_party_extension
16
+ true
17
+ end
18
+
19
+ end
20
+
4
21
  module SpecHelpers
5
22
  end
6
23
 
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe Equalizer, "new" do
4
+
5
+ let(:clazz){
6
+ eq = equalizer
7
+ Class.new{
8
+ def initialize(x, y)
9
+ @x, @y = x, y
10
+ end
11
+ attr_reader :x, :y
12
+ include eq
13
+ }
14
+ }
15
+
16
+ subject{ clazz.new(1, 2).equality_components }
17
+
18
+ context 'with a block' do
19
+ let(:equalizer){ Equalizer.new{ [x] } }
20
+
21
+ it{ should eq([1]) }
22
+ end
23
+
24
+ context 'with a single name' do
25
+ let(:equalizer){ Equalizer.new(:x) }
26
+
27
+ it{ should eq([1]) }
28
+ end
29
+
30
+ context 'with a multiple names' do
31
+ let(:equalizer){ Equalizer.new([:x, :y]) }
32
+
33
+ it{ should eq([1, 2]) }
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe Equalizer do
4
+
5
+ let(:domain){
6
+ Class.new{
7
+ def initialize(x, y)
8
+ @x, @y = x, y
9
+ end
10
+ attr_reader :x, :y
11
+ include Equalizer.new{ [x, y] }
12
+ }
13
+ }
14
+
15
+ let(:object){ domain.new(1, 2) }
16
+
17
+ describe "==" do
18
+ subject{ object == other }
19
+
20
+ context 'with itself' do
21
+ let(:other){ object }
22
+ it{ should be_true }
23
+ end
24
+
25
+ context 'with dupped' do
26
+ let(:other){ object.dup }
27
+ it{ should be_true }
28
+ end
29
+
30
+ context 'with equivalent' do
31
+ let(:other){ domain.new(1, 2) }
32
+ it{ should be_true }
33
+ end
34
+
35
+ context 'with equivalent of a subclass' do
36
+ let(:other){ Class.new(domain).new(1, 2) }
37
+ it{ should be_true }
38
+ end
39
+
40
+ context 'with non equivalent' do
41
+ let(:other){ domain.new(1, 3) }
42
+ it{ should be_false }
43
+ end
44
+
45
+ context 'with other class' do
46
+ let(:other){ self }
47
+ it{ should be_false }
48
+ end
49
+ end
50
+
51
+ describe "eql?" do
52
+ subject{ object.eql?(other) }
53
+
54
+ context 'with itself' do
55
+ let(:other){ object }
56
+ it{ should be_true }
57
+ end
58
+
59
+ context 'with dupped' do
60
+ let(:other){ object.dup }
61
+ it{ should be_true }
62
+ end
63
+
64
+ context 'with equivalent' do
65
+ let(:other){ domain.new(1, 2) }
66
+ it{ should be_true }
67
+ end
68
+
69
+ context 'with equivalent of a subclass' do
70
+ let(:other){ Class.new(domain).new(1, 2) }
71
+ it{ should be_false }
72
+ end
73
+
74
+ context 'with non equivalent' do
75
+ let(:other){ domain.new(1, 3) }
76
+ it{ should be_false }
77
+ end
78
+
79
+ context 'with other class' do
80
+ let(:other){ self }
81
+ it{ should be_false }
82
+ end
83
+ end
84
+
85
+ describe "hash" do
86
+ subject{ object.hash }
87
+
88
+ it 'should be consistent with equal' do
89
+ subject.should eq(domain.new(1,2).hash)
90
+ end
91
+ end
92
+
93
+ end
94
+ end
95
+
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe NegInt do
4
+ subject{ NegInt }
5
+ it_should_behave_like 'a domain class'
6
+ end
7
+
8
+ describe Boolean do
9
+ subject{ Boolean }
10
+ it_should_behave_like 'a domain class'
11
+ end
12
+
13
+ describe Point do
14
+ subject{ Point }
15
+ it_should_behave_like 'a domain class'
16
+ end
17
+
18
+ describe List do
19
+ subject{ List }
20
+ it_should_behave_like 'a domain class'
21
+ end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 1.0.0.rc1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bernard Lambeau
@@ -59,15 +59,59 @@ files:
59
59
  - CHANGELOG.md
60
60
  - Gemfile
61
61
  - Gemfile.lock
62
+ - lib/domain/api.rb
63
+ - lib/domain/factory/reuse.rb
64
+ - lib/domain/factory/sbyc.rb
65
+ - lib/domain/factory/scalar.rb
66
+ - lib/domain/factory/union.rb
67
+ - lib/domain/factory.rb
62
68
  - lib/domain/loader.rb
69
+ - lib/domain/support/equalizer.rb
70
+ - lib/domain/support/fake_domain.rb
71
+ - lib/domain/support/impl_domain.rb
72
+ - lib/domain/support.rb
63
73
  - lib/domain/version.rb
64
74
  - lib/domain.rb
65
75
  - LICENCE.md
66
76
  - Manifest.txt
67
77
  - Rakefile
68
78
  - README.md
79
+ - spec/factory/reuse_domain/test_new.rb
80
+ - spec/factory/reuse_domain/test_predicate.rb
81
+ - spec/factory/reuse_domain/test_recoat.rb
82
+ - spec/factory/reuse_domain/test_reuse.rb
83
+ - spec/factory/reuse_domain/test_values.rb
84
+ - spec/factory/sbyc_domain/test_new.rb
85
+ - spec/factory/sbyc_domain/test_predicate.rb
86
+ - spec/factory/sbyc_domain/test_sub_domains.rb
87
+ - spec/factory/sbyc_domain/test_super_domain.rb
88
+ - spec/factory/sbyc_domain/test_super_domain_of.rb
89
+ - spec/factory/sbyc_domain/test_triple_equal.rb
90
+ - spec/factory/scalar_domain/test_component_reader.rb
91
+ - spec/factory/scalar_domain/test_hash.rb
92
+ - spec/factory/scalar_domain/test_to_hash.rb
93
+ - spec/factory/scalar_domain/test_values.rb
94
+ - spec/factory/test_sbyc.rb
95
+ - spec/factory/test_scalar.rb
96
+ - spec/factory/test_union.rb
97
+ - spec/factory/union_domain/test_new.rb
98
+ - spec/factory/union_domain/test_predicate.rb
99
+ - spec/factory/union_domain/test_sub_domains.rb
100
+ - spec/factory/union_domain/test_super_domain.rb
101
+ - spec/factory/union_domain/test_super_domain_of.rb
102
+ - spec/factory/union_domain/test_triple_equal.rb
103
+ - spec/fixtures/boolean.rb
104
+ - spec/fixtures/list.rb
105
+ - spec/fixtures/neg_int.rb
106
+ - spec/fixtures/point.rb
107
+ - spec/fixtures/tuple.rb
108
+ - spec/shared/a_domain_class.rb
109
+ - spec/shared/a_value_object.rb
69
110
  - spec/spec_helper.rb
111
+ - spec/support/equalizer/test_new.rb
112
+ - spec/support/test_equalizer.rb
70
113
  - spec/test_domain.rb
114
+ - spec/test_fixtures.rb
71
115
  - tasks/gem.rake
72
116
  - tasks/spec_test.rake
73
117
  homepage: https://github.com/blambeau/domain
@@ -85,9 +129,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
129
  required_rubygems_version: !ruby/object:Gem::Requirement
86
130
  none: false
87
131
  requirements:
88
- - - ! '>='
132
+ - - ! '>'
89
133
  - !ruby/object:Gem::Version
90
- version: '0'
134
+ version: 1.3.1
91
135
  requirements: []
92
136
  rubyforge_project:
93
137
  rubygems_version: 1.8.24
@@ -95,5 +139,39 @@ signing_key:
95
139
  specification_version: 3
96
140
  summary: Provide tools for implementing domains (aka data types)
97
141
  test_files:
142
+ - spec/factory/reuse_domain/test_new.rb
143
+ - spec/factory/reuse_domain/test_predicate.rb
144
+ - spec/factory/reuse_domain/test_recoat.rb
145
+ - spec/factory/reuse_domain/test_reuse.rb
146
+ - spec/factory/reuse_domain/test_values.rb
147
+ - spec/factory/sbyc_domain/test_new.rb
148
+ - spec/factory/sbyc_domain/test_predicate.rb
149
+ - spec/factory/sbyc_domain/test_sub_domains.rb
150
+ - spec/factory/sbyc_domain/test_super_domain.rb
151
+ - spec/factory/sbyc_domain/test_super_domain_of.rb
152
+ - spec/factory/sbyc_domain/test_triple_equal.rb
153
+ - spec/factory/scalar_domain/test_component_reader.rb
154
+ - spec/factory/scalar_domain/test_hash.rb
155
+ - spec/factory/scalar_domain/test_to_hash.rb
156
+ - spec/factory/scalar_domain/test_values.rb
157
+ - spec/factory/test_sbyc.rb
158
+ - spec/factory/test_scalar.rb
159
+ - spec/factory/test_union.rb
160
+ - spec/factory/union_domain/test_new.rb
161
+ - spec/factory/union_domain/test_predicate.rb
162
+ - spec/factory/union_domain/test_sub_domains.rb
163
+ - spec/factory/union_domain/test_super_domain.rb
164
+ - spec/factory/union_domain/test_super_domain_of.rb
165
+ - spec/factory/union_domain/test_triple_equal.rb
166
+ - spec/fixtures/boolean.rb
167
+ - spec/fixtures/list.rb
168
+ - spec/fixtures/neg_int.rb
169
+ - spec/fixtures/point.rb
170
+ - spec/fixtures/tuple.rb
171
+ - spec/shared/a_domain_class.rb
172
+ - spec/shared/a_value_object.rb
98
173
  - spec/spec_helper.rb
174
+ - spec/support/equalizer/test_new.rb
175
+ - spec/support/test_equalizer.rb
99
176
  - spec/test_domain.rb
177
+ - spec/test_fixtures.rb