activefacts-api 0.9.3 → 0.9.4
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/TODO +16 -0
- data/VERSION +1 -1
- data/activefacts-api.gemspec +4 -2
- data/lib/activefacts/api/constellation.rb +118 -50
- data/lib/activefacts/api/date.rb +98 -0
- data/lib/activefacts/api/entity.rb +198 -206
- data/lib/activefacts/api/exceptions.rb +19 -4
- data/lib/activefacts/api/guid.rb +4 -13
- data/lib/activefacts/api/instance.rb +55 -93
- data/lib/activefacts/api/instance_index.rb +1 -32
- data/lib/activefacts/api/numeric.rb +51 -55
- data/lib/activefacts/api/object_type.rb +155 -151
- data/lib/activefacts/api/role.rb +3 -32
- data/lib/activefacts/api/standard_types.rb +8 -4
- data/lib/activefacts/api/support.rb +0 -22
- data/lib/activefacts/api/value.rb +62 -39
- data/lib/activefacts/tracer.rb +8 -6
- data/spec/constellation/constellation_spec.rb +150 -80
- data/spec/constellation/instance_spec.rb +97 -73
- data/spec/fact_type/role_values_spec.rb +33 -12
- data/spec/fact_type/roles_spec.rb +4 -28
- data/spec/identification_scheme/identification_spec.rb +1 -0
- data/spec/identification_scheme/identity_change_spec.rb +4 -4
- data/spec/metadata_spec.rb +269 -0
- data/spec/object_type/entity_type/multipart_identification_spec.rb +1 -2
- data/spec/object_type/value_type/autocounter_spec.rb +4 -4
- data/spec/object_type/value_type/date_time_spec.rb +1 -1
- data/spec/object_type/value_type/guid_spec.rb +3 -3
- data/spec/object_type/value_type/value_type_spec.rb +2 -1
- data/spec/simplecov_helper.rb +3 -2
- metadata +5 -3
@@ -0,0 +1,269 @@
|
|
1
|
+
#
|
2
|
+
# ActiveFacts tests: Metadata in the Runtime API
|
3
|
+
# Copyright (c) 2012 Clifford Heath. Read the LICENSE file.
|
4
|
+
#
|
5
|
+
require 'activefacts/api'
|
6
|
+
|
7
|
+
describe "In a vocabulary" do
|
8
|
+
before :each do
|
9
|
+
Object.send :remove_const, :Mod if Object.const_defined?("Mod")
|
10
|
+
module Mod
|
11
|
+
end
|
12
|
+
@constellation = ActiveFacts::API::Constellation.new(Mod)
|
13
|
+
end
|
14
|
+
|
15
|
+
ObjectType_methods = [
|
16
|
+
:has_one, :maybe, :one_to_one,
|
17
|
+
:roles, :subtypes, :supertypes, :vocabulary,
|
18
|
+
# To make private:
|
19
|
+
:check_identifying_role_has_valid_cardinality, :realise_role, :supertypes_transitive,
|
20
|
+
]
|
21
|
+
|
22
|
+
ValueType_methods = [
|
23
|
+
:assert_instance, :identifying_role_values, :index_instance,
|
24
|
+
:inherited, :length, :restrict, :scale, :value_type, :verbalise
|
25
|
+
]
|
26
|
+
|
27
|
+
Instance_methods = [
|
28
|
+
:constellation, :retract, :is_a?,
|
29
|
+
# To remove or move to EntityType
|
30
|
+
:related_entities, :check_value_change_legality,
|
31
|
+
:instance_index
|
32
|
+
]
|
33
|
+
Value_methods = Instance_methods + [
|
34
|
+
:verbalise, :identifying_role_values
|
35
|
+
]
|
36
|
+
|
37
|
+
EntityType_methods = [
|
38
|
+
:assert_instance, :identified_by,
|
39
|
+
:identifying_role_names, :identifying_role_values, :identifying_roles,
|
40
|
+
:index_instance, :inherited,
|
41
|
+
:verbalise,
|
42
|
+
# To make private:
|
43
|
+
:check_no_supertype_instance_exists, :check_supertype_identifiers_match,
|
44
|
+
:identification_inherited_from, :identification_inherited_from=,
|
45
|
+
:find_inherited_role,
|
46
|
+
:overrides_identification_of, :overrides_identification_of=,
|
47
|
+
# To remove
|
48
|
+
:created_instances, :created_instances=
|
49
|
+
]
|
50
|
+
|
51
|
+
Entity_methods = Instance_methods + [
|
52
|
+
:verbalise, :identifying_role_values,
|
53
|
+
# To remove hide or rewrite:
|
54
|
+
:identity_by, :identity_as_hash
|
55
|
+
]
|
56
|
+
|
57
|
+
Cases =
|
58
|
+
ValueClasses.map do |klass| # [String, Date, DateTime, Int, Real, AutoCounter, Decimal, Guid]
|
59
|
+
x=
|
60
|
+
{ :name => "a #{klass}",
|
61
|
+
:definition => %Q{
|
62
|
+
class T < #{klass}
|
63
|
+
value_type
|
64
|
+
end
|
65
|
+
},
|
66
|
+
:pattern => /Method: Class(#[a-z_0-9]*[?=]? )?\((defined in )?ActiveFacts::API::Value::ClassMethods[) ]/,
|
67
|
+
:class_methods => ValueType_methods,
|
68
|
+
:instance_methods => Value_methods,
|
69
|
+
:constructor_args => Array(
|
70
|
+
case klass.name
|
71
|
+
when 'String'; 'foo'
|
72
|
+
when 'DateTime'; [2008, 04, 20, 10, 28, 14]
|
73
|
+
when 'Date'; '2012-12-11'
|
74
|
+
when 'Time'; [2008, 04, 20, 10, 28, 14]
|
75
|
+
when 'Int'; 23
|
76
|
+
when 'Real'; 23.45
|
77
|
+
when 'AutoCounter', 'Guid'; :new
|
78
|
+
when 'Decimal'; '12345.5678'
|
79
|
+
else
|
80
|
+
raise "Please define constructor args for #{klass}"
|
81
|
+
end
|
82
|
+
).compact
|
83
|
+
}
|
84
|
+
debugger if x[:constructor_args].empty?
|
85
|
+
x
|
86
|
+
end + [
|
87
|
+
{ :name => "a Value Sub Type",
|
88
|
+
:definition => %q{
|
89
|
+
class V < String
|
90
|
+
value_type
|
91
|
+
end
|
92
|
+
class T < V
|
93
|
+
end
|
94
|
+
},
|
95
|
+
:pattern => /Method: Class(#[a-z_0-9]*[?=]? )?\((defined in )?ActiveFacts::API::Value::ClassMethods[) ]/,
|
96
|
+
:class_methods => ValueType_methods,
|
97
|
+
:instance_methods => Value_methods,
|
98
|
+
:constructor_args => [ 'foo' ]
|
99
|
+
},
|
100
|
+
|
101
|
+
{ :name => "an Entity Type",
|
102
|
+
:definition => %q{
|
103
|
+
class V < String
|
104
|
+
value_type
|
105
|
+
end
|
106
|
+
class T
|
107
|
+
identified_by :foo
|
108
|
+
one_to_one :foo, :class => V
|
109
|
+
end
|
110
|
+
},
|
111
|
+
:pattern => /Method: Class(#[a-z_0-9]*[?=]? )?\((defined in )?ActiveFacts::API::Entity::ClassMethods[) ]/,
|
112
|
+
:class_methods => EntityType_methods,
|
113
|
+
:instance_methods => Entity_methods,
|
114
|
+
:constructor_args => [ 'foo' ]
|
115
|
+
},
|
116
|
+
|
117
|
+
{ :name => "an Entity Sub Type",
|
118
|
+
:definition => %q{
|
119
|
+
class V < String
|
120
|
+
value_type
|
121
|
+
end
|
122
|
+
class E
|
123
|
+
identified_by :foo
|
124
|
+
one_to_one :foo, :class => V
|
125
|
+
end
|
126
|
+
class T < E
|
127
|
+
end
|
128
|
+
},
|
129
|
+
:pattern => /Method: Class(#[a-z_0-9]*[?=]? )?\((defined in )?ActiveFacts::API::Entity::ClassMethods[) ]/,
|
130
|
+
:class_methods => EntityType_methods,
|
131
|
+
:instance_methods => Entity_methods,
|
132
|
+
:constructor_args => [ 'foo' ]
|
133
|
+
},
|
134
|
+
|
135
|
+
{ :name => "an Entity Sub Type with independent identification",
|
136
|
+
:definition => %q{
|
137
|
+
class V < String
|
138
|
+
value_type
|
139
|
+
end
|
140
|
+
class E
|
141
|
+
identified_by :foo
|
142
|
+
one_to_one :foo, :class => V
|
143
|
+
end
|
144
|
+
class T < E
|
145
|
+
identified_by :bar
|
146
|
+
one_to_one :bar, :class => V
|
147
|
+
end
|
148
|
+
},
|
149
|
+
:pattern => /Method: Class(#[a-z_0-9]*[?=]? )?\((defined in )?ActiveFacts::API::Entity::ClassMethods[) ]/,
|
150
|
+
:class_methods => EntityType_methods,
|
151
|
+
:instance_methods => Entity_methods,
|
152
|
+
:constructor_args => [ 'bar', {:foo => 'foo'} ]
|
153
|
+
},
|
154
|
+
|
155
|
+
{ :name => "an Entity Sub Type with extra supertypes",
|
156
|
+
:definition => %q{
|
157
|
+
class V < String
|
158
|
+
value_type
|
159
|
+
end
|
160
|
+
class E
|
161
|
+
identified_by :foo
|
162
|
+
one_to_one :foo, :class => V
|
163
|
+
end
|
164
|
+
class E2
|
165
|
+
identified_by :baz
|
166
|
+
one_to_one :baz, :class => V
|
167
|
+
end
|
168
|
+
class T < E
|
169
|
+
supertypes E2
|
170
|
+
one_to_one :bar, :class => V
|
171
|
+
end
|
172
|
+
},
|
173
|
+
:pattern => /Method: Class(#[a-z_0-9]*[?=]? )?\((defined in )?ActiveFacts::API::Entity::ClassMethods[) ]/,
|
174
|
+
:class_methods => EntityType_methods,
|
175
|
+
:instance_methods => Entity_methods,
|
176
|
+
:constructor_args => [ 'bar', {:foo => 'foo', :baz => 'baz'} ]
|
177
|
+
},
|
178
|
+
|
179
|
+
]
|
180
|
+
|
181
|
+
Cases.each do |casehash|
|
182
|
+
case_name = casehash[:name]
|
183
|
+
definition = "module Mod; "+ casehash[:definition] + "; end"
|
184
|
+
pattern = casehash[:pattern]
|
185
|
+
class_methods = casehash[:class_methods]
|
186
|
+
instance_methods = casehash[:instance_methods]
|
187
|
+
constructor_args = casehash[:constructor_args]
|
188
|
+
|
189
|
+
describe "#{case_name}" do
|
190
|
+
before :each do
|
191
|
+
eval definition
|
192
|
+
all_T_methods = Mod::T.methods.select{|m| Mod::T.method(m).inspect =~ /ActiveFacts/}.map(&:to_s).sort
|
193
|
+
@object_type_methods, @value_type_methods =
|
194
|
+
*all_T_methods.partition do |m|
|
195
|
+
Mod::T.method(m).inspect =~ /Method: Class(#[a-z_0-9]*[?=]? )?\((defined in )?ActiveFacts::API::ObjectType[) ]/
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "as an ObjectType" do
|
200
|
+
it "should have the appropriate class methods" do
|
201
|
+
@object_type_methods.should == ObjectType_methods.map(&:to_s).sort
|
202
|
+
end
|
203
|
+
|
204
|
+
ObjectType_methods.each do |m|
|
205
|
+
it "should respond to ObjectType.#{m}" do
|
206
|
+
Mod::T.should respond_to(m)
|
207
|
+
Mod::T.method(m).inspect.should =~ /Method: Class(#[a-z_0-9]*[?=]? )?\((defined in )?ActiveFacts::API::ObjectType[) ]/
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "as #{case_name}" do
|
213
|
+
it "should have the appropriate class methods" do
|
214
|
+
@value_type_methods.should == class_methods.map(&:to_s).sort
|
215
|
+
end
|
216
|
+
|
217
|
+
class_methods.each do |m|
|
218
|
+
it "should respond to #{case_name}.#{m}" do
|
219
|
+
Mod::T.should respond_to(m)
|
220
|
+
Mod::T.method(m).inspect.should =~ pattern
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
describe "when instantiated" do
|
226
|
+
before :each do
|
227
|
+
@instance = @constellation.T(*constructor_args)
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should be ok" do
|
231
|
+
@instance.should_not be_nil
|
232
|
+
end
|
233
|
+
|
234
|
+
if @instance
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
describe "An instance of #{case_name}" do
|
239
|
+
before :each do
|
240
|
+
@v = @constellation.T(*constructor_args)
|
241
|
+
all_T_instance_methods = @v.methods.select do |m|
|
242
|
+
i = @v.method(m).inspect
|
243
|
+
i =~ /ActiveFacts/ || i =~ /identifying_role_values/
|
244
|
+
end.sort.map(&:to_sym)
|
245
|
+
@actual_instance_methods = all_T_instance_methods
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should have the appropriate instance methods" do
|
249
|
+
# @actual_instance_methods.should == instance_methods.map(&:to_s).sort
|
250
|
+
# Weaken our expectation to just that nothing should be missing (extra methods are ok)
|
251
|
+
missing_methods = instance_methods - @actual_instance_methods
|
252
|
+
missing_methods.should == []
|
253
|
+
end
|
254
|
+
|
255
|
+
instance_methods.each do |m|
|
256
|
+
it "should respond to #{case_name}\##{m}" do
|
257
|
+
v = @constellation.T(*constructor_args)
|
258
|
+
v.should respond_to(m)
|
259
|
+
if Instance_methods.include?(m)
|
260
|
+
v.method(m).inspect.should =~ /Mod::T(#[a-z_0-9]*[?=]? )?\((defined in )?ActiveFacts::API::Instance[) ]/
|
261
|
+
else
|
262
|
+
v.method(m).inspect.should =~ /Mod::T(#[a-z_0-9]*[?=]? )?\((defined in )?ActiveFacts::API::(Value|Entity)[) ]/
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
@@ -22,9 +22,8 @@ module TestMultiPartIdentifierModule
|
|
22
22
|
end
|
23
23
|
|
24
24
|
describe "Multi-part identifiers" do
|
25
|
-
include ActiveFacts::API
|
26
25
|
before :each do
|
27
|
-
@c = Constellation.new(TestMultiPartIdentifierModule)
|
26
|
+
@c = ActiveFacts::API::Constellation.new(TestMultiPartIdentifierModule)
|
28
27
|
@p = @c.Parent(:new)
|
29
28
|
@c0 = @c.Child(@p, 0)
|
30
29
|
@c2 = @c.Child(@p, 2)
|
@@ -24,8 +24,8 @@ describe "AutoCounter Value Type instances" do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
@constellation = ActiveFacts::API::Constellation.new(Mod)
|
27
|
-
@thing =
|
28
|
-
@thing_id =
|
27
|
+
@thing = @constellation.Thing(:new)
|
28
|
+
@thing_id = @constellation.ThingId(:new)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should respond to verbalise" do
|
@@ -61,8 +61,8 @@ describe "AutoCounter Value Type instances" do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should allow an existing counter to be re-used" do
|
64
|
-
@new_thing =
|
65
|
-
@new_thing.thing_id.should == @thing_id
|
64
|
+
@new_thing = @constellation.Thing(@thing_id)
|
65
|
+
@new_thing.thing_id.to_s.should == @thing_id.to_s
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should return the ValueType in response to .class()" do
|
@@ -24,8 +24,8 @@ describe "Guid Value Type instances" do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
@constellation = ActiveFacts::API::Constellation.new(Mod)
|
27
|
-
@thing =
|
28
|
-
@thing_id =
|
27
|
+
@thing = @constellation.Thing(:new)
|
28
|
+
@thing_id = @constellation.ThingId(:new)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should respond to verbalise" do
|
@@ -51,7 +51,7 @@ describe "Guid Value Type instances" do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should allow an existing guid to be re-used" do
|
54
|
-
@new_thing =
|
54
|
+
@new_thing = @constellation.Thing(@thing_id)
|
55
55
|
@new_thing.thing_id.should == @thing_id
|
56
56
|
end
|
57
57
|
|
@@ -105,7 +105,8 @@ describe "Value Type class definitions" do
|
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should allow configuration of Role value through constructor using role name" do
|
108
|
-
|
108
|
+
c = ActiveFacts::API::Constellation.new(Mod)
|
109
|
+
w = c.Weight(9.0, :name => "pounds")
|
109
110
|
w.name.should == "pounds"
|
110
111
|
end
|
111
112
|
end
|
data/spec/simplecov_helper.rb
CHANGED
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.9.
|
4
|
+
version: 0.9.4
|
5
5
|
prerelease:
|
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:
|
12
|
+
date: 2013-01-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -205,6 +205,7 @@ files:
|
|
205
205
|
- activefacts-api.gemspec
|
206
206
|
- lib/activefacts/api.rb
|
207
207
|
- lib/activefacts/api/constellation.rb
|
208
|
+
- lib/activefacts/api/date.rb
|
208
209
|
- lib/activefacts/api/entity.rb
|
209
210
|
- lib/activefacts/api/exceptions.rb
|
210
211
|
- lib/activefacts/api/guid.rb
|
@@ -228,6 +229,7 @@ files:
|
|
228
229
|
- spec/identification_scheme/identification_spec.rb
|
229
230
|
- spec/identification_scheme/identity_change_spec.rb
|
230
231
|
- spec/identification_scheme/identity_supertype_change_spec.rb
|
232
|
+
- spec/metadata_spec.rb
|
231
233
|
- spec/object_type/entity_type/entity_type_spec.rb
|
232
234
|
- spec/object_type/entity_type/multipart_identification_spec.rb
|
233
235
|
- spec/object_type/value_type/autocounter_spec.rb
|
@@ -253,7 +255,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
253
255
|
version: '0'
|
254
256
|
segments:
|
255
257
|
- 0
|
256
|
-
hash:
|
258
|
+
hash: -4472389217963530963
|
257
259
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
258
260
|
none: false
|
259
261
|
requirements:
|