rom-couchdb 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +7 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +65 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/rom/couchdb.rb +15 -0
- data/lib/rom/couchdb/commands.rb +45 -0
- data/lib/rom/couchdb/dataset.rb +65 -0
- data/lib/rom/couchdb/relation.rb +14 -0
- data/lib/rom/couchdb/repository.rb +27 -0
- data/lib/rom/couchdb/version.rb +6 -0
- data/rom-couchdb.gemspec +26 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8da918149d6b9e7f3fcaf2be59e248a85412c761
|
4
|
+
data.tar.gz: c8bbf55bce104b0749e0b24233dcee7422099eb8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c4fdad583c91fb7656a306366ed68775403fcc27cec198449041f086740900d9bb6d820d783dafa2510e5600cd52a121ec5d51a99bb7fd41d243b4bd36f047ba
|
7
|
+
data.tar.gz: 7fd6573ecd427e38f0ae9cccfc8905ef77092183969615c2007e077199a8bf3fba759f12c5d4a84ca2aa5374674baaf469a1c56ab2e9ff8644d7874d4a10b164
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Hunter Madison
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Rom::CouchDB
|
2
|
+
|
3
|
+
[](https://travis-ci.org/hmadison/rom-couchdb)
|
4
|
+
|
5
|
+
Work in progress for CouchDB support for ROM. Uses [couchrest](https://github.com/couchrest/couchrest) as the connection adapter.
|
6
|
+
|
7
|
+
## Example
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
class Color
|
11
|
+
attr_reader :name, :code, :id, :rev
|
12
|
+
|
13
|
+
def initialize(attributes)
|
14
|
+
puts attributes
|
15
|
+
@name, @code, @id, @rev = attributes.values_at(:name, :code, :id, :rev)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
ROM.setup(:couchdb, 'testdb')
|
20
|
+
|
21
|
+
class Colors < ROM::Relation[:couchdb]
|
22
|
+
def find_id(id)
|
23
|
+
find_by_id(id)
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_view(name, params)
|
27
|
+
find_by_view(name, params)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class ColorMapper < ROM::Mapper
|
32
|
+
relation :colors
|
33
|
+
register_as :entity
|
34
|
+
|
35
|
+
model Color
|
36
|
+
|
37
|
+
attribute :id, from: :'_id'
|
38
|
+
attribute :rev, from: :'_rev'
|
39
|
+
attribute :name
|
40
|
+
attribute :code
|
41
|
+
end
|
42
|
+
|
43
|
+
class CreateColor < ROM::Commands::Create[:couchdb]
|
44
|
+
register_as :create
|
45
|
+
relation :colors
|
46
|
+
result :one
|
47
|
+
end
|
48
|
+
|
49
|
+
class UpdateColor < ROM::Commands::Update[:couchdb]
|
50
|
+
register_as :update
|
51
|
+
relation :colors
|
52
|
+
result :one
|
53
|
+
end
|
54
|
+
|
55
|
+
rom = ROM.finalize.env
|
56
|
+
color_commands = rom.command(:colors)
|
57
|
+
color_relations = rom.relation(:colors)
|
58
|
+
|
59
|
+
|
60
|
+
color = color_commands.as(:entity).create.call(name: "Red", code: 8)
|
61
|
+
update = color_commands.as(:entity).create.call(name: "Blue", code: 9, _id: color.id, _rev: color.rev)
|
62
|
+
|
63
|
+
find = color_relations.as(:entity).find_id(color.id).one
|
64
|
+
all_docs = color_relations.find_view('_all_docs', {})
|
65
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rom/couchdb'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require 'pry'
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/rom/couchdb.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rom'
|
2
|
+
|
3
|
+
require 'rom/couchdb/version'
|
4
|
+
require 'rom/couchdb/repository'
|
5
|
+
require 'rom/couchdb/dataset'
|
6
|
+
require 'rom/couchdb/relation'
|
7
|
+
require 'rom/couchdb/commands'
|
8
|
+
|
9
|
+
module ROM
|
10
|
+
# CouchDB support for ROM
|
11
|
+
module CouchDB
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
ROM.register_adapter(:couchdb, ROM::CouchDB)
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rom/commands'
|
2
|
+
|
3
|
+
module ROM
|
4
|
+
module CouchDB
|
5
|
+
module Commands
|
6
|
+
# CouchDB create command
|
7
|
+
class Create < ROM::Commands::Create
|
8
|
+
def collection
|
9
|
+
relation.dataset
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute(object)
|
13
|
+
document = object.dup
|
14
|
+
collection << document
|
15
|
+
[document]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# CouchDB update command
|
20
|
+
class Update < ROM::Commands::Update
|
21
|
+
def collection
|
22
|
+
relation.dataset
|
23
|
+
end
|
24
|
+
|
25
|
+
def execute(object)
|
26
|
+
document = object.dup
|
27
|
+
collection << (document)
|
28
|
+
[document]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# CouchDB delete command
|
33
|
+
class Delete < ROM::Commands::Delete
|
34
|
+
def collection
|
35
|
+
relation.dataset
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute(object)
|
39
|
+
collection.delete(object)
|
40
|
+
[object]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'couchrest'
|
2
|
+
|
3
|
+
require 'rom/support/options'
|
4
|
+
require 'rom/support/data_proxy'
|
5
|
+
|
6
|
+
module ROM
|
7
|
+
module CouchDB
|
8
|
+
# CouchDB Dataset
|
9
|
+
class Dataset
|
10
|
+
include ROM::Options
|
11
|
+
include ROM::DataProxy
|
12
|
+
|
13
|
+
attr_reader :results
|
14
|
+
|
15
|
+
option :connection, reader: true
|
16
|
+
|
17
|
+
def initialize(data, options = {})
|
18
|
+
@data = data
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def insert(object)
|
23
|
+
input = stringify_proc.call(object.dup)
|
24
|
+
resp = @connection.save_doc(input)
|
25
|
+
# send back the id and revision of the document
|
26
|
+
object[:_id] = resp['id']
|
27
|
+
object[:_rev] = resp['rev']
|
28
|
+
self
|
29
|
+
end
|
30
|
+
alias_method :<<, :insert
|
31
|
+
|
32
|
+
def delete(object)
|
33
|
+
input = stringify_proc.call(object.dup)
|
34
|
+
@connection.delete_doc(input)
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def count
|
39
|
+
@data.count
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_a
|
43
|
+
@data
|
44
|
+
end
|
45
|
+
|
46
|
+
def find_by_id(id, params = {})
|
47
|
+
document = @connection.get(id, params).to_hash
|
48
|
+
self.class.new([document], connection: @connection)
|
49
|
+
end
|
50
|
+
|
51
|
+
def find_by_view(name, params = {})
|
52
|
+
results = @connection.view(name, params)
|
53
|
+
self.class.new([results], connection: @connection)
|
54
|
+
end
|
55
|
+
|
56
|
+
def stringify_proc
|
57
|
+
Transproc(:stringify_keys)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.row_proc
|
61
|
+
Transproc(:symbolize_keys)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'couchrest'
|
2
|
+
|
3
|
+
module ROM
|
4
|
+
module CouchDB
|
5
|
+
# CouchDB repository for ROM
|
6
|
+
class Repository < ROM::Repository
|
7
|
+
attr_reader :connection, :sets
|
8
|
+
|
9
|
+
def initialize(uri)
|
10
|
+
@connection = CouchRest.database(uri)
|
11
|
+
@sets = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def dataset(name)
|
15
|
+
@sets[name] = Dataset.new([], connection: @connection)
|
16
|
+
end
|
17
|
+
|
18
|
+
def [](name)
|
19
|
+
@sets.fetch(name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def dataset?(name)
|
23
|
+
@sets.include?(name)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/rom-couchdb.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/couchdb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rom-couchdb'
|
8
|
+
spec.version = ROM::CouchDB::VERSION
|
9
|
+
spec.authors = ['Hunter Madison']
|
10
|
+
spec.email = ['hunterglenmadison@icloud.com']
|
11
|
+
|
12
|
+
spec.summary = 'CouchDB support for ROM'
|
13
|
+
spec.homepage = 'https://github.com/hmadison'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test)/})}
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'rom', '~> 0.6.2'
|
22
|
+
spec.add_runtime_dependency 'couchrest'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rom-couchdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hunter Madison
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rom
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.6.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.6.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: couchrest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
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.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.9'
|
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:
|
70
|
+
email:
|
71
|
+
- hunterglenmadison@icloud.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rubocop.yml"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/rom/couchdb.rb
|
86
|
+
- lib/rom/couchdb/commands.rb
|
87
|
+
- lib/rom/couchdb/dataset.rb
|
88
|
+
- lib/rom/couchdb/relation.rb
|
89
|
+
- lib/rom/couchdb/repository.rb
|
90
|
+
- lib/rom/couchdb/version.rb
|
91
|
+
- rom-couchdb.gemspec
|
92
|
+
homepage: https://github.com/hmadison
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.5
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: CouchDB support for ROM
|
116
|
+
test_files: []
|
117
|
+
has_rdoc:
|