rom-mongo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: baf2523814478bc55ff949ed66bf4a9afae3c4a6
4
- data.tar.gz: d787e542f6073fe992aafd9f9ef84c0418e1f3cf
3
+ metadata.gz: 8e69abd7cd3bef9b652297a3c97241b9ad3d2c6b
4
+ data.tar.gz: 6fd82e39ddece041401708ab9f57a0c72aecc8ae
5
5
  SHA512:
6
- metadata.gz: cc31577a39e38fc80a7d83a281628d5d715a5083b57510d85628d167403b64ca088e5e003a585680b98ca8391df55246a71cd2b573bb74981dabac0b84c0542f
7
- data.tar.gz: 7283bbc8d7ff0d01f3e0609e773645d166331efbd899e61268fc8acac52c7404c72e50129fca17a86e09c205dd1a6714e5a034031fee71793ad30da0ad827391
6
+ metadata.gz: b2b72325a9b94dcb9e5701d1a9d70b8a3cfc341f364b5ecb02185ff5d715dad8247d5443276a7ad0e7ff235f464f88779553b0e6cfde1276584885e49d0e37f3
7
+ data.tar.gz: b00bbd5a154c383e871a4ff58ae83c491ab3bc15a7a12c115c4ce87768f84245e16c63b0883ad758db97de564314a3fa7fbe766b8a05c33b9cd25260ddc746fc
@@ -4,8 +4,8 @@ env:
4
4
  - CODECLIMATE_REPO_TOKEN=886f3b795e74159719804f8e18b853f4c23a81bd814404e52ec248a0dae6d656
5
5
  script: "bundle exec rake spec"
6
6
  rvm:
7
- - 2.0.0
8
- - 2.1.2
7
+ - 2.0
8
+ - 2.1
9
9
  - rbx-2
10
10
  - jruby
11
11
  - ruby-head
@@ -1,3 +1,11 @@
1
+ ## v0.0.2 2014-12-06
2
+
3
+ ### Added
4
+
5
+ * Command API (solnic)
6
+
7
+ [Compare v0.0.1...v0.0.2](https://github.com/rom-rb/rom-sql/compare/v0.0.1...v0.0.2)
8
+
1
9
  ## v0.0.1 2014-11-25
2
10
 
3
11
  First public release
@@ -1,5 +1,7 @@
1
- require "moped"
1
+ require 'moped'
2
2
 
3
- require "rom"
4
- require "rom/mongo/version"
5
- require "rom/mongo/adapter"
3
+ require 'rom'
4
+ require 'rom/mongo/version'
5
+ require 'rom/mongo/adapter'
6
+
7
+ require 'rom/mongo/commands'
@@ -2,7 +2,6 @@ module ROM
2
2
  module Mongo
3
3
 
4
4
  class Adapter < ROM::Adapter
5
- attr_reader :connection
6
5
 
7
6
  def self.schemes
8
7
  [:mongo]
@@ -10,6 +9,10 @@ module ROM
10
9
 
11
10
  class Dataset
12
11
  include Charlatan.new(:collection, kind: Moped::Query)
12
+
13
+ def each(&block)
14
+ collection.find.each(&block)
15
+ end
13
16
  end
14
17
 
15
18
  def initialize(*args)
@@ -22,8 +25,12 @@ module ROM
22
25
  Dataset.new(connection[name])
23
26
  end
24
27
 
25
- def schema
26
- []
28
+ def dataset?(name)
29
+ connection.collection_names.include?(name.to_s)
30
+ end
31
+
32
+ def command_namespace
33
+ Mongo::Commands
27
34
  end
28
35
 
29
36
  ROM::Adapter.register(self)
@@ -0,0 +1,41 @@
1
+ require 'bson'
2
+
3
+ module ROM
4
+ module Mongo
5
+
6
+ module Commands
7
+
8
+ class Create < ROM::Commands::Create
9
+ alias_method :collection, :relation
10
+
11
+ def execute(document)
12
+ collection.insert(document)
13
+ [document]
14
+ end
15
+
16
+ end
17
+
18
+ class Update < ROM::Commands::Update
19
+ alias_method :set, :call
20
+ alias_method :collection, :relation
21
+
22
+ def execute(attributes)
23
+ collection.update_all('$set' => attributes)
24
+ collection.to_a
25
+ end
26
+
27
+ end
28
+
29
+ class Delete < ROM::Commands::Delete
30
+
31
+ def execute
32
+ removed = target.to_a
33
+ target.remove_all
34
+ removed
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module Mongo
3
- VERSION = "0.0.1"
3
+ VERSION = '0.0.2'.freeze
4
4
  end
5
5
  end
@@ -5,7 +5,7 @@ require 'rom/mongo/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "rom-mongo"
8
- spec.version = ROM::Mongo::VERSION
8
+ spec.version = ROM::Mongo::VERSION.dup
9
9
  spec.authors = ["Piotr Solnica"]
10
10
  spec.email = ["piotr.solnica@gmail.com"]
11
11
  spec.summary = %q{MongoDB support for Ruby Object Mapper}
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency "moped"
22
- spec.add_runtime_dependency "rom", "~> 0.3"
22
+ spec.add_runtime_dependency "rom", "~> 0.4", ">= 0.4.0"
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.7"
25
- spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "rake"
26
26
  end
@@ -3,21 +3,22 @@ require 'spec_helper'
3
3
  require 'virtus'
4
4
 
5
5
  describe 'Mongo adapter' do
6
+ subject(:rom) { setup.finalize }
7
+
6
8
  let(:setup) { ROM.setup(mongo: 'mongo://127.0.0.1:27017/test') }
7
- let(:rom) { setup.finalize }
8
9
 
9
10
  after do
10
11
  rom.mongo.connection.drop
11
12
  end
12
13
 
13
- it 'works' do
14
+ before do
14
15
  setup.schema do
15
16
  base_relation(:users) do
16
17
  repository :mongo
17
18
 
18
- attribute "_id"
19
- attribute "name"
20
- attribute "email"
19
+ attribute '_id'
20
+ attribute 'name'
21
+ attribute 'email'
21
22
  end
22
23
  end
23
24
 
@@ -27,12 +28,20 @@ describe 'Mongo adapter' do
27
28
  end
28
29
  end
29
30
 
31
+ setup.commands(:users) do
32
+ define(:create)
33
+ define(:update)
34
+ define(:delete)
35
+ end
36
+
30
37
  user_model = Class.new do
31
- include Virtus.model
38
+ include Virtus.value_object
32
39
 
33
- attribute :id, String
34
- attribute :name, String
35
- attribute :email, String
40
+ values do
41
+ attribute :id, String
42
+ attribute :name, String
43
+ attribute :email, String
44
+ end
36
45
  end
37
46
 
38
47
  setup.mappers do
@@ -44,11 +53,71 @@ describe 'Mongo adapter' do
44
53
  end
45
54
 
46
55
  rom.schema.users.insert(name: 'Jane', email: 'jane@doe.org')
56
+ rom.schema.users.insert(name: 'Joe', email: 'joe@doe.org')
57
+ end
58
+
59
+ describe 'env#read' do
60
+ it 'returns mapped object' do
61
+ jane = rom.read(:users).by_name('Jane').to_a.first
62
+
63
+ expect(jane.id).to eql(rom.schema.users.find(name: 'Jane').one['_id'].to_s)
64
+ expect(jane.name).to eql('Jane')
65
+ expect(jane.email).to eql('jane@doe.org')
66
+ end
67
+ end
68
+
69
+ describe 'adapter#dataset?' do
70
+ it 'returns true if a collection exists' do
71
+ expect(rom.mongo.adapter.dataset?(:users)).to be(true)
72
+ end
73
+
74
+ it 'returns false if a does not collection exist' do
75
+ expect(rom.mongo.adapter.dataset?(:not_here)).to be(false)
76
+ end
77
+ end
78
+
79
+ describe 'commands' do
80
+ let(:commands) { rom.command(:users) }
47
81
 
48
- jane = rom.read(:users).by_name('Jane').to_a.first
82
+ describe 'create' do
83
+ it 'inserts a document into collection' do
84
+ id = BSON::ObjectId.new
49
85
 
50
- expect(jane.id).to eql(rom.schema.users.find(name: 'Jane').one['_id'].to_s)
51
- expect(jane.name).to eql('Jane')
52
- expect(jane.email).to eql('jane@doe.org')
86
+ result = commands.try { create(_id: id, name: 'joe', email: 'joe@doe.org') }
87
+
88
+ expect(result).to match_array([{ _id: id, name: 'joe', email: 'joe@doe.org' }])
89
+ end
90
+ end
91
+
92
+ describe 'update' do
93
+ it 'updates a document in the collection' do
94
+ jane = rom.read(:users).by_name('Jane').first
95
+
96
+ result = commands.try { update(:by_name, 'Jane').set(email: 'jane.doe@test.com') }
97
+
98
+ expect(result).to match_array(
99
+ [{ '_id' => BSON::ObjectId.from_string(jane.id),
100
+ 'name' => 'Jane',
101
+ 'email' => 'jane.doe@test.com' }]
102
+ )
103
+ end
104
+ end
105
+
106
+ describe 'delete' do
107
+ it 'deletes documents from the collection' do
108
+ jane = rom.read(:users).by_name('Jane').first
109
+ joe = rom.read(:users).by_name('Joe').first
110
+
111
+ result = commands.try { delete(:by_name, 'Joe').execute }
112
+
113
+ expect(result).to match_array(
114
+ [{ '_id' => BSON::ObjectId.from_string(joe.id),
115
+ 'name' => 'Joe',
116
+ 'email' => 'joe@doe.org' }]
117
+ )
118
+
119
+ expect(rom.read(:users).to_a).to eql([jane])
120
+ end
121
+ end
53
122
  end
54
123
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom-mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-25 00:00:00.000000000 Z
11
+ date: 2014-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: moped
@@ -30,42 +30,48 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '0.3'
33
+ version: '0.4'
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: 0.4.0
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
41
  - - ~>
39
42
  - !ruby/object:Gem::Version
40
- version: '0.3'
43
+ version: '0.4'
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.4.0
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: bundler
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - ~>
51
+ - - '>='
46
52
  - !ruby/object:Gem::Version
47
- version: '1.7'
53
+ version: '0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - ~>
58
+ - - '>='
53
59
  - !ruby/object:Gem::Version
54
- version: '1.7'
60
+ version: '0'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: rake
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
- - - ~>
65
+ - - '>='
60
66
  - !ruby/object:Gem::Version
61
- version: '10.0'
67
+ version: '0'
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
- - - ~>
72
+ - - '>='
67
73
  - !ruby/object:Gem::Version
68
- version: '10.0'
74
+ version: '0'
69
75
  description: MongoDB support for Ruby Object Mapper
70
76
  email:
71
77
  - piotr.solnica@gmail.com
@@ -84,6 +90,7 @@ files:
84
90
  - lib/rom-mongo.rb
85
91
  - lib/rom/mongo.rb
86
92
  - lib/rom/mongo/adapter.rb
93
+ - lib/rom/mongo/commands.rb
87
94
  - lib/rom/mongo/version.rb
88
95
  - rom-mongo.gemspec
89
96
  - spec/integration/adapter_spec.rb
@@ -115,3 +122,4 @@ summary: MongoDB support for Ruby Object Mapper
115
122
  test_files:
116
123
  - spec/integration/adapter_spec.rb
117
124
  - spec/spec_helper.rb
125
+ has_rdoc: