mordor 0.1.0 → 0.1.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.
- data/Gemfile.lock +49 -0
- data/lib/mordor.rb +1 -0
- data/lib/mordor/collection.rb +11 -0
- data/lib/mordor/resource.rb +4 -0
- data/mordor.gemspec +4 -2
- data/spec/mordor/collection_spec.rb +38 -0
- data/spec/mordor/resource_spec.rb +15 -0
- metadata +40 -10
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mordor (0.1.0)
|
5
|
+
bson_ext
|
6
|
+
extlib
|
7
|
+
json
|
8
|
+
mongo
|
9
|
+
|
10
|
+
GEM
|
11
|
+
specs:
|
12
|
+
bson (1.4.0)
|
13
|
+
bson_ext (1.4.0)
|
14
|
+
columnize (0.3.4)
|
15
|
+
diff-lcs (1.1.3)
|
16
|
+
extlib (0.9.15)
|
17
|
+
json (1.6.1)
|
18
|
+
linecache (0.46)
|
19
|
+
rbx-require-relative (> 0.0.4)
|
20
|
+
mongo (1.4.0)
|
21
|
+
bson (= 1.4.0)
|
22
|
+
rake (0.9.2.2)
|
23
|
+
rbx-require-relative (0.0.5)
|
24
|
+
rspec (2.7.0)
|
25
|
+
rspec-core (~> 2.7.0)
|
26
|
+
rspec-expectations (~> 2.7.0)
|
27
|
+
rspec-mocks (~> 2.7.0)
|
28
|
+
rspec-core (2.7.1)
|
29
|
+
rspec-expectations (2.7.0)
|
30
|
+
diff-lcs (~> 1.1.2)
|
31
|
+
rspec-mocks (2.7.0)
|
32
|
+
ruby-debug (0.10.4)
|
33
|
+
columnize (>= 0.1)
|
34
|
+
ruby-debug-base (~> 0.10.4.0)
|
35
|
+
ruby-debug-base (0.10.4)
|
36
|
+
linecache (>= 0.3)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
bson_ext
|
43
|
+
extlib
|
44
|
+
json
|
45
|
+
mongo
|
46
|
+
mordor!
|
47
|
+
rake
|
48
|
+
rspec (~> 2.0)
|
49
|
+
ruby-debug
|
data/lib/mordor.rb
CHANGED
data/lib/mordor/collection.rb
CHANGED
@@ -34,5 +34,16 @@ module Mordor
|
|
34
34
|
super
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
def to_json
|
39
|
+
collection_name = @klass.collection_name.to_sym
|
40
|
+
res = {
|
41
|
+
collection_name => []
|
42
|
+
}
|
43
|
+
each do |elem|
|
44
|
+
res[collection_name] << elem.to_hash
|
45
|
+
end
|
46
|
+
res.to_json
|
47
|
+
end
|
37
48
|
end
|
38
49
|
end
|
data/lib/mordor/resource.rb
CHANGED
data/mordor.gemspec
CHANGED
@@ -2,7 +2,7 @@ Gem::Specification.new do |s|
|
|
2
2
|
s.name = "mordor"
|
3
3
|
|
4
4
|
# Do not set the version and date field manually, this is done by the release script
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
s.date = "2011-11-08"
|
7
7
|
|
8
8
|
s.summary = "mordor"
|
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.add_development_dependency('rake')
|
14
14
|
s.add_development_dependency('ruby-debug')
|
15
15
|
s.add_development_dependency('rspec', '~> 2.0')
|
16
|
+
s.add_development_dependency('json')
|
16
17
|
|
17
18
|
s.add_development_dependency('extlib')
|
18
19
|
s.add_development_dependency('mongo')
|
@@ -21,6 +22,7 @@ Gem::Specification.new do |s|
|
|
21
22
|
s.add_runtime_dependency('extlib')
|
22
23
|
s.add_runtime_dependency('mongo')
|
23
24
|
s.add_runtime_dependency('bson_ext')
|
25
|
+
s.add_runtime_dependency('json')
|
24
26
|
|
25
27
|
s.authors = ['Jan-Willem Koelewijn', 'Dirkjan Bussink']
|
26
28
|
s.email = ['janwillem.koelewijn@nedap.com', 'dirkjan.bussink@nedap.com']
|
@@ -28,6 +30,6 @@ Gem::Specification.new do |s|
|
|
28
30
|
|
29
31
|
# The files and test_files directives are set automatically by the release script.
|
30
32
|
# Do not change them by hand, but make sure to add the files to the git repository.
|
31
|
-
s.files = %w(.gitignore Gemfile README Rakefile lib/mordor.rb lib/mordor/collection.rb lib/mordor/resource.rb lib/mordor/version.rb mordor.gemspec spec/mordor/connection_spec.rb spec/mordor/resource_spec.rb spec/spec.opts spec/spec_helper.rb tasks/github-gem.rake)
|
33
|
+
s.files = %w(.gitignore Gemfile Gemfile.lock README Rakefile lib/mordor.rb lib/mordor/collection.rb lib/mordor/resource.rb lib/mordor/version.rb mordor.gemspec spec/mordor/collection_spec.rb spec/mordor/connection_spec.rb spec/mordor/resource_spec.rb spec/spec.opts spec/spec_helper.rb tasks/github-gem.rake)
|
32
34
|
end
|
33
35
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '/spec_helper.rb')
|
2
|
+
|
3
|
+
describe "with respect to collections" do
|
4
|
+
class TestResource
|
5
|
+
include Mordor::Resource
|
6
|
+
|
7
|
+
attribute :first
|
8
|
+
attribute :second
|
9
|
+
attribute :third, :finder_method => :find_by_third_attribute
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "serialization" do
|
13
|
+
before :all do
|
14
|
+
clean_sheet
|
15
|
+
|
16
|
+
5.times do |index|
|
17
|
+
res = TestResource.new(:first => "#{index}_first", :second => "#{index}_second", :third => "#{index}_third")
|
18
|
+
res.save.should be_true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should correctly serialize a collection" do
|
23
|
+
collection = TestResource.all
|
24
|
+
collection.size.should == 5
|
25
|
+
|
26
|
+
json_collection = collection.to_json
|
27
|
+
json_collection.should_not be_nil
|
28
|
+
|
29
|
+
json_collection = JSON.parse(json_collection)
|
30
|
+
|
31
|
+
collection_name = TestResource.collection_name.to_sym.to_s
|
32
|
+
json_collection.keys.should include collection_name
|
33
|
+
json_collection[collection_name].should_not be_nil
|
34
|
+
json_collection[collection_name].should be_a Array
|
35
|
+
json_collection[collection_name].size.should == 5
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -113,6 +113,21 @@ describe "with respect to resources" do
|
|
113
113
|
res.first.should == resource.first
|
114
114
|
res.second.should == resource.second
|
115
115
|
end
|
116
|
+
|
117
|
+
it "should be possible to retrieve all resources" do
|
118
|
+
TestResource.all.should_not be_nil
|
119
|
+
TestResource.all.size.should == 0
|
120
|
+
|
121
|
+
resource = TestResource.new({:first => "first", :second => "second"})
|
122
|
+
resource.save.should be_true
|
123
|
+
|
124
|
+
resource2 = TestResource.new({:first => "first", :second => "second"})
|
125
|
+
resource2.save.should be_true
|
126
|
+
|
127
|
+
collection = TestResource.all
|
128
|
+
collection.should_not be_nil
|
129
|
+
collection.size.should == 2
|
130
|
+
end
|
116
131
|
end
|
117
132
|
|
118
133
|
context "with respect to collections" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mordor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jan-Willem Koelewijn
|
@@ -63,7 +63,7 @@ dependencies:
|
|
63
63
|
type: :development
|
64
64
|
version_requirements: *id003
|
65
65
|
- !ruby/object:Gem::Dependency
|
66
|
-
name:
|
66
|
+
name: json
|
67
67
|
prerelease: false
|
68
68
|
requirement: &id004 !ruby/object:Gem::Requirement
|
69
69
|
none: false
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
type: :development
|
78
78
|
version_requirements: *id004
|
79
79
|
- !ruby/object:Gem::Dependency
|
80
|
-
name:
|
80
|
+
name: extlib
|
81
81
|
prerelease: false
|
82
82
|
requirement: &id005 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
@@ -91,7 +91,7 @@ dependencies:
|
|
91
91
|
type: :development
|
92
92
|
version_requirements: *id005
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
|
-
name:
|
94
|
+
name: mongo
|
95
95
|
prerelease: false
|
96
96
|
requirement: &id006 !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
@@ -105,7 +105,7 @@ dependencies:
|
|
105
105
|
type: :development
|
106
106
|
version_requirements: *id006
|
107
107
|
- !ruby/object:Gem::Dependency
|
108
|
-
name:
|
108
|
+
name: bson_ext
|
109
109
|
prerelease: false
|
110
110
|
requirement: &id007 !ruby/object:Gem::Requirement
|
111
111
|
none: false
|
@@ -116,10 +116,10 @@ dependencies:
|
|
116
116
|
segments:
|
117
117
|
- 0
|
118
118
|
version: "0"
|
119
|
-
type: :
|
119
|
+
type: :development
|
120
120
|
version_requirements: *id007
|
121
121
|
- !ruby/object:Gem::Dependency
|
122
|
-
name:
|
122
|
+
name: extlib
|
123
123
|
prerelease: false
|
124
124
|
requirement: &id008 !ruby/object:Gem::Requirement
|
125
125
|
none: false
|
@@ -133,7 +133,7 @@ dependencies:
|
|
133
133
|
type: :runtime
|
134
134
|
version_requirements: *id008
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
|
-
name:
|
136
|
+
name: mongo
|
137
137
|
prerelease: false
|
138
138
|
requirement: &id009 !ruby/object:Gem::Requirement
|
139
139
|
none: false
|
@@ -146,6 +146,34 @@ dependencies:
|
|
146
146
|
version: "0"
|
147
147
|
type: :runtime
|
148
148
|
version_requirements: *id009
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
name: bson_ext
|
151
|
+
prerelease: false
|
152
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
hash: 3
|
158
|
+
segments:
|
159
|
+
- 0
|
160
|
+
version: "0"
|
161
|
+
type: :runtime
|
162
|
+
version_requirements: *id010
|
163
|
+
- !ruby/object:Gem::Dependency
|
164
|
+
name: json
|
165
|
+
prerelease: false
|
166
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
167
|
+
none: false
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
hash: 3
|
172
|
+
segments:
|
173
|
+
- 0
|
174
|
+
version: "0"
|
175
|
+
type: :runtime
|
176
|
+
version_requirements: *id011
|
149
177
|
description: " Small gem to add MongoDB Resources, resources have attributes that translate into document fields. When an attribute is declared, finders for the attribute are added to the Resource automatically\n"
|
150
178
|
email:
|
151
179
|
- janwillem.koelewijn@nedap.com
|
@@ -159,6 +187,7 @@ extra_rdoc_files: []
|
|
159
187
|
files:
|
160
188
|
- .gitignore
|
161
189
|
- Gemfile
|
190
|
+
- Gemfile.lock
|
162
191
|
- README
|
163
192
|
- Rakefile
|
164
193
|
- lib/mordor.rb
|
@@ -166,6 +195,7 @@ files:
|
|
166
195
|
- lib/mordor/resource.rb
|
167
196
|
- lib/mordor/version.rb
|
168
197
|
- mordor.gemspec
|
198
|
+
- spec/mordor/collection_spec.rb
|
169
199
|
- spec/mordor/connection_spec.rb
|
170
200
|
- spec/mordor/resource_spec.rb
|
171
201
|
- spec/spec.opts
|