activefacts-api 0.8.12 → 0.9.1

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 (36) hide show
  1. data/.rspec +1 -0
  2. data/.travis.yml +9 -0
  3. data/Gemfile +14 -0
  4. data/Rakefile +21 -9
  5. data/VERSION +1 -1
  6. data/activefacts-api.gemspec +31 -12
  7. data/lib/activefacts/api.rb +1 -0
  8. data/lib/activefacts/api/constellation.rb +3 -1
  9. data/lib/activefacts/api/entity.rb +74 -29
  10. data/lib/activefacts/api/exceptions.rb +17 -0
  11. data/lib/activefacts/api/instance.rb +96 -1
  12. data/lib/activefacts/api/instance_index.rb +35 -37
  13. data/lib/activefacts/api/numeric.rb +62 -56
  14. data/lib/activefacts/api/object_type.rb +49 -23
  15. data/lib/activefacts/api/role.rb +8 -2
  16. data/lib/activefacts/api/role_values.rb +8 -26
  17. data/lib/activefacts/api/standard_types.rb +2 -17
  18. data/lib/activefacts/api/vocabulary.rb +1 -1
  19. data/lib/activefacts/tracer.rb +13 -1
  20. data/spec/{constellation_spec.rb → constellation/constellation_spec.rb} +127 -56
  21. data/spec/constellation/instance_index_spec.rb +90 -0
  22. data/spec/{instance_spec.rb → constellation/instance_spec.rb} +48 -42
  23. data/spec/{role_values_spec.rb → fact_type/role_values_spec.rb} +28 -19
  24. data/spec/{roles_spec.rb → fact_type/roles_spec.rb} +55 -21
  25. data/spec/fixtures/tax.rb +45 -0
  26. data/spec/{identification_spec.rb → identification_scheme/identification_spec.rb} +88 -74
  27. data/spec/identification_scheme/identity_change_spec.rb +118 -0
  28. data/spec/identification_scheme/identity_supertype_change_spec.rb +63 -0
  29. data/spec/{entity_type_spec.rb → object_type/entity_type/entity_type_spec.rb} +2 -4
  30. data/spec/object_type/entity_type/multipart_identification_spec.rb +77 -0
  31. data/spec/{autocounter_spec.rb → object_type/value_type/autocounter_spec.rb} +2 -4
  32. data/spec/object_type/value_type/numeric_spec.rb +63 -0
  33. data/spec/{value_type_spec.rb → object_type/value_type/value_type_spec.rb} +10 -14
  34. data/spec/simplecov_helper.rb +8 -0
  35. data/spec/spec_helper.rb +1 -1
  36. metadata +100 -19
@@ -0,0 +1,77 @@
1
+ require 'activefacts/api'
2
+
3
+ module TestMultiPartIdentifierModule
4
+ class ParentId < AutoCounter
5
+ value_type
6
+ end
7
+
8
+ class Parent
9
+ identified_by :parent_id
10
+ one_to_one :parent_id
11
+ end
12
+
13
+ class Position < Int
14
+ value_type
15
+ end
16
+
17
+ class Child
18
+ identified_by :parent, :position
19
+ has_one :parent
20
+ has_one :position
21
+ end
22
+ end
23
+
24
+ describe "Multi-part identifiers" do
25
+ include ActiveFacts::API
26
+ before :each do
27
+ @c = Constellation.new(TestMultiPartIdentifierModule)
28
+ @p = @c.Parent(:new)
29
+ @c0 = @c.Child(@p, 0)
30
+ @c2 = @c.Child(@p, 2)
31
+ @c1 = @c.Child(@p, 1)
32
+ end
33
+
34
+ it "should allow children to be found in the instance index" do
35
+ @c.Child[[@p, 0]].should == @c0
36
+ @c.Child[[@p, 1]].should == @c1
37
+ @c.Child[[@p, 2]].should == @c2
38
+ end
39
+
40
+ it "should sort child keys in the instance index" do
41
+ pending "Key sorting is not supported in this version" unless @p.all_child.respond_to? :keys
42
+ @c.Child.keys.should == [[[@p.parent_id], 0], [[@p.parent_id], 1], [[@p.parent_id], 2]]
43
+ @c.Child.map{|k, c| c.position}.should == [@c0.position, @c1.position, @c2.position]
44
+ end
45
+
46
+ it "should index children in the parent's RoleValues" do
47
+ @p.all_child.size.should == 3
48
+ end
49
+
50
+ it "should allow children to be found in the instance index by the residual key" do
51
+ pending "RoleValues use the whole key, not the residual key" do
52
+ @c.Child[[0]].should == @c0
53
+ @c.Child[[1]].should == @c1
54
+ @c.Child[[2]].should == @c2
55
+ end
56
+ end
57
+
58
+ it "should allow children to be found in the instance index by the whole key" do
59
+ @c.Child[[[@p.parent_id], 0]].should == @c0
60
+ @c.Child[[[@p.parent_id], 1]].should == @c1
61
+ @c.Child[[[@p.parent_id], 2]].should == @c2
62
+ end
63
+
64
+ it "should sort children in the parent's RoleValues" do
65
+ pending "Key sorting is not supported in this version" if @p.all_child.instance_variable_get("@a").kind_of? Array
66
+ @p.all_child.to_a[0].should == @c0
67
+ @p.all_child.to_a[1].should == @c1
68
+ @p.all_child.to_a[2].should == @c2
69
+ end
70
+
71
+ it "should have a correct key for each child in the parent's RoleValues" do
72
+ pending "Key sorting is not supported in this version" if @p.all_child.instance_variable_get("@a").kind_of? Array
73
+ @p.all_child.keys[0].should == [[@p.parent_id], 0]
74
+ @p.all_child.keys[1].should == [[@p.parent_id], 1]
75
+ @p.all_child.keys[2].should == [[@p.parent_id], 2]
76
+ end
77
+ end
@@ -2,8 +2,6 @@
2
2
  # ActiveFacts tests: Value instances in the Runtime API
3
3
  # Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
4
4
  #
5
- require 'rspec'
6
- require 'activefacts/api'
7
5
 
8
6
  describe "AutoCounter Value Type instances" do
9
7
  before :each do
@@ -14,7 +12,7 @@ describe "AutoCounter Value Type instances" do
14
12
  end
15
13
  class Thing
16
14
  identified_by :thing_id
17
- has_one :thing_id
15
+ one_to_one :thing_id
18
16
  end
19
17
  class Ordinal < Int
20
18
  value_type
@@ -43,7 +41,7 @@ describe "AutoCounter Value Type instances" do
43
41
  end
44
42
 
45
43
  it "should respond to its roles" do
46
- @thing_id.respond_to?(:all_thing).should be_true
44
+ @thing_id.respond_to?(:thing).should be_true
47
45
  end
48
46
 
49
47
  it "should allow prevent invalid role assignment" do
@@ -0,0 +1,63 @@
1
+ #
2
+ # ActiveFacts tests: Value instances in the Runtime API
3
+ # Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
4
+ #
5
+
6
+ describe Int do
7
+ before :each do
8
+ @i = Int.new(1)
9
+ end
10
+
11
+ it "should be encodable in JSON" do
12
+ @i.to_json.should == "1"
13
+ end
14
+
15
+ it "should behave like an Integer" do
16
+ 1.should == @i
17
+ @i.should == 1
18
+ @i.to_s.should == "1"
19
+ @i.should eql 1
20
+ @i.should be_an Integer
21
+ end
22
+
23
+ it "should also know that it's a delegator" do
24
+ @i.is_a?(SimpleDelegator).should be_true
25
+ @i.is_a?(Int).should be_true
26
+ end
27
+ end
28
+
29
+ describe Real do
30
+ before :each do
31
+ @r = Real.new(1.0)
32
+ end
33
+
34
+ it "should be encodable in JSON" do
35
+ @r.to_json.should == "1.0"
36
+ end
37
+
38
+ it "should behave like a Float" do
39
+ 1.0.should == @r
40
+ @r.should == 1.0
41
+ @r.to_s.should == "1.0"
42
+ @r.eql?(1.0).should be_true
43
+ @r.is_a?(Float).should be_true
44
+ end
45
+
46
+ it "should also know that it's a delegator" do
47
+ @r.is_a?(SimpleDelegator).should be_true
48
+ @r.is_a?(Real).should be_true
49
+ end
50
+ end
51
+
52
+ describe Decimal do
53
+ it "should still detect Decimal as the main class" do
54
+ bd = Decimal.new("98765432109876543.210")
55
+ bd.to_s("F").should == "98765432109876543.21"
56
+ bd.to_s("E").should == "0.9876543210987654321E17"
57
+ bd.to_s("3E").should =~ /0.987 654 321 098 765 432 1.*E17/
58
+ bd.to_s(3).should =~ /0.987 654 321 098 765 432 1.*E17/
59
+ bd.to_s("3F").should == "987 654 321 098 765 43.21"
60
+ bd.should be_a Decimal
61
+ bd.should be_a BigDecimal
62
+ end
63
+ end
@@ -2,8 +2,6 @@
2
2
  # ActiveFacts tests: Value types in the Runtime API
3
3
  # Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
4
4
  #
5
- require 'rspec'
6
- require 'activefacts/api'
7
5
 
8
6
  describe "Value Type class definitions" do
9
7
  before :each do
@@ -23,7 +21,7 @@ describe "Value Type class definitions" do
23
21
  end
24
22
  end
25
23
 
26
- @classes = [Mod::Name, Mod::Year,Mod::Weight]
24
+ @classes = [Mod::Name, Mod::Year, Mod::Weight]
27
25
  @attrs = [:name, :name, :name]
28
26
 
29
27
  end
@@ -86,18 +84,11 @@ describe "Value Type class definitions" do
86
84
  # Check the role definition may not be accessed by passing an index:
87
85
  Mod::Name.roles(0).should be_nil
88
86
 
89
- @classes.zip(@attrs).each { |pair|
90
- klass, attr = *pair
91
- role = klass.roles(attr)
92
- role.should_not be_nil
93
-
94
- role = klass.roles(attr.to_s)
95
- role.should_not be_nil
96
-
87
+ @classes.zip(@attrs).each { |klass, attr|
88
+ klass.roles(attr).should_not be_nil
89
+ klass.roles(attr.to_s).should_not be_nil
97
90
  # Check the role definition may be accessed by indexing the returned array:
98
- role = klass.roles[attr]
99
- role.should_not be_nil
100
-
91
+ klass.roles[attr].should_not be_nil
101
92
  # Check the role definition array by .include?
102
93
  klass.roles.include?(attr).should be_true
103
94
  }
@@ -112,4 +103,9 @@ describe "Value Type class definitions" do
112
103
  end
113
104
  }.should raise_error
114
105
  end
106
+
107
+ it "should allow configuration of Role value through constructor using role name" do
108
+ w = Mod::Weight.new(9.0, :name => "pounds")
109
+ w.name.should == "pounds"
110
+ end
115
111
  end
@@ -0,0 +1,8 @@
1
+ require 'simplecov'
2
+ require 'activefacts/api'
3
+
4
+
5
+ SimpleCov.start do
6
+ add_filter "/spec/"
7
+ add_filter "/lib/activefacts/tracer.rb"
8
+ end
data/spec/spec_helper.rb CHANGED
@@ -9,4 +9,4 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
9
 
10
10
  RSpec.configure do |config|
11
11
 
12
- end
12
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activefacts-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.12
4
+ version: 0.9.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,59 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-03 00:00:00.000000000Z
12
+ date: 2012-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: jeweler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
14
46
  - !ruby/object:Gem::Dependency
15
47
  name: rspec
16
- requirement: &70247315177760 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.6.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.6.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
17
65
  none: false
18
66
  requirements:
19
67
  - - ~>
@@ -21,10 +69,15 @@ dependencies:
21
69
  version: 2.3.0
22
70
  type: :development
23
71
  prerelease: false
24
- version_requirements: *70247315177760
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.3.0
25
78
  - !ruby/object:Gem::Dependency
26
79
  name: bundler
27
- requirement: &70247315159600 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
28
81
  none: false
29
82
  requirements:
30
83
  - - ~>
@@ -32,10 +85,15 @@ dependencies:
32
85
  version: 1.0.0
33
86
  type: :development
34
87
  prerelease: false
35
- version_requirements: *70247315159600
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.0.0
36
94
  - !ruby/object:Gem::Dependency
37
95
  name: jeweler
38
- requirement: &70247315158800 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
39
97
  none: false
40
98
  requirements:
41
99
  - - ~>
@@ -43,10 +101,15 @@ dependencies:
43
101
  version: 1.5.2
44
102
  type: :development
45
103
  prerelease: false
46
- version_requirements: *70247315158800
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.5.2
47
110
  - !ruby/object:Gem::Dependency
48
111
  name: rdoc
49
- requirement: &70247315158320 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
50
113
  none: false
51
114
  requirements:
52
115
  - - ! '>='
@@ -54,7 +117,12 @@ dependencies:
54
117
  version: 2.4.2
55
118
  type: :development
56
119
  prerelease: false
57
- version_requirements: *70247315158320
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 2.4.2
58
126
  description: ! '
59
127
 
60
128
  The ActiveFacts API is a Ruby DSL for managing constellations of elementary facts.
@@ -80,6 +148,8 @@ extra_rdoc_files:
80
148
  files:
81
149
  - .document
82
150
  - .rspec
151
+ - .travis.yml
152
+ - Gemfile
83
153
  - LICENSE.txt
84
154
  - README.rdoc
85
155
  - Rakefile
@@ -88,6 +158,7 @@ files:
88
158
  - lib/activefacts/api.rb
89
159
  - lib/activefacts/api/constellation.rb
90
160
  - lib/activefacts/api/entity.rb
161
+ - lib/activefacts/api/exceptions.rb
91
162
  - lib/activefacts/api/instance.rb
92
163
  - lib/activefacts/api/instance_index.rb
93
164
  - lib/activefacts/api/numeric.rb
@@ -99,15 +170,22 @@ files:
99
170
  - lib/activefacts/api/value.rb
100
171
  - lib/activefacts/api/vocabulary.rb
101
172
  - lib/activefacts/tracer.rb
102
- - spec/autocounter_spec.rb
103
- - spec/constellation_spec.rb
104
- - spec/entity_type_spec.rb
105
- - spec/identification_spec.rb
106
- - spec/instance_spec.rb
107
- - spec/role_values_spec.rb
108
- - spec/roles_spec.rb
173
+ - spec/constellation/constellation_spec.rb
174
+ - spec/constellation/instance_index_spec.rb
175
+ - spec/constellation/instance_spec.rb
176
+ - spec/fact_type/role_values_spec.rb
177
+ - spec/fact_type/roles_spec.rb
178
+ - spec/fixtures/tax.rb
179
+ - spec/identification_scheme/identification_spec.rb
180
+ - spec/identification_scheme/identity_change_spec.rb
181
+ - spec/identification_scheme/identity_supertype_change_spec.rb
182
+ - spec/object_type/entity_type/entity_type_spec.rb
183
+ - spec/object_type/entity_type/multipart_identification_spec.rb
184
+ - spec/object_type/value_type/autocounter_spec.rb
185
+ - spec/object_type/value_type/numeric_spec.rb
186
+ - spec/object_type/value_type/value_type_spec.rb
187
+ - spec/simplecov_helper.rb
109
188
  - spec/spec_helper.rb
110
- - spec/value_type_spec.rb
111
189
  - TODO
112
190
  homepage: http://github.com/cjheath/activefacts-api
113
191
  licenses:
@@ -122,6 +200,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
200
  - - ! '>='
123
201
  - !ruby/object:Gem::Version
124
202
  version: '0'
203
+ segments:
204
+ - 0
205
+ hash: -115051205144526317
125
206
  required_rubygems_version: !ruby/object:Gem::Requirement
126
207
  none: false
127
208
  requirements:
@@ -130,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
211
  version: '0'
131
212
  requirements: []
132
213
  rubyforge_project:
133
- rubygems_version: 1.8.10
214
+ rubygems_version: 1.8.24
134
215
  signing_key:
135
216
  specification_version: 3
136
217
  summary: A fact-based data model DSL and API