rom-mongo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +23 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +3 -0
- data/lib/rom-mongo.rb +1 -0
- data/lib/rom/mongo.rb +5 -0
- data/lib/rom/mongo/adapter.rb +33 -0
- data/lib/rom/mongo/version.rb +5 -0
- data/rom-mongo.gemspec +26 -0
- data/spec/integration/adapter_spec.rb +54 -0
- data/spec/spec_helper.rb +12 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: baf2523814478bc55ff949ed66bf4a9afae3c4a6
|
4
|
+
data.tar.gz: d787e542f6073fe992aafd9f9ef84c0418e1f3cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc31577a39e38fc80a7d83a281628d5d715a5083b57510d85628d167403b64ca088e5e003a585680b98ca8391df55246a71cd2b573bb74981dabac0b84c0542f
|
7
|
+
data.tar.gz: 7283bbc8d7ff0d01f3e0609e773645d166331efbd899e61268fc8acac52c7404c72e50129fca17a86e09c205dd1a6714e5a034031fee71793ad30da0ad827391
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
language: ruby
|
2
|
+
bundler_args: --without yard guard benchmarks
|
3
|
+
env:
|
4
|
+
- CODECLIMATE_REPO_TOKEN=886f3b795e74159719804f8e18b853f4c23a81bd814404e52ec248a0dae6d656
|
5
|
+
script: "bundle exec rake spec"
|
6
|
+
rvm:
|
7
|
+
- 2.0.0
|
8
|
+
- 2.1.2
|
9
|
+
- rbx-2
|
10
|
+
- jruby
|
11
|
+
- ruby-head
|
12
|
+
matrix:
|
13
|
+
allow_failures:
|
14
|
+
- rvm: ruby-head
|
15
|
+
services:
|
16
|
+
- mongodb
|
17
|
+
notifications:
|
18
|
+
webhooks:
|
19
|
+
urls:
|
20
|
+
- https://webhooks.gitter.im/e/39e1225f489f38b0bd09
|
21
|
+
on_success: change
|
22
|
+
on_failure: always
|
23
|
+
on_start: false
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Piotr Solnica
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
[gem]: https://rubygems.org/gems/rom-mongo
|
2
|
+
[travis]: https://travis-ci.org/rom-rb/rom-mongo
|
3
|
+
[gemnasium]: https://gemnasium.com/rom-rb/rom-mongo
|
4
|
+
[codeclimate]: https://codeclimate.com/github/rom-rb/rom-mongo
|
5
|
+
[inchpages]: http://inch-ci.org/github/rom-rb/rom-mongo
|
6
|
+
|
7
|
+
# ROM::Mongo
|
8
|
+
|
9
|
+
[![Gem Version](https://badge.fury.io/rb/rom-mongo.svg)][gem]
|
10
|
+
[![Build Status](https://travis-ci.org/rom-rb/rom-mongo.svg?branch=master)][travis]
|
11
|
+
[![Dependency Status](https://gemnasium.com/rom-rb/rom-mongo.png)][gemnasium]
|
12
|
+
[![Code Climate](https://codeclimate.com/github/rom-rb/rom-mongo/badges/gpa.svg)][codeclimate]
|
13
|
+
[![Test Coverage](https://codeclimate.com/github/rom-rb/rom-mongo/badges/coverage.svg)][codeclimate]
|
14
|
+
[![Inline docs](http://inch-ci.org/github/rom-rb/rom-mongo.svg?branch=master)][inchpages]
|
15
|
+
|
16
|
+
MongoDB support for [Ruby Object Mapper](https://github.com/rom-rb/rom)
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'rom-mongo'
|
24
|
+
```
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install rom-mongo
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
See `spec/integration/adapter_spec.rb` for a sample usage.
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
See `LICENSE` file.
|
data/Rakefile
ADDED
data/lib/rom-mongo.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rom/mongo'
|
data/lib/rom/mongo.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module ROM
|
2
|
+
module Mongo
|
3
|
+
|
4
|
+
class Adapter < ROM::Adapter
|
5
|
+
attr_reader :connection
|
6
|
+
|
7
|
+
def self.schemes
|
8
|
+
[:mongo]
|
9
|
+
end
|
10
|
+
|
11
|
+
class Dataset
|
12
|
+
include Charlatan.new(:collection, kind: Moped::Query)
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(*args)
|
16
|
+
super
|
17
|
+
@connection = Moped::Session.new(["#{uri.host}:#{uri.port}"])
|
18
|
+
@connection.use uri.path.gsub('/', '')
|
19
|
+
end
|
20
|
+
|
21
|
+
def [](name)
|
22
|
+
Dataset.new(connection[name])
|
23
|
+
end
|
24
|
+
|
25
|
+
def schema
|
26
|
+
[]
|
27
|
+
end
|
28
|
+
|
29
|
+
ROM::Adapter.register(self)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/rom-mongo.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rom/mongo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rom-mongo"
|
8
|
+
spec.version = ROM::Mongo::VERSION
|
9
|
+
spec.authors = ["Piotr Solnica"]
|
10
|
+
spec.email = ["piotr.solnica@gmail.com"]
|
11
|
+
spec.summary = %q{MongoDB support for Ruby Object Mapper}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "moped"
|
22
|
+
spec.add_runtime_dependency "rom", "~> 0.3"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'virtus'
|
4
|
+
|
5
|
+
describe 'Mongo adapter' do
|
6
|
+
let(:setup) { ROM.setup(mongo: 'mongo://127.0.0.1:27017/test') }
|
7
|
+
let(:rom) { setup.finalize }
|
8
|
+
|
9
|
+
after do
|
10
|
+
rom.mongo.connection.drop
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'works' do
|
14
|
+
setup.schema do
|
15
|
+
base_relation(:users) do
|
16
|
+
repository :mongo
|
17
|
+
|
18
|
+
attribute "_id"
|
19
|
+
attribute "name"
|
20
|
+
attribute "email"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
setup.relation(:users) do
|
25
|
+
def by_name(name)
|
26
|
+
find(name: name)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
user_model = Class.new do
|
31
|
+
include Virtus.model
|
32
|
+
|
33
|
+
attribute :id, String
|
34
|
+
attribute :name, String
|
35
|
+
attribute :email, String
|
36
|
+
end
|
37
|
+
|
38
|
+
setup.mappers do
|
39
|
+
define(:users) do
|
40
|
+
model(user_model)
|
41
|
+
|
42
|
+
attribute :id, from: '_id'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
rom.schema.users.insert(name: 'Jane', email: 'jane@doe.org')
|
47
|
+
|
48
|
+
jane = rom.read(:users).by_name('Jane').to_a.first
|
49
|
+
|
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')
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rom-mongo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Piotr Solnica
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: moped
|
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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rom
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: MongoDB support for Ruby Object Mapper
|
70
|
+
email:
|
71
|
+
- piotr.solnica@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- .travis.yml
|
79
|
+
- CHANGELOG.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- lib/rom-mongo.rb
|
85
|
+
- lib/rom/mongo.rb
|
86
|
+
- lib/rom/mongo/adapter.rb
|
87
|
+
- lib/rom/mongo/version.rb
|
88
|
+
- rom-mongo.gemspec
|
89
|
+
- spec/integration/adapter_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
homepage: ''
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.0.14
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: MongoDB support for Ruby Object Mapper
|
115
|
+
test_files:
|
116
|
+
- spec/integration/adapter_spec.rb
|
117
|
+
- spec/spec_helper.rb
|