collector 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -1
- data/lib/collector.rb +1 -0
- data/lib/collector/repository.rb +27 -0
- data/lib/collector/version.rb +1 -1
- data/test/collector/repository_spec.rb +32 -0
- metadata +4 -1
data/README.md
CHANGED
data/lib/collector.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "active_support/inflector"
|
2
|
+
|
3
|
+
module Collector
|
4
|
+
module Repository
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
def collection
|
13
|
+
Collector.connection[collection_name]
|
14
|
+
end
|
15
|
+
|
16
|
+
def collection_name
|
17
|
+
ActiveSupport::Inflector.tableize(model)
|
18
|
+
end
|
19
|
+
|
20
|
+
def model
|
21
|
+
name.to_s.gsub("Repository", "").constantize
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/collector/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path("../../test_helper.rb", __FILE__)
|
2
|
+
|
3
|
+
describe Collector::Repository do
|
4
|
+
|
5
|
+
before do
|
6
|
+
Object.send(:remove_const, :TestRepository) if Object.const_defined?(:TestRepository)
|
7
|
+
class TestRepository
|
8
|
+
include Collector::Repository
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has a model derived from its class name" do
|
13
|
+
TestRepository.model.name.must_equal "Test"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has a collection_name derived from its model" do
|
17
|
+
TestRepository.collection_name.must_equal "tests"
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#collection" do
|
21
|
+
describe "when a connection is set" do
|
22
|
+
it "returns the mongo collection" do
|
23
|
+
collection = mock()
|
24
|
+
connection = mock { stubs(:[]).with("tests").returns(collection) }
|
25
|
+
Collector.stubs(:connection).returns(connection)
|
26
|
+
|
27
|
+
TestRepository.collection.must_equal collection
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: collector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -42,8 +42,10 @@ files:
|
|
42
42
|
- collector.gemspec
|
43
43
|
- lib/collector.rb
|
44
44
|
- lib/collector/model.rb
|
45
|
+
- lib/collector/repository.rb
|
45
46
|
- lib/collector/version.rb
|
46
47
|
- test/collector/model_spec.rb
|
48
|
+
- test/collector/repository_spec.rb
|
47
49
|
- test/collector_spec.rb
|
48
50
|
- test/test_helper.rb
|
49
51
|
homepage: ''
|
@@ -72,5 +74,6 @@ specification_version: 3
|
|
72
74
|
summary: An implementation of the Repository Pattern for MongoDB
|
73
75
|
test_files:
|
74
76
|
- test/collector/model_spec.rb
|
77
|
+
- test/collector/repository_spec.rb
|
75
78
|
- test/collector_spec.rb
|
76
79
|
- test/test_helper.rb
|