rom-rails 0.9.0 → 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +8 -5
- data/lib/generators/rom/commands/templates/create.rb.erb +5 -7
- data/lib/generators/rom/commands/templates/update.rb.erb +5 -7
- data/lib/generators/rom/relation/templates/relation.rb.erb +6 -4
- data/lib/rom-rails.rb +0 -1
- data/lib/rom/rails/configuration.rb +0 -2
- data/lib/rom/rails/version.rb +1 -1
- data/rom-rails.gemspec +2 -4
- data/spec/dummy/app/commands/create_user.rb +10 -0
- data/spec/dummy/app/commands/update_user.rb +9 -0
- data/spec/dummy/app/controllers/users_controller.rb +12 -8
- data/spec/dummy/app/forms/user_form.rb +29 -9
- data/spec/dummy/app/mappers/task_mapper.rb +1 -1
- data/spec/dummy/app/mappers/user_mapper.rb +1 -1
- data/spec/dummy/app/models/user.rb +1 -1
- data/spec/dummy/app/relations/dummy_relation.rb +2 -1
- data/spec/dummy/app/relations/tasks.rb +2 -0
- data/spec/dummy/app/relations/users.rb +2 -0
- data/spec/dummy/lib/rom/test_adapter.rb +1 -1
- data/spec/features/users_spec.rb +1 -3
- data/spec/integration/activerecord_setup.rb +1 -1
- data/spec/integration/initializer_spec.rb +1 -3
- data/spec/integration/logger_spec.rb +1 -3
- data/spec/integration/user_commands_spec.rb +7 -7
- data/spec/integration/user_model_mapping_spec.rb +2 -4
- data/spec/lib/active_record/configuration_spec.rb +1 -2
- data/spec/lib/generators/commands_generator_spec.rb +7 -17
- data/spec/lib/generators/mapper_generator_spec.rb +1 -3
- data/spec/lib/generators/relation_generator_spec.rb +4 -8
- data/spec/lib/generators/repository_generator_spec.rb +1 -3
- data/spec/spec_helper.rb +1 -1
- metadata +12 -61
- data/lib/generators/rom/form/templates/base_form.rb.erb +0 -17
- data/lib/generators/rom/form/templates/edit_form.rb.erb +0 -20
- data/lib/generators/rom/form/templates/new_form.rb.erb +0 -20
- data/lib/generators/rom/form_generator.rb +0 -47
- data/lib/rom/rails/model/form.rb +0 -173
- data/lib/rom/rails/model/form/class_interface.rb +0 -457
- data/lib/rom/rails/model/form/error_proxy.rb +0 -53
- data/spec/dummy/app/forms/new_user_form.rb +0 -13
- data/spec/dummy/app/forms/update_user_form.rb +0 -11
- data/spec/integration/form_with_injected_commands_spec.rb +0 -37
- data/spec/integration/new_user_form_spec.rb +0 -19
- data/spec/lib/generators/form_generator_spec.rb +0 -140
- data/spec/unit/form_spec.rb +0 -366
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15ad5132adeb785fc04f97c8090c43adb48c41d0
|
4
|
+
data.tar.gz: fe847edfa4122b433dee45eea46b2c3795b9ccfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5348f013e4afbadb3d90b85391253d7ecd30737499b0c2a71ba3c330e643b87db80a109a0ebfe7986ec9375a09aa3e988e8b8e39ac3532099ebef5385ed67612
|
7
|
+
data.tar.gz: 70386c85f3322ddd242f5043eb3a37c8fe737b8065afbb5fcf578d4b46de90e5ef00316766533762d4e8e49f088b276eb4635737343c5a2b93dc0dc3d5047a0c
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## HEAD
|
2
|
+
|
3
|
+
### Changed
|
4
|
+
|
5
|
+
* Updated to work with ROM 4.0.beta (cflipse)
|
6
|
+
|
7
|
+
### Removed
|
8
|
+
|
9
|
+
* remove ROM::Model::Form (cflipse)
|
10
|
+
* remove form generator (cflipse)
|
11
|
+
* remove deprecated `config.repositories` method (cflipse)
|
12
|
+
* No longer depends on `rom-model` gem (cflipse)
|
13
|
+
* No longer depends on `charlatan` gem (artofhuman)
|
14
|
+
|
1
15
|
## v0.9.0 2017-01-30
|
2
16
|
|
3
17
|
### Added
|
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
RAILS_VERSION = ENV.fetch("RAILS_VERSION", '5.
|
5
|
+
RAILS_VERSION = ENV.fetch("RAILS_VERSION", '5.1.0').freeze
|
6
6
|
|
7
7
|
%w(railties actionview actionpack activerecord).each do |name|
|
8
8
|
gem name, "~> #{RAILS_VERSION}"
|
@@ -10,11 +10,14 @@ end
|
|
10
10
|
|
11
11
|
gem 'sqlite3', platforms: [:mri, :rbx]
|
12
12
|
gem 'byebug', platforms: :mri
|
13
|
-
|
13
|
+
|
14
|
+
gem 'rom', git: 'https://github.com/rom-rb/rom', branch: 'master' do
|
15
|
+
gem 'rom-core'
|
16
|
+
gem 'rom-mapper'
|
17
|
+
gem 'rom-repository', group: :tools
|
18
|
+
end
|
19
|
+
|
14
20
|
gem 'rom-sql', github: 'rom-rb/rom-sql', branch: 'master'
|
15
|
-
gem 'rom-model', github: 'rom-rb/rom-model', branch: 'master'
|
16
|
-
gem 'rom-repository', github: 'rom-rb/rom-repository', branch: 'master'
|
17
|
-
gem 'rom-mapper', github: 'rom-rb/rom-mapper', branch: 'master'
|
18
21
|
|
19
22
|
platforms :jruby do
|
20
23
|
gem 'jdbc-sqlite3'
|
@@ -3,11 +3,9 @@ class Create<%= model_name %> < ROM::Commands::Create<%= "[:#{adapter}]" %>
|
|
3
3
|
register_as :create
|
4
4
|
result :one
|
5
5
|
|
6
|
-
|
7
|
-
#
|
8
|
-
|
9
|
-
#
|
10
|
-
|
11
|
-
# tuple.merge(created_at: time, updated_at: time)
|
12
|
-
# end
|
6
|
+
<% if adapter.to_sym == :sql -%>
|
7
|
+
# set Timestamp plugin
|
8
|
+
# use :timestamps
|
9
|
+
# timestamp :created_at, :updated_at
|
10
|
+
<% end -%>
|
13
11
|
end
|
@@ -3,11 +3,9 @@ class Update<%= model_name %> < ROM::Commands::Update<%= "[:#{adapter}]" %>
|
|
3
3
|
register_as :update
|
4
4
|
result :one
|
5
5
|
|
6
|
-
|
7
|
-
#
|
8
|
-
|
9
|
-
#
|
10
|
-
|
11
|
-
# tuple.merge(created_at: time)
|
12
|
-
# end
|
6
|
+
<% if adapter.to_sym == :sql -%>
|
7
|
+
# set Timestamp plugin
|
8
|
+
# use :timestamps
|
9
|
+
# timestamp :updated_at
|
10
|
+
<% end -%>
|
13
11
|
end
|
@@ -2,12 +2,14 @@ class <%= class_name %>Relation < ROM::Relation<%= "[:#{adapter}]" %>
|
|
2
2
|
<% if gateway -%>
|
3
3
|
gateway :<%= gateway %>
|
4
4
|
<% else -%>
|
5
|
-
|
5
|
+
gateway :default
|
6
6
|
<% end -%>
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
<% if register_as != dataset -%>
|
9
|
+
schema(:<%= dataset %>, as: :<%= register_as %>, infer: true)
|
10
|
+
<% else -%>
|
11
|
+
schema(:<%= dataset %>, infer: true)
|
12
|
+
<% end -%>
|
11
13
|
|
12
14
|
# define your methods here ie:
|
13
15
|
#
|
data/lib/rom-rails.rb
CHANGED
data/lib/rom/rails/version.rb
CHANGED
data/rom-rails.gemspec
CHANGED
@@ -17,12 +17,10 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_runtime_dependency 'rom', '~>
|
21
|
-
spec.add_runtime_dependency 'rom-model', '~> 0.3'
|
20
|
+
spec.add_runtime_dependency 'rom', '~> 4.0.0.beta'
|
22
21
|
spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
|
23
|
-
spec.add_runtime_dependency 'dry-core', '~> 0.
|
22
|
+
spec.add_runtime_dependency 'dry-core', '~> 0.3'
|
24
23
|
spec.add_runtime_dependency 'addressable', '~> 2.3'
|
25
|
-
spec.add_runtime_dependency 'charlatan', '~> 0.1'
|
26
24
|
spec.add_runtime_dependency 'railties', '>= 3.0', '< 6.0'
|
27
25
|
|
28
26
|
spec.add_development_dependency "rom-repository"
|
@@ -4,23 +4,24 @@ class UsersController < ApplicationController
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def index
|
7
|
-
render :index, locals: { users: rom.
|
7
|
+
render :index, locals: { users: rom.relations[:users].map_with(:user) }
|
8
8
|
end
|
9
9
|
|
10
10
|
def search
|
11
11
|
render :index, locals: {
|
12
|
-
users: rom.
|
12
|
+
users: rom.relations[:users].map_with(:user).by_name(params[:name])
|
13
13
|
}
|
14
14
|
end
|
15
15
|
|
16
16
|
def new
|
17
|
-
render :new, locals: { user:
|
17
|
+
render :new, locals: { user: UserForm.new }
|
18
18
|
end
|
19
19
|
|
20
20
|
def create
|
21
|
-
user_form =
|
21
|
+
user_form = UserForm.new(params[:user].permit!)
|
22
22
|
|
23
|
-
if user_form.
|
23
|
+
if user_form.valid?
|
24
|
+
rom.commands[:users].create.call(user_form.to_h)
|
24
25
|
redirect_to :users
|
25
26
|
else
|
26
27
|
render :new, locals: { user: user_form }
|
@@ -28,15 +29,18 @@ class UsersController < ApplicationController
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def edit
|
31
|
-
|
32
|
+
data = rom.relations[:users].where(id: params[:id]).one
|
33
|
+
user_form = UserForm.new(data)
|
32
34
|
|
33
35
|
render :edit, locals: { user: user_form }
|
34
36
|
end
|
35
37
|
|
36
38
|
def update
|
37
|
-
|
39
|
+
data = rom.relations[:users].where(id: params[:id]).one
|
40
|
+
user_form = UserForm.new(data).merge(params[:user].permit!)
|
38
41
|
|
39
|
-
if user_form.
|
42
|
+
if user_form.valid?
|
43
|
+
rom.commands[:users].update.by_id(params[:id]).call(user_form.to_h)
|
40
44
|
redirect_to :users
|
41
45
|
else
|
42
46
|
render :edit, locals: { user: user_form }
|
@@ -1,15 +1,35 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'active_model'
|
2
|
+
class UserForm
|
3
|
+
include ActiveModel::Model
|
4
|
+
include ActiveModel::Validations
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
attr_accessor :name, :email, :id
|
7
|
+
|
8
|
+
validates :name, :email, presence: true
|
9
|
+
|
10
|
+
def initialize(params = {})
|
11
|
+
@id = params[:id]
|
12
|
+
@name = params[:name]
|
13
|
+
@email = params[:email]
|
7
14
|
end
|
8
15
|
|
9
|
-
|
10
|
-
|
16
|
+
def to_h
|
17
|
+
{ name: name, email: email }
|
18
|
+
end
|
11
19
|
|
12
|
-
|
13
|
-
|
20
|
+
def merge(input)
|
21
|
+
@name = input[:name]
|
22
|
+
@email = input[:email]
|
23
|
+
|
24
|
+
self
|
14
25
|
end
|
26
|
+
|
27
|
+
def persisted?
|
28
|
+
!!id
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.model_name
|
32
|
+
ActiveModel::Name.new(User)
|
33
|
+
end
|
34
|
+
|
15
35
|
end
|
data/spec/features/users_spec.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe 'User commands' do
|
4
|
-
subject(:users) { rom.command(:users) }
|
1
|
+
RSpec.describe 'User commands' do
|
2
|
+
subject(:users) { rom.commands[:users] }
|
5
3
|
|
6
4
|
describe 'delete' do
|
7
5
|
it 'deletes record' do
|
8
|
-
rom.relations
|
9
|
-
|
6
|
+
relation = rom.relations[:users]
|
7
|
+
relation.insert(name: 'Piotr', email: 'piotr@test.com')
|
10
8
|
|
11
|
-
expect
|
9
|
+
expect{
|
10
|
+
users.delete.by_name('Piotr').call
|
11
|
+
}.to change(relation, :count).by(-1)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -1,9 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe 'User model mapping' do
|
1
|
+
RSpec.describe 'User model mapping' do
|
4
2
|
let(:rom) { ROM.env }
|
5
3
|
|
6
|
-
let(:users) { rom.
|
4
|
+
let(:users) { rom.relations[:users].map_with(:user) }
|
7
5
|
|
8
6
|
before do
|
9
7
|
rom.relations.users.insert(name: 'Piotr', email: 'piotr@test.com')
|
@@ -1,8 +1,6 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
require 'generators/rom/commands_generator'
|
4
2
|
|
5
|
-
describe ROM::Generators::CommandsGenerator do
|
3
|
+
RSpec.describe ROM::Generators::CommandsGenerator do
|
6
4
|
destination File.expand_path('../../../../tmp', __FILE__)
|
7
5
|
|
8
6
|
before(:each) do
|
@@ -24,13 +22,9 @@ describe ROM::Generators::CommandsGenerator do
|
|
24
22
|
register_as :create
|
25
23
|
result :one
|
26
24
|
|
27
|
-
#
|
28
|
-
#
|
29
|
-
|
30
|
-
# def timestamp(tuple)
|
31
|
-
# time = Time.current
|
32
|
-
# tuple.merge(created_at: time, updated_at: time)
|
33
|
-
# end
|
25
|
+
# set Timestamp plugin
|
26
|
+
# use :timestamps
|
27
|
+
# timestamp :created_at, :updated_at
|
34
28
|
end
|
35
29
|
CONTENT
|
36
30
|
end
|
@@ -42,13 +36,9 @@ describe ROM::Generators::CommandsGenerator do
|
|
42
36
|
register_as :update
|
43
37
|
result :one
|
44
38
|
|
45
|
-
#
|
46
|
-
#
|
47
|
-
|
48
|
-
# def timestamp(tuple)
|
49
|
-
# time = Time.current
|
50
|
-
# tuple.merge(created_at: time)
|
51
|
-
# end
|
39
|
+
# set Timestamp plugin
|
40
|
+
# use :timestamps
|
41
|
+
# timestamp :updated_at
|
52
42
|
end
|
53
43
|
CONTENT
|
54
44
|
end
|