rom-mongo 0.0.2 → 0.0.3

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: 8e69abd7cd3bef9b652297a3c97241b9ad3d2c6b
4
- data.tar.gz: 6fd82e39ddece041401708ab9f57a0c72aecc8ae
3
+ metadata.gz: fd3c391e9bab1f7f5d67b1ac3dcdaf5c0b2cc779
4
+ data.tar.gz: 5fbfefe474f557aa8974b0573f38817a49882ab9
5
5
  SHA512:
6
- metadata.gz: b2b72325a9b94dcb9e5701d1a9d70b8a3cfc341f364b5ecb02185ff5d715dad8247d5443276a7ad0e7ff235f464f88779553b0e6cfde1276584885e49d0e37f3
7
- data.tar.gz: b00bbd5a154c383e871a4ff58ae83c491ab3bc15a7a12c115c4ce87768f84245e16c63b0883ad758db97de564314a3fa7fbe766b8a05c33b9cd25260ddc746fc
6
+ metadata.gz: 080fd587154820d5b46472ff4ec995f6abb72af39736170ed3e878c7063b247a0aa00de2e99207994074cb21478c1c8d47b9e7bb8bbfa4582759355e8f016f65
7
+ data.tar.gz: 6c7600f8d3deb30b42c49b5ca04d46a083eeeff733b0356f181e08a84e34d0b4d366fd5aea1544b79ec40f8c2cc35e3261216830c73cac3b6df9f12c5232ba5f
@@ -0,0 +1,20 @@
1
+ # Documentation checked by Inch CI
2
+ Style/Documentation:
3
+ Enabled: false
4
+
5
+ # This is a shim file for those who require 'rom-mongo'
6
+ Style/FileName:
7
+ Exclude:
8
+ - lib/rom-mongo.rb
9
+
10
+ # Even a single escaped slash can be confusing
11
+ Style/RegexpLiteral:
12
+ MaxSlashes: 0
13
+
14
+ # Accept both single and double quotes
15
+ Style/StringLiterals:
16
+ Enabled: false
17
+
18
+ # %w makes more sense with 4+ elements
19
+ Style/WordArray:
20
+ MinSize: 3
@@ -1,10 +1,22 @@
1
+ ## v0.0.3 2014-12-31
2
+
3
+ ### Added
4
+
5
+ * Support for header (solnic)
6
+
7
+ ### Changed
8
+
9
+ * Updated to work with latest ROM (solnic)
10
+
11
+ [Compare v0.0.2...v0.0.3](https://github.com/rom-rb/rom-mongo/compare/v0.0.1...v0.0.3)
12
+
1
13
  ## v0.0.2 2014-12-06
2
14
 
3
15
  ### Added
4
16
 
5
17
  * Command API (solnic)
6
18
 
7
- [Compare v0.0.1...v0.0.2](https://github.com/rom-rb/rom-sql/compare/v0.0.1...v0.0.2)
19
+ [Compare v0.0.1...v0.0.2](https://github.com/rom-rb/rom-mongo/compare/v0.0.1...v0.0.2)
8
20
 
9
21
  ## v0.0.1 2014-11-25
10
22
 
data/Rakefile CHANGED
@@ -1,3 +1,10 @@
1
1
  require "rspec/core/rake_task"
2
+ require "rubocop/rake_task"
3
+
4
+ task default: [:spec, :rubocop]
2
5
 
3
6
  RSpec::Core::RakeTask.new(:spec)
7
+
8
+ RuboCop::RakeTask.new do |task|
9
+ task.options << "--display-cop-names"
10
+ end
@@ -1,28 +1,55 @@
1
1
  module ROM
2
2
  module Mongo
3
-
4
3
  class Adapter < ROM::Adapter
5
-
6
4
  def self.schemes
7
5
  [:mongo]
8
6
  end
9
7
 
8
+ module RelationInclusion
9
+ def header
10
+ dataset.header
11
+ end
12
+ end
13
+
10
14
  class Dataset
11
15
  include Charlatan.new(:collection, kind: Moped::Query)
16
+ include Equalizer.new(:collection, :header)
17
+
18
+ alias_method :query, :collection
19
+
20
+ def initialize(collection, header)
21
+ super
22
+ @header = header unless query?
23
+ end
24
+
25
+ def header
26
+ query? ? query.operation.fields : @header
27
+ end
12
28
 
13
29
  def each(&block)
14
30
  collection.find.each(&block)
15
31
  end
32
+
33
+ def query?
34
+ collection.is_a?(Moped::Query)
35
+ end
16
36
  end
17
37
 
38
+ attr_reader :collections
39
+
18
40
  def initialize(*args)
19
41
  super
20
42
  @connection = Moped::Session.new(["#{uri.host}:#{uri.port}"])
21
43
  @connection.use uri.path.gsub('/', '')
44
+ @collections = {}
22
45
  end
23
46
 
24
47
  def [](name)
25
- Dataset.new(connection[name])
48
+ collections.fetch(name)
49
+ end
50
+
51
+ def dataset(name, header)
52
+ collections[name] = Dataset.new(connection[name], header)
26
53
  end
27
54
 
28
55
  def dataset?(name)
@@ -33,8 +60,9 @@ module ROM
33
60
  Mongo::Commands
34
61
  end
35
62
 
36
- ROM::Adapter.register(self)
63
+ def extend_relation_class(klass)
64
+ klass.send(:include, RelationInclusion)
65
+ end
37
66
  end
38
-
39
67
  end
40
68
  end
@@ -2,9 +2,7 @@ require 'bson'
2
2
 
3
3
  module ROM
4
4
  module Mongo
5
-
6
5
  module Commands
7
-
8
6
  class Create < ROM::Commands::Create
9
7
  alias_method :collection, :relation
10
8
 
@@ -12,7 +10,6 @@ module ROM
12
10
  collection.insert(document)
13
11
  [document]
14
12
  end
15
-
16
13
  end
17
14
 
18
15
  class Update < ROM::Commands::Update
@@ -23,19 +20,15 @@ module ROM
23
20
  collection.update_all('$set' => attributes)
24
21
  collection.to_a
25
22
  end
26
-
27
23
  end
28
24
 
29
25
  class Delete < ROM::Commands::Delete
30
-
31
26
  def execute
32
27
  removed = target.to_a
33
28
  target.remove_all
34
29
  removed
35
30
  end
36
-
37
31
  end
38
-
39
32
  end
40
33
  end
41
34
  end
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module Mongo
3
- VERSION = '0.0.2'.freeze
3
+ VERSION = '0.0.3'.freeze
4
4
  end
5
5
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = ROM::Mongo::VERSION.dup
9
9
  spec.authors = ["Piotr Solnica"]
10
10
  spec.email = ["piotr.solnica@gmail.com"]
11
- spec.summary = %q{MongoDB support for Ruby Object Mapper}
11
+ spec.summary = 'MongoDB support for Ruby Object Mapper'
12
12
  spec.description = spec.summary
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
@@ -19,8 +19,9 @@ 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.4", ">= 0.4.0"
22
+ spec.add_runtime_dependency "rom", "~> 0.5", ">= 0.5.0"
23
23
 
24
24
  spec.add_development_dependency "bundler"
25
25
  spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rubocop", "~> 0.28.0"
26
27
  end
@@ -26,6 +26,10 @@ describe 'Mongo adapter' do
26
26
  def by_name(name)
27
27
  find(name: name)
28
28
  end
29
+
30
+ def all
31
+ find
32
+ end
29
33
  end
30
34
 
31
35
  setup.commands(:users) do
@@ -60,7 +64,8 @@ describe 'Mongo adapter' do
60
64
  it 'returns mapped object' do
61
65
  jane = rom.read(:users).by_name('Jane').to_a.first
62
66
 
63
- expect(jane.id).to eql(rom.schema.users.find(name: 'Jane').one['_id'].to_s)
67
+ expect(jane.id)
68
+ .to eql(rom.schema.users.find(name: 'Jane').one['_id'].to_s)
64
69
  expect(jane.name).to eql('Jane')
65
70
  expect(jane.email).to eql('jane@doe.org')
66
71
  end
@@ -76,6 +81,16 @@ describe 'Mongo adapter' do
76
81
  end
77
82
  end
78
83
 
84
+ describe 'dataset#header' do
85
+ it 'returns the header defined in the schema' do
86
+ expect(rom.relations.users.header).to eql(['_id', 'name', 'email'])
87
+
88
+ users = rom.relations.users.find('name' => 'Jane').select(['email'])
89
+
90
+ expect(users.header).to eql(['email'])
91
+ end
92
+ end
93
+
79
94
  describe 'commands' do
80
95
  let(:commands) { rom.command(:users) }
81
96
 
@@ -83,9 +98,12 @@ describe 'Mongo adapter' do
83
98
  it 'inserts a document into collection' do
84
99
  id = BSON::ObjectId.new
85
100
 
86
- result = commands.try { create(_id: id, name: 'joe', email: 'joe@doe.org') }
101
+ result = commands.try do
102
+ create(_id: id, name: 'joe', email: 'joe@doe.org')
103
+ end
87
104
 
88
- expect(result).to match_array([{ _id: id, name: 'joe', email: 'joe@doe.org' }])
105
+ expect(result)
106
+ .to match_array([{ _id: id, name: 'joe', email: 'joe@doe.org' }])
89
107
  end
90
108
  end
91
109
 
@@ -93,7 +111,9 @@ describe 'Mongo adapter' do
93
111
  it 'updates a document in the collection' do
94
112
  jane = rom.read(:users).by_name('Jane').first
95
113
 
96
- result = commands.try { update(:by_name, 'Jane').set(email: 'jane.doe@test.com') }
114
+ result = commands.try do
115
+ update(:by_name, 'Jane').set(email: 'jane.doe@test.com')
116
+ end
97
117
 
98
118
  expect(result).to match_array(
99
119
  [{ '_id' => BSON::ObjectId.from_string(jane.id),
@@ -108,7 +128,7 @@ describe 'Mongo adapter' do
108
128
  jane = rom.read(:users).by_name('Jane').first
109
129
  joe = rom.read(:users).by_name('Joe').first
110
130
 
111
- result = commands.try { delete(:by_name, 'Joe').execute }
131
+ result = commands.try { delete(:by_name, 'Joe') }
112
132
 
113
133
  expect(result).to match_array(
114
134
  [{ '_id' => BSON::ObjectId.from_string(joe.id),
@@ -116,7 +136,7 @@ describe 'Mongo adapter' do
116
136
  'email' => 'joe@doe.org' }]
117
137
  )
118
138
 
119
- expect(rom.read(:users).to_a).to eql([jane])
139
+ expect(rom.read(:users).all).to match_array([jane])
120
140
  end
121
141
  end
122
142
  end
metadata CHANGED
@@ -1,77 +1,91 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom-mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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-12-06 00:00:00.000000000 Z
11
+ date: 2014-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: moped
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rom
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.4'
34
- - - '>='
33
+ version: '0.5'
34
+ - - ">="
35
35
  - !ruby/object:Gem::Version
36
- version: 0.4.0
36
+ version: 0.5.0
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - ~>
41
+ - - "~>"
42
42
  - !ruby/object:Gem::Version
43
- version: '0.4'
44
- - - '>='
43
+ version: '0.5'
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 0.4.0
46
+ version: 0.5.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - '>='
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - '>='
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rake
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - '>='
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - '>='
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rubocop
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.28.0
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.28.0
75
89
  description: MongoDB support for Ruby Object Mapper
76
90
  email:
77
91
  - piotr.solnica@gmail.com
@@ -79,9 +93,10 @@ executables: []
79
93
  extensions: []
80
94
  extra_rdoc_files: []
81
95
  files:
82
- - .gitignore
83
- - .rspec
84
- - .travis.yml
96
+ - ".gitignore"
97
+ - ".rspec"
98
+ - ".rubocop.yml"
99
+ - ".travis.yml"
85
100
  - CHANGELOG.md
86
101
  - Gemfile
87
102
  - LICENSE.txt
@@ -105,21 +120,20 @@ require_paths:
105
120
  - lib
106
121
  required_ruby_version: !ruby/object:Gem::Requirement
107
122
  requirements:
108
- - - '>='
123
+ - - ">="
109
124
  - !ruby/object:Gem::Version
110
125
  version: '0'
111
126
  required_rubygems_version: !ruby/object:Gem::Requirement
112
127
  requirements:
113
- - - '>='
128
+ - - ">="
114
129
  - !ruby/object:Gem::Version
115
130
  version: '0'
116
131
  requirements: []
117
132
  rubyforge_project:
118
- rubygems_version: 2.0.14
133
+ rubygems_version: 2.4.5
119
134
  signing_key:
120
135
  specification_version: 4
121
136
  summary: MongoDB support for Ruby Object Mapper
122
137
  test_files:
123
138
  - spec/integration/adapter_spec.rb
124
139
  - spec/spec_helper.rb
125
- has_rdoc: