rails_ops 1.1.23 → 1.1.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rubocop.yml +17 -0
- data/.github/workflows/ruby.yml +37 -7
- data/.gitignore +2 -0
- data/.rubocop.yml +1 -0
- data/Appraisals +19 -0
- data/CHANGELOG.md +24 -1
- data/LICENSE +1 -1
- data/README.md +137 -16
- data/Rakefile +4 -0
- data/VERSION +1 -1
- data/gemfiles/rails_5.1.gemfile +7 -0
- data/gemfiles/rails_5.2.gemfile +7 -0
- data/gemfiles/rails_6.0.gemfile +7 -0
- data/gemfiles/rails_6.1.gemfile +7 -0
- data/gemfiles/rails_7.0.gemfile +7 -0
- data/lib/generators/operation/USAGE +21 -0
- data/lib/generators/operation/operation_generator.rb +64 -0
- data/lib/generators/operation/templates/controller.erb +56 -0
- data/lib/generators/operation/templates/create.erb +15 -0
- data/lib/generators/operation/templates/destroy.erb +13 -0
- data/lib/generators/operation/templates/load.erb +13 -0
- data/lib/generators/operation/templates/update.erb +16 -0
- data/lib/generators/operation/templates/view.erb +0 -0
- data/lib/rails_ops/model_mixins/sti_fixes.rb +17 -0
- data/lib/rails_ops/model_mixins/virtual_attributes/virtual_column_wrapper.rb +4 -0
- data/lib/rails_ops/model_mixins.rb +1 -0
- data/lib/rails_ops.rb +1 -0
- data/rails_ops.gemspec +14 -6
- data/test/dummy/app/models/animal.rb +1 -0
- data/test/dummy/app/models/bird.rb +1 -0
- data/test/dummy/app/models/cat.rb +1 -0
- data/test/dummy/app/models/dog.rb +1 -0
- data/test/dummy/app/models/flower.rb +7 -0
- data/test/dummy/app/models/nightingale.rb +1 -0
- data/test/dummy/app/models/phoenix.rb +1 -0
- data/test/dummy/config/application.rb +13 -2
- data/test/dummy/config/environments/test.rb +1 -1
- data/test/dummy/config/initializers/backtrace_silencers.rb +1 -1
- data/test/dummy/db/schema.rb +8 -0
- data/test/test_helper.rb +2 -0
- data/test/unit/rails_ops/generators/operation_generator_test.rb +254 -0
- data/test/unit/rails_ops/operation/model/create_test.rb +16 -0
- data/test/unit/rails_ops/operation/model/sti_test.rb +70 -0
- data/test/unit/rails_ops/operation/model/update_test.rb +71 -0
- metadata +99 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bcce101893137c4a67443fb2f0c056695a9f31d9eddd4d8db480e2e27abb004
|
4
|
+
data.tar.gz: 360264275974a50bf59bde14c29ea5a10192d35bc7c983829a190b56aa4bc853
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3334b17bf543eb8168f13388a822e3572c9a6bb4522cc8db8d27755ffda18cccaba4a7283efc21e8d4da3bd5c5e2ab64d7eef2c5ad7478aef57b432dd23f06d
|
7
|
+
data.tar.gz: 87e7d4cc99de70f5287f1c639b9607dfac59a8fcf492225fbc3956f49f2f7f372724eb153dd9016cc2927d9e5116a0522531e681fcd577314118ecda484f7393
|
@@ -0,0 +1,17 @@
|
|
1
|
+
name: Rubocop check
|
2
|
+
on: push
|
3
|
+
|
4
|
+
jobs:
|
5
|
+
verify:
|
6
|
+
name: Test
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v1
|
11
|
+
- name: Set up Ruby
|
12
|
+
uses: ruby/setup-ruby@v1
|
13
|
+
with:
|
14
|
+
ruby-version: 3.0.1
|
15
|
+
bundler-cache: true
|
16
|
+
- name: Run rubocop
|
17
|
+
run: bundle exec rubocop
|
data/.github/workflows/ruby.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
name:
|
1
|
+
name: Unit tests
|
2
2
|
|
3
3
|
on:
|
4
4
|
push:
|
@@ -12,16 +12,46 @@ jobs:
|
|
12
12
|
strategy:
|
13
13
|
fail-fast: false
|
14
14
|
matrix:
|
15
|
-
|
16
|
-
|
15
|
+
include:
|
16
|
+
- rails-version: '5.1'
|
17
|
+
ruby-version: '2.3.0'
|
18
|
+
- rails-version: '5.1'
|
19
|
+
ruby-version: '2.5.1'
|
20
|
+
- rails-version: '5.2'
|
21
|
+
ruby-version: '2.3.0'
|
22
|
+
- rails-version: '5.2'
|
23
|
+
ruby-version: '2.5.1'
|
24
|
+
- rails-version: '5.2'
|
25
|
+
ruby-version: '2.6.2'
|
26
|
+
- rails-version: '6.0'
|
27
|
+
ruby-version: '2.5.1'
|
28
|
+
- rails-version: '6.0'
|
29
|
+
ruby-version: '2.6.2'
|
30
|
+
- rails-version: '6.0'
|
31
|
+
ruby-version: '2.7.1'
|
32
|
+
- rails-version: '6.1'
|
33
|
+
ruby-version: '2.5.1'
|
34
|
+
- rails-version: '6.1'
|
35
|
+
ruby-version: '2.6.2'
|
36
|
+
- rails-version: '6.1'
|
37
|
+
ruby-version: '2.7.1'
|
38
|
+
- rails-version: '6.1'
|
39
|
+
ruby-version: '3.0.1'
|
40
|
+
- rails-version: '7.0'
|
41
|
+
ruby-version: '2.7.1'
|
42
|
+
- rails-version: '7.0'
|
43
|
+
ruby-version: '3.0.1'
|
44
|
+
- rails-version: '7.0'
|
45
|
+
ruby-version: '3.1.0'
|
46
|
+
name: Test against Ruby ${{ matrix.ruby-version }} / Rails ${{ matrix.rails-version }}
|
47
|
+
env:
|
48
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails-version }}.gemfile
|
17
49
|
steps:
|
18
50
|
- uses: actions/checkout@v2
|
19
|
-
- name: Set up Ruby
|
51
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
20
52
|
uses: ruby/setup-ruby@v1
|
21
53
|
with:
|
22
54
|
ruby-version: ${{ matrix.ruby-version }}
|
23
55
|
bundler-cache: true
|
24
56
|
- name: Run rake tests
|
25
|
-
run: bundle exec rake
|
26
|
-
- name: Run rubocop
|
27
|
-
run: bundle exec rubocop
|
57
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/Appraisals
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
appraise "rails-7.0" do
|
2
|
+
gem "rails", "~> 7.0.1"
|
3
|
+
end
|
4
|
+
|
5
|
+
appraise "rails-6.1" do
|
6
|
+
gem "rails", "~> 6.1.4"
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise "rails-6.0" do
|
10
|
+
gem "rails", "~> 6.0.4"
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise "rails-5.2" do
|
14
|
+
gem "rails", "~> 5.2.6"
|
15
|
+
end
|
16
|
+
|
17
|
+
appraise "rails-5.1" do
|
18
|
+
gem "rails", "~> 5.1.7"
|
19
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,29 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 1.1.
|
3
|
+
## 1.1.27 (2022-02-15)
|
4
|
+
|
5
|
+
* Add `module` option to `operation` generator
|
6
|
+
|
7
|
+
## 1.1.26 (2022-01-18)
|
8
|
+
|
9
|
+
* #25: Add test matrix for unit tests
|
10
|
+
|
11
|
+
* Add compatibility for Rails 7 and Ruby 3.1.0
|
12
|
+
|
13
|
+
## 1.1.25 (2022-01-17)
|
14
|
+
|
15
|
+
* #24: Add generator `operation` that generates a controller, operations and empty
|
16
|
+
view files
|
17
|
+
|
18
|
+
## 1.1.24 (2021-11-24)
|
19
|
+
|
20
|
+
* Add support for STI in model operations
|
21
|
+
|
22
|
+
## 1.1.23 (2021-11-01)
|
23
|
+
|
24
|
+
* No changes to previous release
|
25
|
+
|
26
|
+
## 1.1.22 (2021-11-01)
|
4
27
|
|
5
28
|
* Add support for lazy model authorization
|
6
29
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
[![
|
1
|
+
[![Unit tests](https://github.com/sitrox/rails_ops/actions/workflows/ruby.yml/badge.svg)](https://github.com/sitrox/rails_ops/actions/workflows/ruby.yml)
|
2
|
+
[![Rubocop check](https://github.com/sitrox/rails_ops/actions/workflows/rubocop.yml/badge.svg)](https://github.com/sitrox/rails_ops/actions/workflows/rubocop.yml)
|
2
3
|
[![Gem Version](https://badge.fury.io/rb/rails_ops.svg)](https://badge.fury.io/rb/rails_ops)
|
3
4
|
|
4
5
|
rails_ops
|
@@ -22,9 +23,21 @@ Requirements & Installation
|
|
22
23
|
|
23
24
|
### Requirements
|
24
25
|
|
25
|
-
- RailsOps only works with Rails applications
|
26
|
-
|
27
|
-
|
26
|
+
- RailsOps only works with Rails applications, with the following Rails versions being tested in the CI:
|
27
|
+
* Rails 5.1.x
|
28
|
+
* Rails 5.2.x
|
29
|
+
* Rails 6.0.x
|
30
|
+
* Rails 6.1.x
|
31
|
+
* Rails 7.0.x
|
32
|
+
- Additionally, the following Ruby versions are covered by our unit tests:
|
33
|
+
* 2.3.0
|
34
|
+
* 2.5.1
|
35
|
+
* 2.6.2
|
36
|
+
* 2.7.1
|
37
|
+
* 3.0.1
|
38
|
+
* 3.1.0
|
39
|
+
- Please see the [unit test workflow](https://github.com/sitrox/rails_ops/actions/workflows/ruby.yml) for the combinations of the Rails & Ruby versions, as only compatible versions are tested with each other.
|
40
|
+
- Prior Rails and Ruby versions may be supported but they are not tested in the CI.
|
28
41
|
- Rails Ops' model operations require ActiveRecord but are database / adapter
|
29
42
|
agnostic
|
30
43
|
|
@@ -54,15 +67,16 @@ Requirements & Installation
|
|
54
67
|
following inside of the `Application` class within your
|
55
68
|
`config/application.rb`:
|
56
69
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
70
|
+
```ruby
|
71
|
+
app_operations = "#{Rails.root}/app/operations"
|
72
|
+
ActiveSupport::Dependencies.autoload_paths.delete(app_operations)
|
73
|
+
|
74
|
+
module Operations; end
|
75
|
+
loader = Rails.autoloaders.main
|
76
|
+
loader.push_dir(app_operations, namespace: Operations)
|
77
|
+
```
|
61
78
|
|
62
|
-
|
63
|
-
# that will run when loaded.
|
64
|
-
config.paths.add 'lib', eager_load: true
|
65
|
-
```
|
79
|
+
Taken from [this github issues comment](https://github.com/rails/rails/issues/40126#issuecomment-816275285).
|
66
80
|
|
67
81
|
Operation Basics
|
68
82
|
----------------
|
@@ -1194,8 +1208,8 @@ sensible default. See the respective class' source code for details.
|
|
1194
1208
|
In case of operations inheriting from `RailsOps::Operation::Model::Update`, you
|
1195
1209
|
can specify the `model_authorization_action` to be `lazy`, meaning that it will
|
1196
1210
|
only be checked when *performing* the operation, but not on initialization. This
|
1197
|
-
can be useful for displaying readonly forms to users which
|
1198
|
-
|
1211
|
+
can be useful for displaying readonly forms to users which have read-permissions
|
1212
|
+
only:
|
1199
1213
|
|
1200
1214
|
```ruby
|
1201
1215
|
class Operations::User::Update < RailsOps::Operation::Model::Update
|
@@ -1204,7 +1218,7 @@ class Operations::User::Update < RailsOps::Operation::Model::Update
|
|
1204
1218
|
# This automatically calls `authorize_model! :read`. Because it is set to be
|
1205
1219
|
# `lazy`, the authorization will only run when the operation is actually
|
1206
1220
|
# *performed*, and not already at instantiation.
|
1207
|
-
model_authorization_action :
|
1221
|
+
model_authorization_action :update, lazy: true
|
1208
1222
|
end
|
1209
1223
|
```
|
1210
1224
|
|
@@ -1270,6 +1284,34 @@ This block receives the params hash as it would be passed to the sub operation
|
|
1270
1284
|
and allows to modify it. The block's return value is then passed to the
|
1271
1285
|
sub-operation. Do not change the params inplace but instead return a new hash.
|
1272
1286
|
|
1287
|
+
### Single-table inheritance
|
1288
|
+
|
1289
|
+
Model operations also support STI models (Single Table Inheritance). However,
|
1290
|
+
there is the caviat that if you do extend your model in the operation (e.g.
|
1291
|
+
`model Animal do { ... }`), RailsOps automatically creates an anonymous subclass
|
1292
|
+
of the given class (e.g. `Animal`). Operations will always load / create models
|
1293
|
+
that are instances of this anonymous class.
|
1294
|
+
|
1295
|
+
Consider the following operation:
|
1296
|
+
|
1297
|
+
```ruby
|
1298
|
+
class Animal < ApplicationRecord; end
|
1299
|
+
class Bird < Animal; end
|
1300
|
+
class Mouse < Animal; end
|
1301
|
+
|
1302
|
+
class LoadAnimal < RailsOps::Operation::Model::Load
|
1303
|
+
model Animal do
|
1304
|
+
# Something
|
1305
|
+
end
|
1306
|
+
end
|
1307
|
+
|
1308
|
+
bird = Bird.create
|
1309
|
+
op_bird = LoadAnimal.new(id: bird.id)
|
1310
|
+
|
1311
|
+
bird.class # => Class "Bird", extending "Animal"
|
1312
|
+
op_bird.class # => Anonymous class, extending "Animal", not "Bird"
|
1313
|
+
```
|
1314
|
+
|
1273
1315
|
Record extension and virtual records
|
1274
1316
|
------------------------------------
|
1275
1317
|
|
@@ -1460,6 +1502,85 @@ sub-operations, see section *Calling sub-operations* for more information.
|
|
1460
1502
|
Operation Inheritance
|
1461
1503
|
---------------------
|
1462
1504
|
|
1505
|
+
Generators
|
1506
|
+
----------
|
1507
|
+
|
1508
|
+
RailsOps features a generator to easily create a structure for common CRUD-style
|
1509
|
+
constructs. The generator creates the CRUD operations, some empty view files, a
|
1510
|
+
controller and adds an entry in the routing file.
|
1511
|
+
|
1512
|
+
This is e.g. useful when adding a new model to an application, as the basic structure
|
1513
|
+
is usually rather similar.
|
1514
|
+
|
1515
|
+
### Usage
|
1516
|
+
|
1517
|
+
Run the generator using the `operation` generator, specifying the name of the
|
1518
|
+
operation class:
|
1519
|
+
|
1520
|
+
```ruby
|
1521
|
+
rails g operation User
|
1522
|
+
```
|
1523
|
+
|
1524
|
+
This will generate the following operations:
|
1525
|
+
|
1526
|
+
* `app/operations/user/load.rb`
|
1527
|
+
* `app/operations/user/create.rb`
|
1528
|
+
* `app/operations/user/update.rb`
|
1529
|
+
* `app/operations/user/destroy.rb`
|
1530
|
+
|
1531
|
+
as well as the controller `app/controllers/users_controller.rb` and the following
|
1532
|
+
empty view files:
|
1533
|
+
|
1534
|
+
* `app/views/users/index.html.haml`
|
1535
|
+
* `app/views/users/show.html.haml`
|
1536
|
+
* `app/views/users/new.html.haml`
|
1537
|
+
* `app/views/users/edit.html.haml`
|
1538
|
+
|
1539
|
+
It will also add the entry `resources :users` to the `config/routes.rb` file.
|
1540
|
+
|
1541
|
+
If you want to skip the controller, the views or the routes, you can do so using the
|
1542
|
+
flags:
|
1543
|
+
|
1544
|
+
* `--skip-controller`
|
1545
|
+
* `--skip-routes`
|
1546
|
+
* `--skip-views`
|
1547
|
+
|
1548
|
+
Or if you want to skip them all: `--only-operations`.
|
1549
|
+
|
1550
|
+
You can also add a module as a namespace, all generated files will be put in
|
1551
|
+
the proper subfolders and modules by using the `--module` option.
|
1552
|
+
|
1553
|
+
As an example:
|
1554
|
+
|
1555
|
+
```ruby
|
1556
|
+
rails g operation User --module Admin
|
1557
|
+
```
|
1558
|
+
|
1559
|
+
This will generate the following operations:
|
1560
|
+
|
1561
|
+
* `app/operations/admin/user/load.rb`
|
1562
|
+
* `app/operations/admin/user/create.rb`
|
1563
|
+
* `app/operations/admin/user/update.rb`
|
1564
|
+
* `app/operations/admin/user/destroy.rb`
|
1565
|
+
|
1566
|
+
These operations will be namespaced in the `Admin` module, e.g. `app/operations/admin/user/load.rb` will define `Operations::Admin::User::Load`.
|
1567
|
+
|
1568
|
+
It will also generate the controller `app/controllers/admin/users_controller.rb` and the following
|
1569
|
+
empty view files:
|
1570
|
+
|
1571
|
+
* `app/views/admin/users/index.html.haml`
|
1572
|
+
* `app/views/admin/users/show.html.haml`
|
1573
|
+
* `app/views/admin/users/new.html.haml`
|
1574
|
+
* `app/views/admin/users/edit.html.haml`
|
1575
|
+
|
1576
|
+
Both lower- and uppercase will generate the same files (i.e. `--module Admin` and `--module admin` are equal).
|
1577
|
+
|
1578
|
+
You can even nest the generated files deeper, `--module Admin::Foo` and `--module admin/foo` will both work.
|
1579
|
+
|
1580
|
+
Of course, at this point, the operations will need some adaptions, especially the
|
1581
|
+
[parameter schemas](#validating-params), and the controllers need the logic for the
|
1582
|
+
success and failure cases, as this depends on your application.
|
1583
|
+
|
1463
1584
|
Caveats
|
1464
1585
|
-------
|
1465
1586
|
|
@@ -1481,4 +1602,4 @@ Rails architecture.
|
|
1481
1602
|
|
1482
1603
|
## Copyright
|
1483
1604
|
|
1484
|
-
Copyright © 2017 -
|
1605
|
+
Copyright © 2017 - 2022 Sitrox. See `LICENSE` for further details.
|
data/Rakefile
CHANGED
@@ -15,11 +15,15 @@ task :gemspec do
|
|
15
15
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
16
|
spec.require_paths = ['lib']
|
17
17
|
|
18
|
+
spec.add_development_dependency 'appraisal'
|
18
19
|
spec.add_development_dependency 'bundler'
|
19
20
|
spec.add_development_dependency 'rake'
|
20
21
|
spec.add_development_dependency 'sqlite3'
|
21
22
|
spec.add_development_dependency 'cancancan'
|
23
|
+
spec.add_development_dependency 'pry'
|
24
|
+
spec.add_development_dependency 'colorize'
|
22
25
|
spec.add_development_dependency 'rubocop', '0.47.1'
|
26
|
+
spec.add_development_dependency 'sprockets-rails'
|
23
27
|
spec.add_dependency 'active_type', '>= 1.3.0'
|
24
28
|
spec.add_dependency 'minitest'
|
25
29
|
spec.add_dependency 'rails'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.27
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Description:
|
2
|
+
Generates CRUD operations, along with a controller, views and an entry in the route file
|
3
|
+
|
4
|
+
Example:
|
5
|
+
bin/rails generate operation User
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
app/operations/user/load.rb
|
9
|
+
app/operations/user/create.rb
|
10
|
+
app/operations/user/update.rb
|
11
|
+
app/operations/user/destroy.rb
|
12
|
+
|
13
|
+
app/controllers/users_controller.rb
|
14
|
+
|
15
|
+
app/views/users/index.html.haml
|
16
|
+
app/views/users/show.html.haml
|
17
|
+
app/views/users/new.html.haml
|
18
|
+
app/views/users/edit.html.haml
|
19
|
+
|
20
|
+
And add a routing entry:
|
21
|
+
resources :users
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class OperationGenerator < Rails::Generators::NamedBase
|
2
|
+
source_root File.expand_path('templates', __dir__)
|
3
|
+
|
4
|
+
class_option :skip_controller, type: :boolean, desc: "Don't add a controller."
|
5
|
+
class_option :skip_views, type: :boolean, desc: "Don't add the views."
|
6
|
+
class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
|
7
|
+
class_option :only_operations, type: :boolean, desc: 'Only add the operations. This is equal to specifying --skip-controller --skip-routes --skip-views'
|
8
|
+
class_option :module, type: :string, desc: 'Add the operations in a module, e.g. "Admin" results in namespacing everything in the Admin module'
|
9
|
+
|
10
|
+
def add_operations
|
11
|
+
@class_name = name.classify
|
12
|
+
@underscored_name = name.underscore
|
13
|
+
@underscored_pluralized_name = name.underscore.pluralize
|
14
|
+
|
15
|
+
operations_path = 'app/operations/'
|
16
|
+
|
17
|
+
if options[:module].present?
|
18
|
+
@module_name = options[:module].classify
|
19
|
+
@module_underscored_name = @module_name.underscore
|
20
|
+
|
21
|
+
operations_path += "#{@module_underscored_name}/"
|
22
|
+
end
|
23
|
+
|
24
|
+
operations_path += @underscored_name.to_s
|
25
|
+
|
26
|
+
template 'load.erb', "#{operations_path}/load.rb"
|
27
|
+
template 'create.erb', "#{operations_path}/create.rb"
|
28
|
+
template 'update.erb', "#{operations_path}/update.rb"
|
29
|
+
template 'destroy.erb', "#{operations_path}/destroy.rb"
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_controller
|
33
|
+
return if options[:skip_controller] || options[:only_operations]
|
34
|
+
|
35
|
+
controller_file_path = 'app/controllers/'
|
36
|
+
if @module_underscored_name.present?
|
37
|
+
controller_file_path += "#{@module_underscored_name}/"
|
38
|
+
end
|
39
|
+
controller_file_path += "#{@underscored_pluralized_name}_controller.rb"
|
40
|
+
@controller_name = "#{@class_name.pluralize}Controller"
|
41
|
+
|
42
|
+
template 'controller.erb', controller_file_path
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_views
|
46
|
+
return if options[:skip_views] || options[:only_operations]
|
47
|
+
|
48
|
+
views_folder = 'app/views/'
|
49
|
+
if @module_underscored_name.present?
|
50
|
+
views_folder += "#{@module_underscored_name}/"
|
51
|
+
end
|
52
|
+
views_folder += @underscored_pluralized_name.to_s
|
53
|
+
|
54
|
+
%w(index show new edit).each do |view|
|
55
|
+
template 'view.erb', "#{views_folder}/#{view}.html.haml"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_routes
|
60
|
+
return if options[:skip_routes] || options[:only_operations]
|
61
|
+
|
62
|
+
route "resources :#{@underscored_pluralized_name}"
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
<%
|
2
|
+
controller_code = <<-RUBY
|
3
|
+
class #{@controller_name} < ApplicationController
|
4
|
+
def index; end
|
5
|
+
|
6
|
+
def show
|
7
|
+
op Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Load
|
8
|
+
end
|
9
|
+
|
10
|
+
def new
|
11
|
+
op Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Create
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
if run Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Create
|
16
|
+
# handle successful case
|
17
|
+
else
|
18
|
+
# handle error case
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def edit
|
23
|
+
op Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Update
|
24
|
+
end
|
25
|
+
|
26
|
+
def update
|
27
|
+
if run Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Update
|
28
|
+
# handle successful case
|
29
|
+
else
|
30
|
+
# handle error case
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def destroy
|
35
|
+
if run Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Destroy
|
36
|
+
# handle successful case
|
37
|
+
else
|
38
|
+
# handle error case
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
RUBY
|
43
|
+
-%>
|
44
|
+
<% if @module_name.present? -%>
|
45
|
+
module <%= @module_name %>
|
46
|
+
<% controller_code.split("\n").each do |line| -%>
|
47
|
+
<% if line.blank? -%>
|
48
|
+
|
49
|
+
<% else -%>
|
50
|
+
<%= line %>
|
51
|
+
<% end -%>
|
52
|
+
<% end -%>
|
53
|
+
end
|
54
|
+
<% else -%>
|
55
|
+
<%= controller_code -%>
|
56
|
+
<% end -%>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<% if @module_name.present? -%>
|
2
|
+
module Operations::<%= @module_name %>::<%= @class_name %>
|
3
|
+
<% else -%>
|
4
|
+
module Operations::<%= @class_name %>
|
5
|
+
<% end -%>
|
6
|
+
class Create < RailsOps::Operation::Model::Create
|
7
|
+
schema3 do
|
8
|
+
hsh? :<%= @underscored_name %> do
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
model ::<%= @class_name %>
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<% if @module_name.present? -%>
|
2
|
+
module Operations::<%= @module_name %>::<%= @class_name %>
|
3
|
+
<% else -%>
|
4
|
+
module Operations::<%= @class_name %>
|
5
|
+
<% end -%>
|
6
|
+
class Destroy < RailsOps::Operation::Model::Destroy
|
7
|
+
schema3 do
|
8
|
+
str! :id
|
9
|
+
end
|
10
|
+
|
11
|
+
model ::<%= @class_name %>
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<% if @module_name.present? -%>
|
2
|
+
module Operations::<%= @module_name %>::<%= @class_name %>
|
3
|
+
<% else -%>
|
4
|
+
module Operations::<%= @class_name %>
|
5
|
+
<% end -%>
|
6
|
+
class Load < RailsOps::Operation::Model::Load
|
7
|
+
schema3 do
|
8
|
+
str! :id
|
9
|
+
end
|
10
|
+
|
11
|
+
model ::<%= @class_name %>
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<% if @module_name.present? -%>
|
2
|
+
module Operations::<%= @module_name %>::<%= @class_name %>
|
3
|
+
<% else -%>
|
4
|
+
module Operations::<%= @class_name %>
|
5
|
+
<% end -%>
|
6
|
+
class Update < RailsOps::Operation::Model::Update
|
7
|
+
schema3 do
|
8
|
+
str! :id
|
9
|
+
hsh? :<%= @underscored_name %> do
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
model ::<%= @class_name %>
|
15
|
+
end
|
16
|
+
end
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RailsOps
|
2
|
+
module ModelMixins
|
3
|
+
module StiFixes
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
def finder_needs_type_condition?
|
8
|
+
base_class.finder_needs_type_condition?
|
9
|
+
end
|
10
|
+
|
11
|
+
def name
|
12
|
+
base_class.name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|