rom-rails 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -1
- data/CHANGELOG.md +10 -0
- data/README.md +11 -55
- data/lib/rom/model.rb +3 -1
- data/lib/rom/rails/controller_extension.rb +1 -1
- data/lib/rom/rails/railtie.rb +1 -1
- data/lib/rom/rails/version.rb +1 -1
- data/rom-rails.gemspec +1 -1
- data/spec/dummy/app/commands/users.rb +4 -0
- data/spec/dummy/spec/integration/user_commands_spec.rb +10 -1
- data/spec/dummy/spec/integration/user_model_mapping_spec.rb +1 -1
- data/spec/unit/model_spec.rb +23 -0
- metadata +11 -6
- data/.ruby-version +0 -1
- data/LICENSE.txt +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d21be75bbb9e3c79f408a7543e948cbbe5a2d48
|
4
|
+
data.tar.gz: 0c7bf6a32c50ceca32d4575f4840725f8b2d2ca6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e16b255e12b8b290652b9d9e19b8dcf585486f65544ee00ec91b537b969d485e035f64b6f8f38ac24c5b913913466dcba4d19221570274144cb2be08f359984e
|
7
|
+
data.tar.gz: f890b82c6a0b8c4b237db7a638ec31731f0e291c2a1ca800d80bc846a333adbcace7fd3b9e99f39af9085932f99dfb986d06a85bba79aa8c7480b278f1aeccae
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
2
4
|
bundler_args: --without yard guard benchmarks
|
3
5
|
env:
|
4
6
|
- CODECLIMATE_REPO_TOKEN=87c9080bda25bce8e63a294f99312345c144c0f6d5eedf400fd753356fbf7dcf
|
5
|
-
script: "RAILS_ENV=test rake app:db:schema:load app:spec"
|
7
|
+
script: "RAILS_ENV=test bundle exec rake app:db:schema:load app:spec"
|
6
8
|
rvm:
|
7
9
|
- 2.0
|
8
10
|
- 2.1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## v0.2.1 2015-01-07
|
2
|
+
|
3
|
+
### Changed
|
4
|
+
|
5
|
+
* input params uses virtus' `:strict` mode by default (stevehodgkiss)
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
|
9
|
+
* `rom` extension is now mixed into ActionController::Base which addresses #12 (solnic)
|
10
|
+
|
1
11
|
## v0.2.0 2014-12-31
|
2
12
|
|
3
13
|
### Added
|
data/README.md
CHANGED
@@ -14,66 +14,22 @@
|
|
14
14
|
[![Test Coverage](https://codeclimate.com/github/rom-rb/rom-rails/badges/coverage.svg)][codeclimate]
|
15
15
|
[![Inline docs](http://inch-ci.org/github/rom-rb/rom-rails.svg?branch=master)][inchpages]
|
16
16
|
|
17
|
-
Rails integration for [Ruby Object Mapper](https://github.com/rom-rb/rom)
|
17
|
+
Rails integration for [Ruby Object Mapper](https://github.com/rom-rb/rom) which
|
18
|
+
ships with:
|
18
19
|
|
19
|
-
|
20
|
+
* Params sanitizer/coercer extension
|
21
|
+
* Validation extension based on `ActiveModel`
|
22
|
+
* Relation generators
|
23
|
+
* Mapper generators
|
24
|
+
* Command generators
|
20
25
|
|
21
|
-
|
26
|
+
## Resources
|
22
27
|
|
23
|
-
|
24
|
-
gem 'rom'
|
25
|
-
gem 'rom-rails'
|
26
|
-
```
|
28
|
+
You can read more about ROM and Rails on the official website:
|
27
29
|
|
28
|
-
|
30
|
+
* [Introduction to ROM](http://rom-rb.org/introduction)
|
31
|
+
* [Rails tutorial](http://rom-rb.org/tutorials/rails)
|
29
32
|
|
30
|
-
Defining schema is only required for adapters that don't support inferring schema
|
31
|
-
automatically. This means if you're using `rom-sql` you don't have to define the schema.
|
32
|
-
In other cases the railtie expects the schema to be in `db/rom/schema.rb` which
|
33
|
-
is loaded before relations and mappers.
|
34
|
-
|
35
|
-
## Relations and mappers
|
36
|
-
|
37
|
-
The railtie automatically loads relations and mappers from `app/relations` and
|
38
|
-
`app/mappers` and finalizes the environment afterwards. During the booting process
|
39
|
-
rom's setup object is available via `Rails.application.config.rom.setup`.
|
40
|
-
|
41
|
-
## Relations in controllers
|
42
|
-
|
43
|
-
The recommended way of using relations in controllers is to specify which relations
|
44
|
-
are needed for particular actions using a DSL provided by the railtie:
|
45
|
-
|
46
|
-
``` ruby
|
47
|
-
class UsersController < ApplicationController
|
48
|
-
relation 'users.index', only: :index
|
49
|
-
relation 'users.by_name', only: :search, requires: :name
|
50
|
-
|
51
|
-
def index
|
52
|
-
render
|
53
|
-
end
|
54
|
-
|
55
|
-
def search
|
56
|
-
render :index
|
57
|
-
end
|
58
|
-
end
|
59
|
-
```
|
60
|
-
|
61
|
-
By doing this actions will have access to `users` which is also set as a helper
|
62
|
-
method making it available in the views.
|
63
|
-
|
64
|
-
This means **no database interaction will take place in the views or helpers**
|
65
|
-
as ROM materializes relations when "injecting" them into controller actions.
|
66
|
-
|
67
|
-
## Status
|
68
|
-
|
69
|
-
This project is still in beta state. For examples of usage please take a look
|
70
|
-
at `spec/dummy` app.
|
71
|
-
|
72
|
-
Proper documentation will be added once the interface is stable.
|
73
|
-
|
74
|
-
## Roadmap
|
75
|
-
|
76
|
-
Please refer to [issues](https://github.com/rom-rb/rom-rails/issues).
|
77
33
|
|
78
34
|
## Community
|
79
35
|
|
data/lib/rom/model.rb
CHANGED
@@ -35,9 +35,11 @@ module ROM
|
|
35
35
|
#
|
36
36
|
# @api public
|
37
37
|
module Params
|
38
|
+
VirtusModel = Virtus.model(strict: true, required: false)
|
39
|
+
|
38
40
|
def self.included(base)
|
39
41
|
base.class_eval do
|
40
|
-
include
|
42
|
+
include VirtusModel
|
41
43
|
include ActiveModel::Validations
|
42
44
|
include ActiveModel::Conversion
|
43
45
|
end
|
data/lib/rom/rails/railtie.rb
CHANGED
data/lib/rom/rails/version.rb
CHANGED
data/rom-rails.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
20
|
spec.add_runtime_dependency 'rom', '~> 0.5', '>= 0.5.0'
|
21
|
-
spec.add_runtime_dependency 'virtus', '~> 1.0'
|
21
|
+
spec.add_runtime_dependency 'virtus', '~> 1.0', '>= 1.0.4'
|
22
22
|
spec.add_runtime_dependency 'railties', ['>= 3.0', '< 5.0']
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler"
|
@@ -7,7 +7,7 @@ describe 'User commands' do
|
|
7
7
|
it 'inserts user with valid params' do
|
8
8
|
result = users.try { create(name: 'Jade') }
|
9
9
|
|
10
|
-
expect(result.value).to eql(id:
|
10
|
+
expect(result.value).to eql(id: result.value[:id], name: 'Jade')
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'returns error if params are not valid' do
|
@@ -18,4 +18,13 @@ describe 'User commands' do
|
|
18
18
|
expect(result.error.messages[:name]).to include("can't be blank")
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
describe 'delete' do
|
23
|
+
it 'deletes record' do
|
24
|
+
users.create.call(name: 'Piotr')
|
25
|
+
result = users.try { delete(:by_name, 'Piotr') }
|
26
|
+
|
27
|
+
expect(result.error).to be(nil)
|
28
|
+
end
|
29
|
+
end
|
21
30
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ROM::Model::Params do
|
4
|
+
let(:klass) {
|
5
|
+
Class.new do
|
6
|
+
include ROM::Model::Params
|
7
|
+
|
8
|
+
attribute :name, String
|
9
|
+
end
|
10
|
+
}
|
11
|
+
|
12
|
+
it 'fails loudly when given an incorrect type' do
|
13
|
+
expect {
|
14
|
+
klass.new(name: [])
|
15
|
+
}.to raise_error(Virtus::CoercionError, /name/)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'does not fail on nil or missing attributes' do
|
19
|
+
expect {
|
20
|
+
klass.new
|
21
|
+
}.not_to raise_error
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.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:
|
11
|
+
date: 2015-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rom
|
@@ -37,6 +37,9 @@ dependencies:
|
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '1.0'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.0.4
|
40
43
|
type: :runtime
|
41
44
|
prerelease: false
|
42
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -44,6 +47,9 @@ dependencies:
|
|
44
47
|
- - "~>"
|
45
48
|
- !ruby/object:Gem::Version
|
46
49
|
version: '1.0'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.0.4
|
47
53
|
- !ruby/object:Gem::Dependency
|
48
54
|
name: railties
|
49
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,12 +122,10 @@ files:
|
|
116
122
|
- ".gitignore"
|
117
123
|
- ".rspec"
|
118
124
|
- ".rubocop.yml"
|
119
|
-
- ".ruby-version"
|
120
125
|
- ".travis.yml"
|
121
126
|
- CHANGELOG.md
|
122
127
|
- Gemfile
|
123
128
|
- LICENSE
|
124
|
-
- LICENSE.txt
|
125
129
|
- README.md
|
126
130
|
- Rakefile
|
127
131
|
- lib/generators/rom.rb
|
@@ -199,6 +203,7 @@ files:
|
|
199
203
|
- spec/lib/generators/mapper_generator_spec.rb
|
200
204
|
- spec/lib/generators/relation_generator_spec.rb
|
201
205
|
- spec/spec_helper.rb
|
206
|
+
- spec/unit/model_spec.rb
|
202
207
|
homepage: http://rom-rb.org
|
203
208
|
licenses:
|
204
209
|
- MIT
|
@@ -219,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
224
|
version: '0'
|
220
225
|
requirements: []
|
221
226
|
rubyforge_project:
|
222
|
-
rubygems_version: 2.
|
227
|
+
rubygems_version: 2.4.5
|
223
228
|
signing_key:
|
224
229
|
specification_version: 4
|
225
230
|
summary: Integrate Ruby Object Mapper with Rails
|
@@ -284,4 +289,4 @@ test_files:
|
|
284
289
|
- spec/lib/generators/mapper_generator_spec.rb
|
285
290
|
- spec/lib/generators/relation_generator_spec.rb
|
286
291
|
- spec/spec_helper.rb
|
287
|
-
|
292
|
+
- spec/unit/model_spec.rb
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.1
|
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
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.
|