rom-mongo 0.0.3 → 0.1.0

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: fd3c391e9bab1f7f5d67b1ac3dcdaf5c0b2cc779
4
- data.tar.gz: 5fbfefe474f557aa8974b0573f38817a49882ab9
3
+ metadata.gz: 8a48989a26577814779425d8ef55181ffa6f3d47
4
+ data.tar.gz: 958e7bfea5f3dcf0cf50604c82578ae5bee76313
5
5
  SHA512:
6
- metadata.gz: 080fd587154820d5b46472ff4ec995f6abb72af39736170ed3e878c7063b247a0aa00de2e99207994074cb21478c1c8d47b9e7bb8bbfa4582759355e8f016f65
7
- data.tar.gz: 6c7600f8d3deb30b42c49b5ca04d46a083eeeff733b0356f181e08a84e34d0b4d366fd5aea1544b79ec40f8c2cc35e3261216830c73cac3b6df9f12c5232ba5f
6
+ metadata.gz: 7f9020ddc8ee6d5ab39a9e9231c8493c6e6e38fc021a7009114b15209db384d1d809168384f3577bb0ee4791dbb9b14306bf448572d38e5c1fc0dc145ce37ae5
7
+ data.tar.gz: 6ca1c6acf4fa3d06f8500ccd8c1134c4da37c55d101cf9d54866fb258a7f19d15b85913cd3d1c39b26ec8ff2bfe55838ac467d1c5619917dee356b67b11c9ebd
@@ -1,20 +1,74 @@
1
+ # Generated by `rubocop --auto-gen-config`
2
+ inherit_from: .rubocop_todo.yml
3
+
4
+ # Exclude temporary files
5
+ AllCops:
6
+ Exclude:
7
+ - tmp/**/*
8
+
9
+ # It’s quite readable when we know what we are doing
10
+ Lint/AssignmentInCondition:
11
+ Enabled: false
12
+
13
+ # No need to handle LoadError in Rakefile
14
+ Lint/HandleExceptions:
15
+ Exclude:
16
+ - Rakefile
17
+
18
+ # gemspec is a special snowflake
19
+ Metrics/LineLength:
20
+ Exclude:
21
+ - rom-mongo.gemspec
22
+
23
+ # The enforced style doesn’t match Vim’s defaults
24
+ Style/AlignParameters:
25
+ Enabled: false
26
+
27
+ # UTF-8 is perfectly fine in comments
28
+ Style/AsciiComments:
29
+ Enabled: false
30
+
31
+ # Allow using braces for value-returning blocks
32
+ Style/Blocks:
33
+ Enabled: false
34
+
1
35
  # Documentation checked by Inch CI
2
36
  Style/Documentation:
3
37
  Enabled: false
4
38
 
5
- # This is a shim file for those who require 'rom-mongo'
6
- Style/FileName:
7
- Exclude:
8
- - lib/rom-mongo.rb
39
+ # Early returns have their vices
40
+ Style/GuardClause:
41
+ Enabled: false
42
+
43
+ # Need to be skipped for >-> usage
44
+ Style/Lambda:
45
+ Enabled: false
46
+
47
+ # Multiline block chains are ok
48
+ Style/MultilineBlockChain:
49
+ Enabled: false
9
50
 
10
51
  # Even a single escaped slash can be confusing
11
52
  Style/RegexpLiteral:
12
53
  MaxSlashes: 0
13
54
 
55
+ # Don’t introduce semantic fail/raise distinction
56
+ Style/SignalException:
57
+ EnforcedStyle: only_raise
58
+
59
+ # Need to be skipped for >-> usage
60
+ Style/SpaceAroundOperators:
61
+ Enabled: false
62
+
14
63
  # Accept both single and double quotes
15
64
  Style/StringLiterals:
16
65
  Enabled: false
17
66
 
18
- # %w makes more sense with 4+ elements
19
- Style/WordArray:
20
- MinSize: 3
67
+ # Allow def self.foo; @foo; end
68
+ Style/TrivialAccessors:
69
+ Enabled: false
70
+
71
+ # This is a shim file for those who require 'rom-mongo'
72
+ Style/FileName:
73
+ Exclude:
74
+ - lib/rom-mongo.rb
@@ -0,0 +1,6 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2015-01-26 22:39:39 +0100 using RuboCop version 0.28.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
@@ -1,17 +1,23 @@
1
1
  language: ruby
2
- bundler_args: --without yard guard benchmarks
2
+ sudo: false
3
+ cache: bundler
4
+ bundler_args: --without yard guard benchmarks tools
3
5
  env:
4
- - CODECLIMATE_REPO_TOKEN=886f3b795e74159719804f8e18b853f4c23a81bd814404e52ec248a0dae6d656
5
- script: "bundle exec rake spec"
6
+ global:
7
+ - JRUBY_OPTS='--dev -J-Xmx1024M'
8
+ - CODECLIMATE_REPO_TOKEN=886f3b795e74159719804f8e18b853f4c23a81bd814404e52ec248a0dae6d656
9
+ script: "bundle exec rake ci"
6
10
  rvm:
7
11
  - 2.0
8
12
  - 2.1
9
13
  - rbx-2
10
14
  - jruby
15
+ - jruby-head
11
16
  - ruby-head
12
17
  matrix:
13
18
  allow_failures:
14
19
  - rvm: ruby-head
20
+ - rvm: jruby-head
15
21
  services:
16
22
  - mongodb
17
23
  notifications:
@@ -1,3 +1,11 @@
1
+ ## v0.1.0 2014-12-23
2
+
3
+ Update to work with ROM 0.6.0
4
+
5
+ ### Changed
6
+
7
+ * Updated to work with latest ROM (splattael)
8
+
1
9
  ## v0.0.3 2014-12-31
2
10
 
3
11
  ### Added
@@ -8,7 +16,7 @@
8
16
 
9
17
  * Updated to work with latest ROM (solnic)
10
18
 
11
- [Compare v0.0.2...v0.0.3](https://github.com/rom-rb/rom-mongo/compare/v0.0.1...v0.0.3)
19
+ [Compare v0.0.2...v0.0.3](https://github.com/rom-rb/rom-mongo/compare/v0.0.2...v0.0.3)
12
20
 
13
21
  ## v0.0.2 2014-12-06
14
22
 
data/Gemfile CHANGED
@@ -3,8 +3,17 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :test do
6
+ gem 'inflecto'
6
7
  gem 'rom', git: 'https://github.com/rom-rb/rom.git', branch: 'master'
7
8
  gem 'rspec', '~> 3.1'
8
9
  gem 'codeclimate-test-reporter', require: false
9
10
  gem 'virtus'
10
11
  end
12
+
13
+ group :tools do
14
+ gem 'rubocop'
15
+
16
+ gem 'guard'
17
+ gem 'guard-rspec'
18
+ gem 'guard-rubocop'
19
+ end
data/README.md CHANGED
@@ -33,8 +33,8 @@ Or install it yourself as:
33
33
 
34
34
  ## Usage
35
35
 
36
- See `spec/integration/adapter_spec.rb` for a sample usage.
36
+ See [spec/integration/repository_spec.rb](spec/integration/repository_spec.rb) for a sample usage.
37
37
 
38
38
  ## License
39
39
 
40
- See `LICENSE` file.
40
+ See [LICENSE](LICENSE) file.
data/Rakefile CHANGED
@@ -1,10 +1,18 @@
1
1
  require "rspec/core/rake_task"
2
- require "rubocop/rake_task"
3
-
4
- task default: [:spec, :rubocop]
5
2
 
6
3
  RSpec::Core::RakeTask.new(:spec)
4
+ task default: [:ci]
5
+
6
+ desc "Run CI tasks"
7
+ task ci: [:spec]
8
+
9
+ begin
10
+ require "rubocop/rake_task"
11
+
12
+ Rake::Task[:default].enhance [:rubocop]
7
13
 
8
- RuboCop::RakeTask.new do |task|
9
- task.options << "--display-cop-names"
14
+ RuboCop::RakeTask.new do |task|
15
+ task.options << "--display-cop-names"
16
+ end
17
+ rescue LoadError
10
18
  end
@@ -1,7 +1,6 @@
1
- require 'moped'
2
-
3
1
  require 'rom'
2
+
4
3
  require 'rom/mongo/version'
5
- require 'rom/mongo/adapter'
4
+ require 'rom/mongo/repository'
6
5
 
7
- require 'rom/mongo/commands'
6
+ ROM.register_adapter(:mongo, ROM::Mongo)
@@ -1,10 +1,14 @@
1
1
  require 'bson'
2
2
 
3
+ require 'rom/commands'
4
+
3
5
  module ROM
4
6
  module Mongo
5
7
  module Commands
6
8
  class Create < ROM::Commands::Create
7
- alias_method :collection, :relation
9
+ def collection
10
+ relation.dataset
11
+ end
8
12
 
9
13
  def execute(document)
10
14
  collection.insert(document)
@@ -13,8 +17,9 @@ module ROM
13
17
  end
14
18
 
15
19
  class Update < ROM::Commands::Update
16
- alias_method :set, :call
17
- alias_method :collection, :relation
20
+ def collection
21
+ relation.dataset
22
+ end
18
23
 
19
24
  def execute(attributes)
20
25
  collection.update_all('$set' => attributes)
@@ -25,7 +30,7 @@ module ROM
25
30
  class Delete < ROM::Commands::Delete
26
31
  def execute
27
32
  removed = target.to_a
28
- target.remove_all
33
+ target.dataset.remove_all
29
34
  removed
30
35
  end
31
36
  end
@@ -0,0 +1,9 @@
1
+ require 'charlatan'
2
+
3
+ module ROM
4
+ module Mongo
5
+ class Dataset
6
+ include Charlatan.new(:collection, kind: Moped::Query)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,42 @@
1
+ require 'moped'
2
+ require 'uri'
3
+
4
+ require 'rom/repository'
5
+
6
+ require 'rom/mongo/dataset'
7
+ require 'rom/mongo/commands'
8
+
9
+ module ROM
10
+ module Mongo
11
+ class Relation < ROM::Relation
12
+ forward :insert, :find
13
+ end
14
+
15
+ class Repository < ROM::Repository
16
+ attr_reader :collections
17
+
18
+ def initialize(uri)
19
+ host, database = uri.split('/')
20
+ @connection = Moped::Session.new([host])
21
+ @connection.use database
22
+ @collections = {}
23
+ end
24
+
25
+ def [](name)
26
+ collections.fetch(name)
27
+ end
28
+
29
+ def dataset(name)
30
+ collections[name] = Dataset.new(connection[name])
31
+ end
32
+
33
+ def dataset?(name)
34
+ connection.collection_names.include?(name.to_s)
35
+ end
36
+
37
+ def command_namespace
38
+ Mongo::Commands
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module Mongo
3
- VERSION = '0.0.3'.freeze
3
+ VERSION = '0.1.0'.freeze
4
4
  end
5
5
  end
@@ -18,8 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_runtime_dependency "charlatan"
21
22
  spec.add_runtime_dependency "moped"
22
- spec.add_runtime_dependency "rom", "~> 0.5", ">= 0.5.0"
23
+ spec.add_runtime_dependency "rom", "~> 0.6", ">= 0.6.0"
23
24
 
24
25
  spec.add_development_dependency "bundler"
25
26
  spec.add_development_dependency "rake"
@@ -2,26 +2,17 @@ require 'spec_helper'
2
2
 
3
3
  require 'virtus'
4
4
 
5
- describe 'Mongo adapter' do
5
+ describe 'Mongo repository' do
6
6
  subject(:rom) { setup.finalize }
7
7
 
8
- let(:setup) { ROM.setup(mongo: 'mongo://127.0.0.1:27017/test') }
8
+ let(:setup) { ROM.setup(:mongo, '127.0.0.1:27017/test') }
9
+ let(:repository) { rom.repositories[:default] }
9
10
 
10
11
  after do
11
- rom.mongo.connection.drop
12
+ repository.connection.drop
12
13
  end
13
14
 
14
15
  before do
15
- setup.schema do
16
- base_relation(:users) do
17
- repository :mongo
18
-
19
- attribute '_id'
20
- attribute 'name'
21
- attribute 'email'
22
- end
23
- end
24
-
25
16
  setup.relation(:users) do
26
17
  def by_name(name)
27
18
  find(name: name)
@@ -52,42 +43,36 @@ describe 'Mongo adapter' do
52
43
  define(:users) do
53
44
  model(user_model)
54
45
 
46
+ register_as :model
47
+
55
48
  attribute :id, from: '_id'
49
+ attribute :name, from: 'name'
50
+ attribute :email, from: 'email'
56
51
  end
57
52
  end
58
53
 
59
- rom.schema.users.insert(name: 'Jane', email: 'jane@doe.org')
60
- rom.schema.users.insert(name: 'Joe', email: 'joe@doe.org')
54
+ rom.relations.users.insert(name: 'Jane', email: 'jane@doe.org')
55
+ rom.relations.users.insert(name: 'Joe', email: 'joe@doe.org')
61
56
  end
62
57
 
63
- describe 'env#read' do
58
+ describe 'env#relation' do
64
59
  it 'returns mapped object' do
65
- jane = rom.read(:users).by_name('Jane').to_a.first
60
+ jane = rom.relation(:users).as(:model).by_name('Jane').one!
66
61
 
67
62
  expect(jane.id)
68
- .to eql(rom.schema.users.find(name: 'Jane').one['_id'].to_s)
63
+ .to eql(rom.relation(:users) { |r| r.find(name: 'Jane') }.one['_id'].to_s)
69
64
  expect(jane.name).to eql('Jane')
70
65
  expect(jane.email).to eql('jane@doe.org')
71
66
  end
72
67
  end
73
68
 
74
- describe 'adapter#dataset?' do
69
+ describe 'repository#dataset?' do
75
70
  it 'returns true if a collection exists' do
76
- expect(rom.mongo.adapter.dataset?(:users)).to be(true)
71
+ expect(repository.dataset?(:users)).to be(true)
77
72
  end
78
73
 
79
74
  it 'returns false if a does not collection exist' do
80
- expect(rom.mongo.adapter.dataset?(:not_here)).to be(false)
81
- end
82
- end
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'])
75
+ expect(repository.dataset?(:not_here)).to be(false)
91
76
  end
92
77
  end
93
78
 
@@ -99,7 +84,7 @@ describe 'Mongo adapter' do
99
84
  id = BSON::ObjectId.new
100
85
 
101
86
  result = commands.try do
102
- create(_id: id, name: 'joe', email: 'joe@doe.org')
87
+ commands.create.call(_id: id, name: 'joe', email: 'joe@doe.org')
103
88
  end
104
89
 
105
90
  expect(result)
@@ -109,10 +94,10 @@ describe 'Mongo adapter' do
109
94
 
110
95
  describe 'update' do
111
96
  it 'updates a document in the collection' do
112
- jane = rom.read(:users).by_name('Jane').first
97
+ jane = rom.relation(:users).as(:model).by_name('Jane').one!
113
98
 
114
99
  result = commands.try do
115
- update(:by_name, 'Jane').set(email: 'jane.doe@test.com')
100
+ commands.update.by_name('Jane').set(email: 'jane.doe@test.com')
116
101
  end
117
102
 
118
103
  expect(result).to match_array(
@@ -125,10 +110,10 @@ describe 'Mongo adapter' do
125
110
 
126
111
  describe 'delete' do
127
112
  it 'deletes documents from the collection' do
128
- jane = rom.read(:users).by_name('Jane').first
129
- joe = rom.read(:users).by_name('Joe').first
113
+ jane = rom.relation(:users).as(:model).by_name('Jane').one!
114
+ joe = rom.relation(:users).as(:model).by_name('Joe').one!
130
115
 
131
- result = commands.try { delete(:by_name, 'Joe') }
116
+ result = commands.try { commands.delete.by_name('Joe') }
132
117
 
133
118
  expect(result).to match_array(
134
119
  [{ '_id' => BSON::ObjectId.from_string(joe.id),
@@ -136,7 +121,7 @@ describe 'Mongo adapter' do
136
121
  'email' => 'joe@doe.org' }]
137
122
  )
138
123
 
139
- expect(rom.read(:users).all).to match_array([jane])
124
+ expect(rom.relation(:users).as(:model).all).to match_array([jane])
140
125
  end
141
126
  end
142
127
  end
@@ -10,3 +10,14 @@ require 'rom-mongo'
10
10
  root = Pathname(__FILE__).dirname
11
11
 
12
12
  Dir[root.join('shared/*.rb').to_s].each { |f| require f }
13
+
14
+ RSpec.configure do |config|
15
+ config.before do
16
+ @constants = Object.constants
17
+ end
18
+
19
+ config.after do
20
+ added_constants = Object.constants - @constants
21
+ added_constants.each { |name| Object.send(:remove_const, name) }
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rom/lint/spec'
4
+
5
+ describe ROM::Mongo::Repository do
6
+ it_behaves_like 'a rom repository' do
7
+ let(:identifier) { :mongo }
8
+ let(:repository) { ROM::Mongo::Repository }
9
+ let(:uri) { '127.0.0.1:27017/test' }
10
+ end
11
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom-mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
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-31 00:00:00.000000000 Z
11
+ date: 2015-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: charlatan
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: moped
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -30,20 +44,20 @@ dependencies:
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0.5'
47
+ version: '0.6'
34
48
  - - ">="
35
49
  - !ruby/object:Gem::Version
36
- version: 0.5.0
50
+ version: 0.6.0
37
51
  type: :runtime
38
52
  prerelease: false
39
53
  version_requirements: !ruby/object:Gem::Requirement
40
54
  requirements:
41
55
  - - "~>"
42
56
  - !ruby/object:Gem::Version
43
- version: '0.5'
57
+ version: '0.6'
44
58
  - - ">="
45
59
  - !ruby/object:Gem::Version
46
- version: 0.5.0
60
+ version: 0.6.0
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: bundler
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -96,6 +110,7 @@ files:
96
110
  - ".gitignore"
97
111
  - ".rspec"
98
112
  - ".rubocop.yml"
113
+ - ".rubocop_todo.yml"
99
114
  - ".travis.yml"
100
115
  - CHANGELOG.md
101
116
  - Gemfile
@@ -104,12 +119,14 @@ files:
104
119
  - Rakefile
105
120
  - lib/rom-mongo.rb
106
121
  - lib/rom/mongo.rb
107
- - lib/rom/mongo/adapter.rb
108
122
  - lib/rom/mongo/commands.rb
123
+ - lib/rom/mongo/dataset.rb
124
+ - lib/rom/mongo/repository.rb
109
125
  - lib/rom/mongo/version.rb
110
126
  - rom-mongo.gemspec
111
- - spec/integration/adapter_spec.rb
127
+ - spec/integration/repository_spec.rb
112
128
  - spec/spec_helper.rb
129
+ - spec/unit/repository_spec.rb
113
130
  homepage: ''
114
131
  licenses:
115
132
  - MIT
@@ -135,5 +152,6 @@ signing_key:
135
152
  specification_version: 4
136
153
  summary: MongoDB support for Ruby Object Mapper
137
154
  test_files:
138
- - spec/integration/adapter_spec.rb
155
+ - spec/integration/repository_spec.rb
139
156
  - spec/spec_helper.rb
157
+ - spec/unit/repository_spec.rb
@@ -1,68 +0,0 @@
1
- module ROM
2
- module Mongo
3
- class Adapter < ROM::Adapter
4
- def self.schemes
5
- [:mongo]
6
- end
7
-
8
- module RelationInclusion
9
- def header
10
- dataset.header
11
- end
12
- end
13
-
14
- class Dataset
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
28
-
29
- def each(&block)
30
- collection.find.each(&block)
31
- end
32
-
33
- def query?
34
- collection.is_a?(Moped::Query)
35
- end
36
- end
37
-
38
- attr_reader :collections
39
-
40
- def initialize(*args)
41
- super
42
- @connection = Moped::Session.new(["#{uri.host}:#{uri.port}"])
43
- @connection.use uri.path.gsub('/', '')
44
- @collections = {}
45
- end
46
-
47
- def [](name)
48
- collections.fetch(name)
49
- end
50
-
51
- def dataset(name, header)
52
- collections[name] = Dataset.new(connection[name], header)
53
- end
54
-
55
- def dataset?(name)
56
- connection.collection_names.include?(name.to_s)
57
- end
58
-
59
- def command_namespace
60
- Mongo::Commands
61
- end
62
-
63
- def extend_relation_class(klass)
64
- klass.send(:include, RelationInclusion)
65
- end
66
- end
67
- end
68
- end