domain 1.0.0.rc2 → 1.0.0.rc3
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 +1 -1
- data/domain.noespec +1 -1
- data/lib/domain/api.rb +0 -33
- data/lib/domain/factory/union.rb +17 -1
- data/lib/domain/support.rb +1 -0
- data/lib/domain/support/comparisons.rb +21 -0
- data/lib/domain/support/equalizer.rb +1 -15
- data/lib/domain/version.rb +1 -1
- data/spec/factory/sbyc_domain/test_comparison.rb +15 -0
- data/spec/factory/union_domain/test_comparison.rb +34 -0
- data/spec/factory/union_domain/test_greater_or_equal_to.rb +18 -0
- data/spec/factory/{sbyc_domain/test_super_domain_of.rb → union_domain/test_greater_than.rb} +4 -4
- data/spec/shared/a_domain_class.rb +23 -3
- data/spec/support/test_equalizer.rb +1 -1
- metadata +11 -10
- data/spec/factory/sbyc_domain/test_sub_domains.rb +0 -14
- data/spec/factory/union_domain/test_super_domain.rb +0 -10
- data/spec/factory/union_domain/test_super_domain_of.rb +0 -18
data/CHANGELOG.md
CHANGED
data/domain.noespec
CHANGED
data/lib/domain/api.rb
CHANGED
@@ -1,39 +1,6 @@
|
|
1
1
|
module Domain
|
2
2
|
module API
|
3
3
|
|
4
|
-
# Returns the super domain of `self`.
|
5
|
-
#
|
6
|
-
# @return [Class]
|
7
|
-
# the super domain of `self` as a ruby class
|
8
|
-
#
|
9
|
-
# @api public
|
10
|
-
def super_domain
|
11
|
-
superclass
|
12
|
-
end
|
13
|
-
|
14
|
-
# Returns the sub domains of `self`.
|
15
|
-
#
|
16
|
-
# @return [Array]
|
17
|
-
# an array of sub domains (possibly empty)
|
18
|
-
#
|
19
|
-
# @api public
|
20
|
-
def sub_domains
|
21
|
-
[]
|
22
|
-
end
|
23
|
-
|
24
|
-
# Returns true if this domain is a super domain of `dom`.
|
25
|
-
#
|
26
|
-
# @param [Class] dom
|
27
|
-
# a domain
|
28
|
-
#
|
29
|
-
# @return [Boolean]
|
30
|
-
# true if self is a super domain of `dom`, false otherwise
|
31
|
-
#
|
32
|
-
# @api public
|
33
|
-
def super_domain_of?(dom)
|
34
|
-
sub_domains.include?(dom)
|
35
|
-
end
|
36
|
-
|
37
4
|
# Raises a type error for `args`.
|
38
5
|
#
|
39
6
|
# @param [Array] args
|
data/lib/domain/factory/union.rb
CHANGED
@@ -2,7 +2,7 @@ module Domain
|
|
2
2
|
module Union
|
3
3
|
|
4
4
|
def self.new(*sub_domains)
|
5
|
-
DomainFactory.factor [ Methods, class_module(sub_domains) ]
|
5
|
+
DomainFactory.factor [ Methods, Comparisons, class_module(sub_domains) ]
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.class_module(sub_domains)
|
@@ -29,6 +29,22 @@ module Domain
|
|
29
29
|
predicate.call(value)
|
30
30
|
end
|
31
31
|
|
32
|
+
# Compares with another domain
|
33
|
+
def <=>(other)
|
34
|
+
mine, yours = sub_domains_of(self), sub_domains_of(other)
|
35
|
+
return 0 if self==other || mine==yours
|
36
|
+
return -1 if mine.subset?(yours)
|
37
|
+
return 1 if mine.superset?(yours)
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def sub_domains_of(x)
|
44
|
+
return x.sub_domains.to_set if x.respond_to?(:sub_domains)
|
45
|
+
[ x ].to_set
|
46
|
+
end
|
47
|
+
|
32
48
|
end # module Methods
|
33
49
|
|
34
50
|
end # class Union
|
data/lib/domain/support.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Domain
|
2
|
+
module Comparisons
|
3
|
+
|
4
|
+
def >(other)
|
5
|
+
(x = (self <=> other)) && (x > 0)
|
6
|
+
end
|
7
|
+
|
8
|
+
def >=(other)
|
9
|
+
(x = (self <=> other)) && (x >= 0)
|
10
|
+
end
|
11
|
+
|
12
|
+
def <(other)
|
13
|
+
(x = (self <=> other)) && (x < 0)
|
14
|
+
end
|
15
|
+
|
16
|
+
def <=(other)
|
17
|
+
(x = (self <=> other)) && (x <= 0)
|
18
|
+
end
|
19
|
+
|
20
|
+
end # module Comparisons
|
21
|
+
end # module Domain
|
@@ -31,21 +31,6 @@ module Domain
|
|
31
31
|
equality_components.map{|c| c.hash }.reduce(self.class.hash, :^)
|
32
32
|
end
|
33
33
|
|
34
|
-
# Compare the object with other object for equality
|
35
|
-
#
|
36
|
-
# @example
|
37
|
-
# object.eql?(other) # => true or false
|
38
|
-
#
|
39
|
-
# @param [Object] other
|
40
|
-
# the other object to compare with
|
41
|
-
#
|
42
|
-
# @return [Boolean]
|
43
|
-
#
|
44
|
-
# @api public
|
45
|
-
def eql?(other)
|
46
|
-
instance_of?(other.class) and cmp?(__method__, other)
|
47
|
-
end
|
48
|
-
|
49
34
|
# Compare the object with other object for equivalency
|
50
35
|
#
|
51
36
|
# @example
|
@@ -61,6 +46,7 @@ module Domain
|
|
61
46
|
return false unless self.class <=> other.class
|
62
47
|
cmp?(__method__, other)
|
63
48
|
end
|
49
|
+
alias :eql? :==
|
64
50
|
|
65
51
|
private
|
66
52
|
|
data/lib/domain/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Domain
|
3
|
+
describe SByC, "<=>" do
|
4
|
+
|
5
|
+
it 'detects a super-domain' do
|
6
|
+
(NegInt <=> Integer).should eq(-1)
|
7
|
+
(NegInt <=> Numeric).should eq(-1)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'detects a non ancestor' do
|
11
|
+
(NegInt <=> String).should be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Domain
|
3
|
+
describe Union, "<=>" do
|
4
|
+
|
5
|
+
it 'returns 1 when a super domain' do
|
6
|
+
(Boolean <=> TrueClass).should eq(1)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'returns 0 on itself' do
|
10
|
+
(Boolean <=> Boolean).should eq(0)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns 0 on equivalent' do
|
14
|
+
(Boolean <=> Domain.union(TrueClass, FalseClass)).should eq(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns 1 on superset of domains ' do
|
18
|
+
(Boolean <=> Domain.union(TrueClass)).should eq(1)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns -1 on subset of domains ' do
|
22
|
+
(Domain.union(TrueClass) <=> Boolean).should eq(-1)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns -1 when compared with Object' do
|
26
|
+
(Boolean <=> Object).should eq(-1)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns nil when not a super domain' do
|
30
|
+
(Boolean <=> Integer).should be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Domain
|
3
|
+
describe Union, ">=" do
|
4
|
+
|
5
|
+
it 'returns true when a super domain' do
|
6
|
+
(Boolean >= TrueClass).should be_true
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'returns true on itself' do
|
10
|
+
(Boolean >= Boolean).should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns false when not a super domain' do
|
14
|
+
(Boolean >= Integer).should be_false
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
module Domain
|
3
|
-
describe
|
3
|
+
describe Union, ">" do
|
4
4
|
|
5
5
|
it 'returns true when a super domain' do
|
6
|
-
Boolean.should
|
6
|
+
(Boolean > TrueClass).should be_true
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'returns false on itself' do
|
10
|
-
Boolean
|
10
|
+
(Boolean > Boolean).should be_false
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'returns false when not a super domain' do
|
14
|
-
Boolean
|
14
|
+
(Boolean > Integer).should be_false
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
@@ -2,9 +2,29 @@ shared_examples_for 'a domain class' do
|
|
2
2
|
|
3
3
|
it{ should be_a(Class) }
|
4
4
|
|
5
|
-
it{ should respond_to(:sub_domains) }
|
6
|
-
it{ should respond_to(:super_domain) }
|
7
|
-
|
8
5
|
it{ should respond_to(:third_party_extension) }
|
9
6
|
|
7
|
+
context 'comparisons' do
|
8
|
+
|
9
|
+
it 'should compare with itself' do
|
10
|
+
(subject <=> subject).should eq(0)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should <= with itself' do
|
14
|
+
(subject <= subject).should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should < with itself' do
|
18
|
+
(subject < subject).should be_false
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should >= with itself' do
|
22
|
+
(subject >= subject).should be_true
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should > with itself' do
|
26
|
+
(subject > subject).should be_false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
10
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: domain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc3
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/domain/factory/union.rb
|
67
67
|
- lib/domain/factory.rb
|
68
68
|
- lib/domain/loader.rb
|
69
|
+
- lib/domain/support/comparisons.rb
|
69
70
|
- lib/domain/support/domain_factory.rb
|
70
71
|
- lib/domain/support/equalizer.rb
|
71
72
|
- lib/domain/support.rb
|
@@ -81,11 +82,10 @@ files:
|
|
81
82
|
- spec/factory/reuse_domain/test_recoat.rb
|
82
83
|
- spec/factory/reuse_domain/test_reuse.rb
|
83
84
|
- spec/factory/reuse_domain/test_values.rb
|
85
|
+
- spec/factory/sbyc_domain/test_comparison.rb
|
84
86
|
- spec/factory/sbyc_domain/test_new.rb
|
85
87
|
- spec/factory/sbyc_domain/test_predicate.rb
|
86
|
-
- spec/factory/sbyc_domain/test_sub_domains.rb
|
87
88
|
- spec/factory/sbyc_domain/test_super_domain.rb
|
88
|
-
- spec/factory/sbyc_domain/test_super_domain_of.rb
|
89
89
|
- spec/factory/sbyc_domain/test_triple_equal.rb
|
90
90
|
- spec/factory/scalar_domain/test_component_reader.rb
|
91
91
|
- spec/factory/scalar_domain/test_hash.rb
|
@@ -94,11 +94,12 @@ files:
|
|
94
94
|
- spec/factory/test_sbyc.rb
|
95
95
|
- spec/factory/test_scalar.rb
|
96
96
|
- spec/factory/test_union.rb
|
97
|
+
- spec/factory/union_domain/test_comparison.rb
|
98
|
+
- spec/factory/union_domain/test_greater_or_equal_to.rb
|
99
|
+
- spec/factory/union_domain/test_greater_than.rb
|
97
100
|
- spec/factory/union_domain/test_new.rb
|
98
101
|
- spec/factory/union_domain/test_predicate.rb
|
99
102
|
- 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
103
|
- spec/factory/union_domain/test_triple_equal.rb
|
103
104
|
- spec/fixtures/attr_list.rb
|
104
105
|
- spec/fixtures/boolean.rb
|
@@ -146,11 +147,10 @@ test_files:
|
|
146
147
|
- spec/factory/reuse_domain/test_recoat.rb
|
147
148
|
- spec/factory/reuse_domain/test_reuse.rb
|
148
149
|
- spec/factory/reuse_domain/test_values.rb
|
150
|
+
- spec/factory/sbyc_domain/test_comparison.rb
|
149
151
|
- spec/factory/sbyc_domain/test_new.rb
|
150
152
|
- spec/factory/sbyc_domain/test_predicate.rb
|
151
|
-
- spec/factory/sbyc_domain/test_sub_domains.rb
|
152
153
|
- spec/factory/sbyc_domain/test_super_domain.rb
|
153
|
-
- spec/factory/sbyc_domain/test_super_domain_of.rb
|
154
154
|
- spec/factory/sbyc_domain/test_triple_equal.rb
|
155
155
|
- spec/factory/scalar_domain/test_component_reader.rb
|
156
156
|
- spec/factory/scalar_domain/test_hash.rb
|
@@ -159,11 +159,12 @@ test_files:
|
|
159
159
|
- spec/factory/test_sbyc.rb
|
160
160
|
- spec/factory/test_scalar.rb
|
161
161
|
- spec/factory/test_union.rb
|
162
|
+
- spec/factory/union_domain/test_comparison.rb
|
163
|
+
- spec/factory/union_domain/test_greater_or_equal_to.rb
|
164
|
+
- spec/factory/union_domain/test_greater_than.rb
|
162
165
|
- spec/factory/union_domain/test_new.rb
|
163
166
|
- spec/factory/union_domain/test_predicate.rb
|
164
167
|
- spec/factory/union_domain/test_sub_domains.rb
|
165
|
-
- spec/factory/union_domain/test_super_domain.rb
|
166
|
-
- spec/factory/union_domain/test_super_domain_of.rb
|
167
168
|
- spec/factory/union_domain/test_triple_equal.rb
|
168
169
|
- spec/fixtures/attr_list.rb
|
169
170
|
- spec/fixtures/boolean.rb
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
module Domain
|
3
|
-
describe SByC, "sub_domains" do
|
4
|
-
|
5
|
-
it 'returns the sub domains passed at construction' do
|
6
|
-
Boolean.sub_domains.should eq([TrueClass, FalseClass])
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'defaults an empty array' do
|
10
|
-
NegInt.sub_domains.should eq([])
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
module Domain
|
3
|
-
describe Union, "super_domain_of?" do
|
4
|
-
|
5
|
-
it 'returns true when a super domain' do
|
6
|
-
Boolean.should be_super_domain_of(TrueClass)
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns false on itself' do
|
10
|
-
Boolean.should_not be_super_domain_of(Boolean)
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns false when not a super domain' do
|
14
|
-
Boolean.should_not be_super_domain_of(Integer)
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|