domain 0.0.1 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,9 +1,9 @@
1
1
  module Domain
2
2
  module Version
3
3
 
4
- MAJOR = 0
4
+ MAJOR = 1
5
5
  MINOR = 0
6
- TINY = 1
6
+ TINY = "0.rc1"
7
7
 
8
8
  def self.to_s
9
9
  [ MAJOR, MINOR, TINY ].join('.')
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe Reuse, "new" do
4
+
5
+ it 'returns an instance when correct reused instance' do
6
+ List.new([1, 2, 3]).should be_a(List)
7
+ end
8
+
9
+ it 'returns an instance when correct reused instance and valid predicate' do
10
+ Tuple.new(:foo => "bar").should be_a(Tuple)
11
+ end
12
+
13
+ it 'raises an ArgumentError when not correct reused instance' do
14
+ lambda{
15
+ List.new("foo")
16
+ }.should raise_error(ArgumentError)
17
+ end
18
+
19
+ it 'raises an ArgumentError when the predicate is not satisfied' do
20
+ lambda{
21
+ Tuple.new("foo" => :bar)
22
+ }.should raise_error(ArgumentError)
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe Reuse, "predicate" do
4
+
5
+ it 'returns a Proc' do
6
+ Tuple.predicate.should be_a(Proc)
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe Reuse, "recoat" do
4
+
5
+ let(:object){ List.new([1, 2, 3]) }
6
+
7
+ describe "map" do
8
+ subject{ object.map{|x| x*2} }
9
+
10
+ it{ should be_a(List) }
11
+ it{ should eq(List.new([2, 4, 6])) }
12
+ end
13
+
14
+ describe "reject" do
15
+ subject{ object.reject{|x| x%2 == 0} }
16
+
17
+ it{ should be_a(List) }
18
+ it{ should eq(List.new([1, 3])) }
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe Reuse, "reuse" do
4
+
5
+ let(:object){ List.new([1, 2, 3]) }
6
+
7
+ describe "size" do
8
+ subject{ object.size }
9
+
10
+ it{ should eq(3) }
11
+ end
12
+
13
+ describe "empty?" do
14
+ subject{ object.empty? }
15
+
16
+ it{ should be_false }
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe Reuse, "values" do
4
+
5
+ let(:object) { List.new([1, 2, 3]) }
6
+ let(:another_object){ List.new([2, 3, 4]) }
7
+
8
+ it_should_behave_like 'a value object'
9
+
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe SByC, "new" do
4
+
5
+ it 'returns the value when it satisfies the predicate' do
6
+ NegInt.new(-12).should eq(-12)
7
+ end
8
+
9
+ it 'raises an argument error when the value does not satisfy the predicate' do
10
+ lambda{
11
+ NegInt.new(12)
12
+ }.should raise_error(ArgumentError)
13
+ end
14
+
15
+ it 'raises an argument error when the value is not a superclazz value' do
16
+ lambda{
17
+ NegInt.new("bla")
18
+ }.should raise_error(ArgumentError)
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe SByC, "predicate" do
4
+
5
+ it 'returns a Proc' do
6
+ Boolean.predicate.should be_a(Proc)
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe SByC, "super_domain" do
4
+
5
+ it 'returns the super domain passed at construction' do
6
+ NegInt.super_domain.should be(Integer)
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe SByC, "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
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe SByC, "===" do
4
+
5
+ it 'returns true when a proper value' do
6
+ (Boolean === true).should be_true
7
+ (Boolean === false).should be_true
8
+ end
9
+
10
+ it 'returns false when not a value' do
11
+ (Boolean === 1).should be_false
12
+ end
13
+
14
+ it 'returns false when a superclass value that satisfies the predicate' do
15
+ (NegInt === -1).should be_true
16
+ end
17
+
18
+ it 'returns false when a superclass value that do not satisfy the predicate' do
19
+ (NegInt === 1).should be_false
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe Scalar, "component reader" do
4
+
5
+ let(:point){ Point.new(1, 2) }
6
+
7
+ it 'has a `x` reader' do
8
+ point.x.should eq(1)
9
+ end
10
+
11
+ it 'has a `y` reader' do
12
+ point.y.should eq(2)
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe Scalar, "hash" do
4
+
5
+ let(:point){ Point.new(1, 2) }
6
+
7
+ subject{ point.hash }
8
+
9
+ it 'should equal the hash of an equivalent point' do
10
+ subject.should eq(Point.new(1,2).hash)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe Scalar, "to_hash" do
4
+
5
+ let(:point){ Point.new(1, 2) }
6
+
7
+ subject{ point.to_hash }
8
+
9
+ it 'returns a hash with component values' do
10
+ subject.should eq(:x => 1, :y => 2)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe Scalar, "values" do
4
+
5
+ let(:object) { Point.new(1, 2) }
6
+ let(:another_object){ Point.new(2, 3) }
7
+
8
+ it_should_behave_like 'a value object'
9
+
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ describe Domain, "sbyc" do
3
+
4
+ subject{ Domain.sbyc(Integer){|i| i > 0} }
5
+
6
+ it_should_behave_like 'a domain class'
7
+
8
+ it 'should recognize positive integers' do
9
+ (subject === 10).should be_true
10
+ end
11
+
12
+ it 'should not recognize negative integers' do
13
+ (subject === -10).should be_false
14
+ end
15
+
16
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ describe Domain, "scalar" do
3
+
4
+ subject{ Domain.scalar(:x, :y) }
5
+
6
+ it_should_behave_like 'a domain class'
7
+
8
+ it 'should create a class that accepts two components' do
9
+ point = subject.new(1, 2)
10
+ point.x.should eq(1)
11
+ point.y.should eq(2)
12
+ end
13
+
14
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ describe Domain, "union" do
3
+
4
+ subject{ Domain.union(TrueClass, FalseClass) }
5
+
6
+ it_should_behave_like 'a domain class'
7
+
8
+ it 'should recognize true and false' do
9
+ (subject === true).should be_true
10
+ (subject === false).should be_true
11
+ end
12
+
13
+ it 'should not recognize non booleans' do
14
+ (subject === -10).should be_false
15
+ end
16
+
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe Union, "new" do
4
+
5
+ it 'returns the value when it satisfies the predicate' do
6
+ Boolean.new(true).should be(true)
7
+ Boolean.new(false).should be(false)
8
+ end
9
+
10
+ it 'raises an argument error when the value is not a superclazz value' do
11
+ lambda{
12
+ Boolean.new("12")
13
+ }.should raise_error(ArgumentError)
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe Union, "predicate" do
4
+
5
+ it 'returns a Proc' do
6
+ Boolean.predicate.should be_a(Proc)
7
+ end
8
+
9
+ it 'is satisfied when a valid value' do
10
+ Boolean.predicate.call(true).should be_true
11
+ end
12
+
13
+ it 'is not satisfied when an invalid value' do
14
+ Boolean.predicate.call("12").should be_false
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe Union, "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
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe Union, "super_domain" do
4
+
5
+ it 'returns the super domain passed at construction' do
6
+ Boolean.super_domain.should be(Object)
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ module Domain
3
+ describe Union, "===" do
4
+
5
+ it 'returns true when a proper value' do
6
+ (Boolean === true).should be_true
7
+ (Boolean === false).should be_true
8
+ end
9
+
10
+ it 'returns false when not a value' do
11
+ (Boolean === 1).should be_false
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ class Boolean
2
+ extend Domain::Union.new(TrueClass, FalseClass)
3
+ end
@@ -0,0 +1,6 @@
1
+ class List
2
+ extend Domain::Reuse.new(Array)
3
+
4
+ reuse :size, :empty?
5
+ recoat :map, :select, :reject
6
+ end