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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f71a2cbfa094787fbd2ca709cd2c229aca10799
4
- data.tar.gz: 73f461e9a6e50aec0d632f4332137fc389d57a70
3
+ metadata.gz: d5a38d2264b1f215a3dbcccadc91a7031358ab0d
4
+ data.tar.gz: 69054a1fdda6257167af21e190e6574f89d192ad
5
5
  SHA512:
6
- metadata.gz: a74fec1aaf8c1d5f0feb8b2128fa4db3c0ec31cf7018f8905ef396e3a614d071f17d7f60f2bd3411ca887efdbb9959faa3e73f0082fa3cbedcf43a95efd93286
7
- data.tar.gz: 1ad96805142be1ac15bb329109e251c8c4170ce2c42f6fc409b7351899bb8ae283686241b414a7f1ff1bb08dc4b1b10f0ff59da2ad4e0d46f2e3c8e90f1dbf62
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 an experimental Ruby library with the goal to
18
- provide powerful object mapping capabilities without limiting the full power of
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
- * [Rails tutorial](http://rom-rb.org/tutorials/todo-app-with-rails/)
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
@@ -33,7 +33,8 @@ module ROM
33
33
  def initialize(command, err)
34
34
  super("command: #{command.inspect}; original message: #{err.message}")
35
35
  @command = command
36
- @original_error = original_error
36
+ @original_error = err
37
+ set_backtrace(err.backtrace)
37
38
  end
38
39
  end
39
40
 
@@ -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(EMPTY_FN) do |ops|
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, FILTER_EMPTY))
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, FILTER_EMPTY))
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
@@ -1,3 +1,3 @@
1
1
  module ROM
2
- VERSION = '0.8.0'.freeze
2
+ VERSION = '0.8.1'.freeze
3
3
  end
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.2', '>= 0.2.4'
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 Transproc(:accept_keys, [:name])
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 Transproc(:accept_keys, [:title, :user])
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 Transproc(:accept_keys, [:name, :task])
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 Transproc(:accept_keys, [:title, :user])
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 Transproc(:accept_keys, [:title, :user])
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 Transproc(:accept_keys, [:title, :user])
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
@@ -33,6 +33,10 @@ module Test
33
33
  end
34
34
  end
35
35
 
36
+ def T(*args)
37
+ ROM::Processor::Transproc::Functions[*args]
38
+ end
39
+
36
40
  RSpec.configure do |config|
37
41
  config.after do
38
42
  Test.remove_constants
@@ -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::Delete do
5
+ describe ROM::Memory::Commands::Create do
6
6
  include_context 'users and tasks'
7
7
 
8
- subject(:command) { ROM::Memory::Commands::Delete.build(users) }
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::Create do
5
+ describe ROM::Memory::Commands::Delete do
6
6
  include_context 'users and tasks'
7
7
 
8
- subject(:command) { ROM::Memory::Commands::Create.build(users) }
8
+ subject(:command) { ROM::Memory::Commands::Delete.build(users) }
9
9
 
10
10
  let(:users) { rom.relations[:users] }
11
11
 
@@ -7,7 +7,7 @@ describe ROM::Relation::Graph do
7
7
 
8
8
  it_behaves_like 'materializable relation' do
9
9
  let(:mapper) do
10
- Transproc(:combine, [[:tasks, name: :name]])
10
+ T(:combine, [[:tasks, name: :name]])
11
11
  end
12
12
 
13
13
  let(:relation) do
@@ -8,7 +8,7 @@ describe ROM::ArrayDataset do
8
8
  include ROM::ArrayDataset
9
9
 
10
10
  def self.row_proc
11
- Transproc(:symbolize_keys)
11
+ T(:symbolize_keys)
12
12
  end
13
13
  end
14
14
  end
@@ -8,7 +8,7 @@ describe ROM::EnumerableDataset do
8
8
  include ROM::EnumerableDataset
9
9
 
10
10
  def self.row_proc
11
- Transproc(:symbolize_keys)
11
+ T(:symbolize_keys)
12
12
  end
13
13
  end
14
14
  end
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.0
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-06-22 00:00:00.000000000 Z
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.2'
19
+ version: '0.3'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.2.4
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.2'
29
+ version: '0.3'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.2.4
32
+ version: 0.3.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: equalizer
35
35
  requirement: !ruby/object:Gem::Requirement