rom 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +8 -64
- data/lib/rom/constants.rb +2 -1
- data/lib/rom/processor/transproc.rb +25 -11
- data/lib/rom/version.rb +1 -1
- data/rom.gemspec +1 -1
- data/spec/integration/commands/graph_spec.rb +6 -6
- data/spec/spec_helper.rb +4 -0
- data/spec/unit/rom/commands/graph_spec.rb +8 -0
- data/spec/unit/rom/memory/commands/create_spec.rb +2 -2
- data/spec/unit/rom/memory/commands/delete_spec.rb +2 -2
- data/spec/unit/rom/relation/graph_spec.rb +1 -1
- data/spec/unit/rom/support/array_dataset_spec.rb +1 -1
- data/spec/unit/rom/support/enumerable_dataset_spec.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5a38d2264b1f215a3dbcccadc91a7031358ab0d
|
4
|
+
data.tar.gz: 69054a1fdda6257167af21e190e6574f89d192ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66241774ced83118c07f10e9266e1094f6e7211f7d194983a43779deca602ca734ee2ee79461af90b190b033057cd2aad3a296fc12b1804aae0851cbbb48fc33
|
7
|
+
data.tar.gz: 394fdb0895e9d020540b73ff39ae7fe8cf3051294f03d6c0f17584dafba6110130dc5c5ed26324ad6fbda311000027696a127531e00ef644ddfbfb226e01c098
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,20 @@
|
|
1
|
+
## v0.8.1 2015-07-12
|
2
|
+
|
3
|
+
### Fixed
|
4
|
+
|
5
|
+
* `ROM::CommandError` properly sets original error and backtrace (solnic)
|
6
|
+
|
7
|
+
### Changed
|
8
|
+
|
9
|
+
* Internal transproc processor has been updated to the new API (solnic)
|
10
|
+
|
11
|
+
[Compare v0.8.0...v0.8.1](https://github.com/rom-rb/rom/compare/v0.8.0...v0.8.1)
|
12
|
+
|
1
13
|
## v0.8.0 2015-06-22
|
2
14
|
|
3
15
|
### Added
|
4
16
|
|
17
|
+
* Commands can be combined into a single command that can work with a nested input (solnic)
|
5
18
|
* New `step` mapper operation that allows multistep transformations inside a single mapper (dekz)
|
6
19
|
* New `ungroup` and `unfold` mapper operations inverse `group` and `fold` (nepalez)
|
7
20
|
* Support deep nesting of `unwrap` mapper operations (nepalez)
|
data/README.md
CHANGED
@@ -14,26 +14,28 @@
|
|
14
14
|
[![Test Coverage](https://codeclimate.com/github/rom-rb/rom/badges/coverage.svg)][codeclimate]
|
15
15
|
[![Inline docs](http://inch-ci.org/github/rom-rb/rom.svg?branch=master&style=flat)][inchpages]
|
16
16
|
|
17
|
-
Ruby Object Mapper (ROM) is
|
18
|
-
provide powerful object mapping capabilities without limiting the
|
19
|
-
your datastore.
|
17
|
+
Ruby Object Mapper (ROM) is a data mapping and persistence toolkit for Ruby
|
18
|
+
with the goal to provide powerful object mapping capabilities without limiting the
|
19
|
+
full power of your datastore.
|
20
20
|
|
21
21
|
Learn more:
|
22
22
|
|
23
23
|
* [Introduction](http://rom-rb.org/introduction/)
|
24
|
-
* [
|
24
|
+
* [Guides](http://rom-rb.org/introduction/)
|
25
|
+
* [Tutorials](http://rom-rb.org/tutorials/)
|
25
26
|
|
26
27
|
## Adapters
|
27
28
|
|
28
29
|
* [rom-sql](https://github.com/rom-rb/rom-sql)
|
29
30
|
* [rom-yesql](https://github.com/rom-rb/rom-yesql)
|
31
|
+
* [rom-couchdb](https://github.com/rom-rb/rom-couchdb)
|
30
32
|
* [rom-mongo](https://github.com/rom-rb/rom-mongo)
|
31
|
-
* [rom-yaml](https://github.com/rom-rb/rom-yaml)
|
32
|
-
* [rom-csv](https://github.com/rom-rb/rom-csv)
|
33
33
|
* [rom-neo4j](https://github.com/rom-rb/rom-neo4j)
|
34
34
|
* [rom-event_store](https://github.com/rom-rb/rom-event_store)
|
35
35
|
* [rom-influxdb](https://github.com/rom-rb/rom-influxdb)
|
36
36
|
* [rom-rethinkdb](https://github.com/rom-rb/rom-rethinkdb)
|
37
|
+
* [rom-yaml](https://github.com/rom-rb/rom-yaml)
|
38
|
+
* [rom-csv](https://github.com/rom-rb/rom-csv)
|
37
39
|
|
38
40
|
See [issues](https://github.com/rom-rb/rom/issues?q=is%3Aopen+is%3Aissue+label%3Aadapter+label%3Afeature)
|
39
41
|
for a list of adapters that are planned to be added soon.
|
@@ -44,64 +46,6 @@ for a list of adapters that are planned to be added soon.
|
|
44
46
|
* [rom-rails](https://github.com/rom-rb/rom-rails)
|
45
47
|
* [rom-roda](https://github.com/rom-rb/rom-roda)
|
46
48
|
|
47
|
-
## Synopsis
|
48
|
-
|
49
|
-
``` ruby
|
50
|
-
ROM.setup(:memory)
|
51
|
-
|
52
|
-
# This is our domain-specific class
|
53
|
-
class User
|
54
|
-
attr_reader :name, :age
|
55
|
-
|
56
|
-
def initialize(attributes)
|
57
|
-
@name, @age = attributes.values_at(:name, :age)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
# Here we define user relation which encapsulates accessing user data that
|
62
|
-
# we can map to domain objects
|
63
|
-
class Users < ROM::Relation[:memory]
|
64
|
-
def by_name(name)
|
65
|
-
restrict(name: name)
|
66
|
-
end
|
67
|
-
|
68
|
-
def adults
|
69
|
-
restrict { |user| user[:age] >= 18 }
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
# Even though mappers can be derived from model definitions here's how you
|
74
|
-
# could define it explicitly
|
75
|
-
class UserMapper < ROM::Mapper
|
76
|
-
relation :users
|
77
|
-
register_as :entity
|
78
|
-
|
79
|
-
model User
|
80
|
-
|
81
|
-
attribute :name
|
82
|
-
attribute :age
|
83
|
-
end
|
84
|
-
|
85
|
-
# You can define specialized commands that handle creating, updating and deleting
|
86
|
-
# data, those classes can use external input param handlers and validators too
|
87
|
-
class CreateUser < ROM::Commands::Create[:memory]
|
88
|
-
register_as :create
|
89
|
-
relation :users
|
90
|
-
result :one
|
91
|
-
end
|
92
|
-
|
93
|
-
# finalize the setup and retrieve object registry (aka ROM env)
|
94
|
-
rom = ROM.finalize.env
|
95
|
-
|
96
|
-
# accessing defined commands
|
97
|
-
rom.command(:users).create.call(name: "Joe", age: 17)
|
98
|
-
rom.command(:users).create.call(name: "Jane", age: 18)
|
99
|
-
|
100
|
-
# reading relations using defined mappers
|
101
|
-
puts rom.relation(:users) { |r| r.by_name("Jane").adults }.as(:entity).to_a.inspect
|
102
|
-
# => [#<User:0x007fdba161cc48 @id=2, @name="Jane", @age=18>]
|
103
|
-
```
|
104
|
-
|
105
49
|
## ROADMAP
|
106
50
|
|
107
51
|
ROM is on its way towards 1.0.0. You can see an overview of tasks scheduled for 1.0.0 on our [waffle board](https://waffle.io/rom-rb/rom?label=1.0.0). Please notice that most of the 1.0.0 features/changes will become part of minor (0.x) upgrades before 1.0.0 final gets released.
|
data/lib/rom/constants.rb
CHANGED
@@ -14,6 +14,23 @@ module ROM
|
|
14
14
|
class Transproc < Processor
|
15
15
|
include ::Transproc::Composer
|
16
16
|
|
17
|
+
module Functions
|
18
|
+
extend ::Transproc::Registry
|
19
|
+
|
20
|
+
import ::Transproc::Coercions
|
21
|
+
import ::Transproc::ArrayTransformations
|
22
|
+
import ::Transproc::HashTransformations
|
23
|
+
import ::Transproc::ClassTransformations
|
24
|
+
|
25
|
+
def self.identity(tuple)
|
26
|
+
tuple
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.filter_empty(arr)
|
30
|
+
arr.reject { |row| row.values.all?(&:nil?) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
17
34
|
# @return [Header] header from a mapper
|
18
35
|
#
|
19
36
|
# @api private
|
@@ -34,14 +51,6 @@ module ROM
|
|
34
51
|
# @api private
|
35
52
|
attr_reader :row_proc
|
36
53
|
|
37
|
-
# Default no-op row_proc
|
38
|
-
EMPTY_FN = -> tuple { tuple }.freeze
|
39
|
-
|
40
|
-
# Filter out empty tuples from an array
|
41
|
-
FILTER_EMPTY = Transproc(
|
42
|
-
-> arr { arr.reject { |row| row.values.all?(&:nil?) } }
|
43
|
-
)
|
44
|
-
|
45
54
|
# Build a transproc function from the header
|
46
55
|
#
|
47
56
|
# @param [ROM::Header] header
|
@@ -67,7 +76,7 @@ module ROM
|
|
67
76
|
#
|
68
77
|
# @api private
|
69
78
|
def to_transproc
|
70
|
-
compose(
|
79
|
+
compose(t(:identity)) do |ops|
|
71
80
|
combined = header.combined
|
72
81
|
ops << t(:combine, combined.map(&method(:combined_args))) if combined.any?
|
73
82
|
ops << header.preprocessed.map { |attr| visit(attr, true) }
|
@@ -207,7 +216,7 @@ module ROM
|
|
207
216
|
|
208
217
|
compose do |ops|
|
209
218
|
ops << t(:group, name, keys)
|
210
|
-
ops << t(:map_array, t(:map_value, name,
|
219
|
+
ops << t(:map_array, t(:map_value, name, t(:filter_empty)))
|
211
220
|
ops << others.map { |attr|
|
212
221
|
t(:map_array, t(:map_value, name, visit(attr, true)))
|
213
222
|
}
|
@@ -262,7 +271,7 @@ module ROM
|
|
262
271
|
|
263
272
|
compose do |ops|
|
264
273
|
ops << t(:group, name, keys)
|
265
|
-
ops << t(:map_array, t(:map_value, name,
|
274
|
+
ops << t(:map_array, t(:map_value, name, t(:filter_empty)))
|
266
275
|
ops << t(:map_array, t(:fold, name, keys.first))
|
267
276
|
end
|
268
277
|
end
|
@@ -369,6 +378,11 @@ module ROM
|
|
369
378
|
def new(*args)
|
370
379
|
self.class.new(*args)
|
371
380
|
end
|
381
|
+
|
382
|
+
# @api private
|
383
|
+
def t(*args)
|
384
|
+
Functions[*args]
|
385
|
+
end
|
372
386
|
end
|
373
387
|
end
|
374
388
|
end
|
data/lib/rom/version.rb
CHANGED
data/rom.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.test_files = `git ls-files -- {spec}/*`.split("\n")
|
16
16
|
gem.license = 'MIT'
|
17
17
|
|
18
|
-
gem.add_runtime_dependency 'transproc', '~> 0.
|
18
|
+
gem.add_runtime_dependency 'transproc', '~> 0.3', '>= 0.3.0'
|
19
19
|
gem.add_runtime_dependency 'equalizer', '~> 0.0', '>= 0.0.9'
|
20
20
|
|
21
21
|
gem.add_development_dependency 'rake', '~> 10.3'
|
@@ -12,14 +12,14 @@ describe 'Building up a command graph for nested input' do
|
|
12
12
|
|
13
13
|
setup.commands(:users) do
|
14
14
|
define(:create) do
|
15
|
-
input
|
15
|
+
input T(:accept_keys, [:name])
|
16
16
|
result :one
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
setup.commands(:books) do
|
21
21
|
define(:create) do
|
22
|
-
input
|
22
|
+
input T(:accept_keys, [:title, :user])
|
23
23
|
|
24
24
|
def execute(tuples, user)
|
25
25
|
super(tuples.map { |t| t.merge(user: user.fetch(:name)) })
|
@@ -29,7 +29,7 @@ describe 'Building up a command graph for nested input' do
|
|
29
29
|
|
30
30
|
setup.commands(:tags) do
|
31
31
|
define(:create) do
|
32
|
-
input
|
32
|
+
input T(:accept_keys, [:name, :task])
|
33
33
|
|
34
34
|
def execute(tuples, task)
|
35
35
|
super(tuples.map { |t| t.merge(task: task.fetch(:title)) })
|
@@ -41,7 +41,7 @@ describe 'Building up a command graph for nested input' do
|
|
41
41
|
it 'creates a command graph for nested input :one result as root' do
|
42
42
|
setup.commands(:tasks) do
|
43
43
|
define(:create) do
|
44
|
-
input
|
44
|
+
input T(:accept_keys, [:title, :user])
|
45
45
|
result :one
|
46
46
|
|
47
47
|
def execute(tuple, user)
|
@@ -102,7 +102,7 @@ describe 'Building up a command graph for nested input' do
|
|
102
102
|
it 'creates a command graph for nested input with :many results as root' do
|
103
103
|
setup.commands(:tasks) do
|
104
104
|
define(:create) do
|
105
|
-
input
|
105
|
+
input T(:accept_keys, [:title, :user])
|
106
106
|
|
107
107
|
def execute(tuples, user)
|
108
108
|
super(tuples.map { |t| t.merge(user: user.fetch(:name)) })
|
@@ -178,7 +178,7 @@ describe 'Building up a command graph for nested input' do
|
|
178
178
|
|
179
179
|
setup.commands(:tasks) do
|
180
180
|
define(:create) do
|
181
|
-
input
|
181
|
+
input T(:accept_keys, [:title, :user])
|
182
182
|
|
183
183
|
def execute(tuples, user)
|
184
184
|
super(tuples.map { |t| t.merge(user: user.fetch(:name)) })
|
data/spec/spec_helper.rb
CHANGED
@@ -141,6 +141,14 @@ describe ROM::Commands::Graph do
|
|
141
141
|
allow(command.nodes[0]).to receive(:call).and_raise(StandardError, 'ooops')
|
142
142
|
|
143
143
|
expect { command.call }.to raise_error(ROM::CommandFailure, /oops/)
|
144
|
+
|
145
|
+
begin
|
146
|
+
command.call
|
147
|
+
rescue ROM::CommandFailure => e
|
148
|
+
expect(e.original_error).to be_a(ROM::CommandFailure)
|
149
|
+
expect(e.original_error.message).to include('ooops')
|
150
|
+
expect(e.backtrace).to eql(e.original_error.backtrace)
|
151
|
+
end
|
144
152
|
end
|
145
153
|
end
|
146
154
|
end
|
@@ -2,10 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
require 'rom/memory'
|
4
4
|
|
5
|
-
describe ROM::Memory::Commands::
|
5
|
+
describe ROM::Memory::Commands::Create do
|
6
6
|
include_context 'users and tasks'
|
7
7
|
|
8
|
-
subject(:command) { ROM::Memory::Commands::
|
8
|
+
subject(:command) { ROM::Memory::Commands::Create.build(users) }
|
9
9
|
|
10
10
|
let(:users) { rom.relations[:users] }
|
11
11
|
|
@@ -2,10 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
require 'rom/memory'
|
4
4
|
|
5
|
-
describe ROM::Memory::Commands::
|
5
|
+
describe ROM::Memory::Commands::Delete do
|
6
6
|
include_context 'users and tasks'
|
7
7
|
|
8
|
-
subject(:command) { ROM::Memory::Commands::
|
8
|
+
subject(:command) { ROM::Memory::Commands::Delete.build(users) }
|
9
9
|
|
10
10
|
let(:users) { rom.relations[:users] }
|
11
11
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: transproc
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.3'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.
|
22
|
+
version: 0.3.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '0.
|
29
|
+
version: '0.3'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.
|
32
|
+
version: 0.3.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: equalizer
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|