collector 0.0.4 → 0.0.5

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/README.md CHANGED
@@ -22,7 +22,11 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ ### Configure a connection
26
+
27
+ ```ruby
28
+ Collector.connection = Mongo::Connection.new
29
+ ```
26
30
 
27
31
  ## Contributing
28
32
 
data/lib/collector.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "collector/version"
2
2
 
3
3
  require "collector/model"
4
+ require "collector/repository"
4
5
 
5
6
  module Collector
6
7
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Collector
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -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
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