gearbox 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +138 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +20 -0
- data/README.html +89 -0
- data/README.md +87 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/examples/audience.rb +24 -0
- data/lib/examples/person.rb +29 -0
- data/lib/examples/reference.rb +38 -0
- data/lib/examples/theme.rb +8 -0
- data/lib/gearbox.rb +40 -0
- data/lib/gearbox/attribute_collection.rb +42 -0
- data/lib/gearbox/mixins/ad_hoc_properties.rb +41 -0
- data/lib/gearbox/mixins/resource.rb +17 -0
- data/lib/gearbox/mixins/semantic_accessors.rb +118 -0
- data/lib/gearbox/rdf_collection.rb +72 -0
- data/lib/gearbox/type.rb +85 -0
- data/lib/gearbox/types.rb +28 -0
- data/lib/gearbox/types/any.rb +24 -0
- data/lib/gearbox/types/boolean.rb +31 -0
- data/lib/gearbox/types/date.rb +27 -0
- data/lib/gearbox/types/decimal.rb +29 -0
- data/lib/gearbox/types/float.rb +28 -0
- data/lib/gearbox/types/integer.rb +27 -0
- data/lib/gearbox/types/native.rb +22 -0
- data/lib/gearbox/types/string.rb +27 -0
- data/lib/gearbox/types/uri.rb +25 -0
- data/spec/examples/audience_spec.rb +28 -0
- data/spec/examples/person_spec.rb +45 -0
- data/spec/examples/reference_spec.rb +43 -0
- data/spec/examples/theme_spec.rb +137 -0
- data/spec/gearbox/attribute_collection_spec.rb +33 -0
- data/spec/gearbox/mixins/ad_hoc_properties_spec.rb +52 -0
- data/spec/gearbox/mixins/resource_spec.rb +32 -0
- data/spec/gearbox/mixins/semantic_accessors_spec.rb +53 -0
- data/spec/gearbox/rdf_collection_spec.rb +52 -0
- data/spec/gearbox_spec.rb +13 -0
- data/spec/spec_helper.rb +16 -0
- metadata +235 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
include Gearbox
|
4
|
+
|
5
|
+
describe AttributeCollection do
|
6
|
+
|
7
|
+
subject { AttributeCollection.new }
|
8
|
+
|
9
|
+
it "should add an attribute with a Hash and store an OpenStruct" do
|
10
|
+
subject[:key] = {:this => :works}
|
11
|
+
subject[:key].this.must_equal(:works)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "normalizes keys to symbols" do
|
15
|
+
# Note: end product is lowercase and underscored.
|
16
|
+
# Removing white space, non-alphanumeric, repeats,
|
17
|
+
# leading and trailing underscores
|
18
|
+
key = %[* Something $trange !@#$\%^&]
|
19
|
+
normalized_key = :something_trange
|
20
|
+
value = {:this => :works}
|
21
|
+
subject[key] = value
|
22
|
+
subject[normalized_key].this.must_equal :works
|
23
|
+
subject[key].this.must_equal :works
|
24
|
+
end
|
25
|
+
|
26
|
+
it "initializes with a default hash" do
|
27
|
+
subject = AttributeCollection.new :this => :works
|
28
|
+
subject[:key] = {:another => :value}
|
29
|
+
subject[:key].another.must_equal :value
|
30
|
+
subject[:key].this.must_equal :works
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
include Gearbox
|
4
|
+
|
5
|
+
describe AdHocProperties do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@class = Class.new do
|
9
|
+
def self.name; 'demo_class'; end
|
10
|
+
include SemanticAccessors
|
11
|
+
include AdHocProperties
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { @class.new }
|
16
|
+
|
17
|
+
it "has an id getter and setter" do
|
18
|
+
id = 1
|
19
|
+
subject.id = id
|
20
|
+
subject.id.must_equal(id)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Concerned about the id and the model lifecycle.
|
24
|
+
it "offers a bnode, deriving from the id" do
|
25
|
+
subject.id = 3
|
26
|
+
subject.bnode.must_be_kind_of RDF::Node
|
27
|
+
subject.bnode.id.must_equal "demo_class_3"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "generates a UUID for the bnode if the id is nil" do
|
31
|
+
subject.id.must_be_nil
|
32
|
+
subject.bnode
|
33
|
+
subject.id.wont_be_nil
|
34
|
+
subject.bnode.id.must_equal "demo_class_#{subject.id}"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has an attributes_list" do
|
38
|
+
subject.must_respond_to :attributes_list
|
39
|
+
subject.attributes_list.must_be_kind_of RDFCollection
|
40
|
+
end
|
41
|
+
|
42
|
+
# Excited about models that can take new properties ad hoc, therefore being more
|
43
|
+
# friendly to the underlying graph and the nature of semantic data generally.
|
44
|
+
it "can add_property with a predicate and an object" do
|
45
|
+
subject.add_property :field_name, :predicate, :object
|
46
|
+
newly_created = subject.attributes_list[:field_name]
|
47
|
+
newly_created.subject.id.must_equal subject.bnode.id
|
48
|
+
newly_created.predicate.id.must_equal 'predicate'
|
49
|
+
newly_created.object.id.must_equal 'object'
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
include Gearbox
|
4
|
+
|
5
|
+
describe Resource do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@class = Class.new do
|
9
|
+
def self.name; 'demo_class'; end
|
10
|
+
include Gearbox
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { @class.new }
|
15
|
+
|
16
|
+
it "uses AdHocProperties" do
|
17
|
+
Resource.included_modules.must_include Gearbox::AdHocProperties
|
18
|
+
end
|
19
|
+
|
20
|
+
it "uses SemanticAccessors" do
|
21
|
+
Resource.included_modules.must_include Gearbox::SemanticAccessors
|
22
|
+
end
|
23
|
+
|
24
|
+
it "uses RDF::Mutable" do
|
25
|
+
Resource.included_modules.must_include RDF::Mutable
|
26
|
+
end
|
27
|
+
|
28
|
+
it "uses RDF::Queryable" do
|
29
|
+
Resource.included_modules.must_include RDF::Queryable
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
include Gearbox
|
4
|
+
|
5
|
+
describe SemanticAccessors do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@class = Class.new do
|
9
|
+
def self.name; 'demo_class'; end
|
10
|
+
include SemanticAccessors
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { @class.new }
|
15
|
+
|
16
|
+
it "has an rdf_collection" do
|
17
|
+
subject.must_respond_to :rdf_collection
|
18
|
+
subject.rdf_collection.must_be_kind_of RDFCollection
|
19
|
+
end
|
20
|
+
|
21
|
+
it "has an attribute_collection on the class" do
|
22
|
+
subject.class.must_respond_to :attribute_collection
|
23
|
+
subject.class.attribute_collection.must_be_kind_of AttributeCollection
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has an attribute macro for setting up new attributes" do
|
27
|
+
@class.attribute :given_name, :predicate => RDF::FOAF.givenname
|
28
|
+
subject.given_name = "Frank"
|
29
|
+
subject.given_name.must_equal("Frank")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "raises an error unless a predicate is defined" do
|
33
|
+
lambda{@class.attribute :given_name}.must_raise(ArgumentError, /predicate/i)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "takes a hash on initialization" do
|
37
|
+
@class.attribute :given_name, :predicate => RDF::FOAF.givenname
|
38
|
+
subject = @class.new :given_name => "Frank"
|
39
|
+
subject.given_name.must_equal "Frank"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "takes an RDFCollection on initialization" do
|
43
|
+
@class.attribute :given_name, :predicate => RDF::FOAF.givenname
|
44
|
+
collection = RDFCollection.new
|
45
|
+
collection[:given_name] = RDF::Statement.new(:a, RDF::FOAF.givenname, 'Frank')
|
46
|
+
collection[:family_name] = RDF::Statement.new(:a, RDF::FOAF.familyname, 'Wilde')
|
47
|
+
subject = @class.new(collection)
|
48
|
+
subject.given_name.must_equal "Frank"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "takes an Array of RDF::Statement objects on initialization"
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
include Gearbox
|
4
|
+
|
5
|
+
describe RDFCollection do
|
6
|
+
|
7
|
+
subject { RDFCollection.new() }
|
8
|
+
|
9
|
+
it "uses RDF::Enumerable " do
|
10
|
+
RDFCollection.included_modules.must_include RDF::Enumerable
|
11
|
+
end
|
12
|
+
|
13
|
+
it "adds statements with add_statement or []=" do
|
14
|
+
statement = RDF::Statement(:a, :b, :c)
|
15
|
+
subject.add_statement :x, statement
|
16
|
+
subject[:y] = statement
|
17
|
+
|
18
|
+
subject[:x].must_equal statement
|
19
|
+
subject[:y].must_equal statement
|
20
|
+
end
|
21
|
+
|
22
|
+
it "looks up statements by []" do
|
23
|
+
statement = RDF::Statement(:a, :b, :c)
|
24
|
+
subject[:x] = statement
|
25
|
+
subject[:x].must_equal statement
|
26
|
+
end
|
27
|
+
|
28
|
+
it "normalizes keys to symbols" do
|
29
|
+
# Note: end product is lowercase and underscored.
|
30
|
+
# Removing white space, non-alphanumeric, repeats,
|
31
|
+
# leading and trailing underscores
|
32
|
+
key = %[* Something $trange !@#$\%^&]
|
33
|
+
normalized_key = :something_trange
|
34
|
+
statement = RDF::Statement(:a, :b, :c)
|
35
|
+
subject[key] = statement
|
36
|
+
subject[normalized_key].must_equal statement
|
37
|
+
end
|
38
|
+
|
39
|
+
it "uses a has_key? interface, by normalizing the key" do
|
40
|
+
key = %[* Something $trange !@#$\%^&]
|
41
|
+
subject[key] = RDF::Statement(:a, :b, :c)
|
42
|
+
subject.has_key?(key).must_equal true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "uses has_key? without normalizing the key, when asked" do
|
46
|
+
key = %[* Something $trange !@#$\%^&]
|
47
|
+
normalized_key = :something_trange
|
48
|
+
subject[key] = RDF::Statement(:a, :b, :c)
|
49
|
+
subject.has_key?(key, :normalize => false).must_equal false
|
50
|
+
subject.has_key?(normalized_key, :normalize => false).must_equal true
|
51
|
+
end
|
52
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'minitest/spec'
|
12
|
+
require 'minitest/autorun'
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
+
require 'gearbox'
|
metadata
ADDED
@@ -0,0 +1,235 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gearbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- David Richards
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-02 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: linkeddata
|
16
|
+
requirement: &2168807240 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2168807240
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &2168806240 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2168806240
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: uuid
|
38
|
+
requirement: &2168805000 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2168805000
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: autotest-fsevent
|
49
|
+
requirement: &2168803360 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2168803360
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: autotest-growl
|
60
|
+
requirement: &2168800780 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2168800780
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: &2168799800 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2168799800
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: yard
|
82
|
+
requirement: &2168798460 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.6.0
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2168798460
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: bundler
|
93
|
+
requirement: &2168797220 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *2168797220
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: jeweler
|
104
|
+
requirement: &2168795880 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.6.4
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *2168795880
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: simplecov
|
115
|
+
requirement: &2168794200 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: *2168794200
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: guard-markdown
|
126
|
+
requirement: &2168792740 !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: *2168792740
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
name: ruby-debug19
|
137
|
+
requirement: &2168791760 !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
type: :development
|
144
|
+
prerelease: false
|
145
|
+
version_requirements: *2168791760
|
146
|
+
- !ruby/object:Gem::Dependency
|
147
|
+
name: guard-minitest
|
148
|
+
requirement: &2168790840 !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
type: :development
|
155
|
+
prerelease: false
|
156
|
+
version_requirements: *2168790840
|
157
|
+
description: A SPARQL-driven modeling toolset for semantic models.
|
158
|
+
email: davidlamontrichards@gmail.com
|
159
|
+
executables: []
|
160
|
+
extensions: []
|
161
|
+
extra_rdoc_files:
|
162
|
+
- LICENSE.txt
|
163
|
+
- README.html
|
164
|
+
- README.md
|
165
|
+
files:
|
166
|
+
- .document
|
167
|
+
- Gemfile
|
168
|
+
- Gemfile.lock
|
169
|
+
- Guardfile
|
170
|
+
- LICENSE.txt
|
171
|
+
- README.html
|
172
|
+
- README.md
|
173
|
+
- Rakefile
|
174
|
+
- VERSION
|
175
|
+
- lib/examples/audience.rb
|
176
|
+
- lib/examples/person.rb
|
177
|
+
- lib/examples/reference.rb
|
178
|
+
- lib/examples/theme.rb
|
179
|
+
- lib/gearbox.rb
|
180
|
+
- lib/gearbox/attribute_collection.rb
|
181
|
+
- lib/gearbox/mixins/ad_hoc_properties.rb
|
182
|
+
- lib/gearbox/mixins/resource.rb
|
183
|
+
- lib/gearbox/mixins/semantic_accessors.rb
|
184
|
+
- lib/gearbox/rdf_collection.rb
|
185
|
+
- lib/gearbox/type.rb
|
186
|
+
- lib/gearbox/types.rb
|
187
|
+
- lib/gearbox/types/any.rb
|
188
|
+
- lib/gearbox/types/boolean.rb
|
189
|
+
- lib/gearbox/types/date.rb
|
190
|
+
- lib/gearbox/types/decimal.rb
|
191
|
+
- lib/gearbox/types/float.rb
|
192
|
+
- lib/gearbox/types/integer.rb
|
193
|
+
- lib/gearbox/types/native.rb
|
194
|
+
- lib/gearbox/types/string.rb
|
195
|
+
- lib/gearbox/types/uri.rb
|
196
|
+
- spec/examples/audience_spec.rb
|
197
|
+
- spec/examples/person_spec.rb
|
198
|
+
- spec/examples/reference_spec.rb
|
199
|
+
- spec/examples/theme_spec.rb
|
200
|
+
- spec/gearbox/attribute_collection_spec.rb
|
201
|
+
- spec/gearbox/mixins/ad_hoc_properties_spec.rb
|
202
|
+
- spec/gearbox/mixins/resource_spec.rb
|
203
|
+
- spec/gearbox/mixins/semantic_accessors_spec.rb
|
204
|
+
- spec/gearbox/rdf_collection_spec.rb
|
205
|
+
- spec/gearbox_spec.rb
|
206
|
+
- spec/spec_helper.rb
|
207
|
+
homepage: http://github.com/davidrichards/gearbox
|
208
|
+
licenses:
|
209
|
+
- MIT
|
210
|
+
post_install_message:
|
211
|
+
rdoc_options: []
|
212
|
+
require_paths:
|
213
|
+
- lib
|
214
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
215
|
+
none: false
|
216
|
+
requirements:
|
217
|
+
- - ! '>='
|
218
|
+
- !ruby/object:Gem::Version
|
219
|
+
version: '0'
|
220
|
+
segments:
|
221
|
+
- 0
|
222
|
+
hash: -317438611168027119
|
223
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
224
|
+
none: false
|
225
|
+
requirements:
|
226
|
+
- - ! '>='
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: '0'
|
229
|
+
requirements: []
|
230
|
+
rubyforge_project:
|
231
|
+
rubygems_version: 1.8.17
|
232
|
+
signing_key:
|
233
|
+
specification_version: 3
|
234
|
+
summary: Flexible semantic models.
|
235
|
+
test_files: []
|