rom-rails 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8841ce1317e0b85ca6e9df4bfcdbc30b0a3a545f
4
- data.tar.gz: 2f9a18f403fcaf8bda465616937ebfcda0464ec7
3
+ metadata.gz: 9d21be75bbb9e3c79f408a7543e948cbbe5a2d48
4
+ data.tar.gz: 0c7bf6a32c50ceca32d4575f4840725f8b2d2ca6
5
5
  SHA512:
6
- metadata.gz: bac7c987bad0abc06d290b68ebb7078330febd35ff76571cd0e4f240c89c4a494e67dcc519e860b2bae7552f6876691eecb641186b99c08178745da43e881293
7
- data.tar.gz: 2d57f131b6515a8176c05fc7574b82aee3e8129385b026c8fa0accf296637427d5ae3e882336867eca2f84d379643e4661afb3d4ff94358e03a85b9a7d946d73
6
+ metadata.gz: e16b255e12b8b290652b9d9e19b8dcf585486f65544ee00ec91b537b969d485e035f64b6f8f38ac24c5b913913466dcba4d19221570274144cb2be08f359984e
7
+ data.tar.gz: f890b82c6a0b8c4b237db7a638ec31731f0e291c2a1ca800d80bc846a333adbcace7fd3b9e99f39af9085932f99dfb986d06a85bba79aa8c7480b278f1aeccae
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .ruby-version
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
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
- ## Installation and setup
20
+ * Params sanitizer/coercer extension
21
+ * Validation extension based on `ActiveModel`
22
+ * Relation generators
23
+ * Mapper generators
24
+ * Command generators
20
25
 
21
- In your Gemfile:
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
- ## Schema
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 Virtus.model
42
+ include VirtusModel
41
43
  include ActiveModel::Validations
42
44
  include ActiveModel::Conversion
43
45
  end
@@ -8,7 +8,7 @@ module ROM
8
8
  end
9
9
 
10
10
  def rom
11
- ::Rails.application.config.rom.env
11
+ ROM.env
12
12
  end
13
13
 
14
14
  module ClassExtensions
@@ -45,7 +45,7 @@ module ROM
45
45
  app.config.rom.setup!
46
46
  app.config.rom.load!
47
47
  app.config.rom.finalize!
48
- ApplicationController.send(:include, ControllerExtension)
48
+ ActionController::Base.send(:include, ControllerExtension)
49
49
  end
50
50
  end
51
51
 
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module Rails
3
- VERSION = "0.2.0".freeze
3
+ VERSION = "0.2.1".freeze
4
4
  end
5
5
  end
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"
@@ -4,4 +4,8 @@ ROM.commands(:users) do
4
4
  validator UserValidator
5
5
  result :one
6
6
  end
7
+
8
+ define(:delete) do
9
+ result :one
10
+ end
7
11
  end
@@ -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: 1, name: 'Jade')
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
@@ -6,7 +6,7 @@ describe 'User model mapping' do
6
6
  let(:users) { rom.read(:users) }
7
7
 
8
8
  before do
9
- rom.command(:users).create.call(name: 'Piotr')
9
+ rom.command(:users).try { create(name: 'Piotr') }
10
10
  end
11
11
 
12
12
  it 'works' do
@@ -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.0
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: 2014-12-31 00:00:00.000000000 Z
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.2.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
- has_rdoc:
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.