rails_ops 1.1.24 → 1.1.28

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +17 -0
  3. data/.github/workflows/ruby.yml +37 -7
  4. data/.gitignore +2 -0
  5. data/.rubocop.yml +1 -0
  6. data/Appraisals +19 -0
  7. data/CHANGELOG.md +25 -2
  8. data/LICENSE +1 -1
  9. data/README.md +106 -13
  10. data/Rakefile +2 -0
  11. data/VERSION +1 -1
  12. data/gemfiles/rails_5.1.gemfile +7 -0
  13. data/gemfiles/rails_5.2.gemfile +7 -0
  14. data/gemfiles/rails_6.0.gemfile +7 -0
  15. data/gemfiles/rails_6.1.gemfile +7 -0
  16. data/gemfiles/rails_7.0.gemfile +7 -0
  17. data/lib/generators/operation/USAGE +21 -0
  18. data/lib/generators/operation/operation_generator.rb +64 -0
  19. data/lib/generators/operation/templates/controller.erb +56 -0
  20. data/lib/generators/operation/templates/create.erb +15 -0
  21. data/lib/generators/operation/templates/destroy.erb +13 -0
  22. data/lib/generators/operation/templates/load.erb +13 -0
  23. data/lib/generators/operation/templates/update.erb +16 -0
  24. data/lib/generators/operation/templates/view.erb +0 -0
  25. data/lib/rails_ops/mixins/model/authorization.rb +1 -3
  26. data/lib/rails_ops/model_mixins/sti_fixes.rb +2 -6
  27. data/lib/rails_ops/model_mixins/virtual_attributes/virtual_column_wrapper.rb +4 -0
  28. data/lib/rails_ops.rb +1 -13
  29. data/rails_ops.gemspec +10 -6
  30. data/test/dummy/app/models/flower.rb +7 -0
  31. data/test/dummy/config/application.rb +10 -10
  32. data/test/dummy/db/schema.rb +4 -0
  33. data/test/unit/rails_ops/generators/operation_generator_test.rb +254 -0
  34. data/test/unit/rails_ops/operation/model/create_test.rb +16 -0
  35. data/test/unit/rails_ops/operation/model/update_test.rb +71 -0
  36. metadata +56 -11
  37. data/lib/rails_ops/model_casting.rb +0 -17
  38. data/lib/rails_ops/patches/active_type_patch.rb +0 -52
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f5db505fe961fecc4e9723b857f989860cf5056d76eb9814a4d4903bb0a6bfe
4
- data.tar.gz: 3ab7053bc62a8bfb77b8c81ac90c97467ccdde7778e906097c4328c68c47607c
3
+ metadata.gz: 47bf9f1036ce2dc4920702cf743def5630af73960f1a750abedc578708454d61
4
+ data.tar.gz: d0ddd78f73c479e26f6d601d3dfdbeeefc0f667f0b5d094538f2e1faa210275d
5
5
  SHA512:
6
- metadata.gz: 91c83b59903d7b82539e04c87a4604b6878a8f837a89931f95dcbf542d209e446e3caa849825f5042be68d0c95277f888445438f44ac7e9971f8140d02b4f124
7
- data.tar.gz: 80c4f9044744f71f34c07b70c73b584d74fad04d958db6055246d7d13aeb592a1a8bdae58ee258ae1f1513f325b2f9978e1ed50cf14dbe50f560dbc3899c532c
6
+ metadata.gz: 47bd674965ba4ff732f343391b1ad77d11c8ceed69505d519979a2c9a81d45344a9dd21151b1a749ad24fed922c15d3223eee4418317acee947b5cfcb3dbf8cd
7
+ data.tar.gz: dea5e80197169cf93b06ea713ca198b97ff711b9171a3869d0da922341d6ebe5286993045009051b03f3eec2e41ed2172bdcc4c9a15943bea93a5bf042fdfbca
@@ -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
@@ -1,4 +1,4 @@
1
- name: Build
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
- ruby-version: ['2.3.0', '2.5.1', '2.6.2', '2.7.1', '3.0.1']
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 test
26
- - name: Run rubocop
27
- run: bundle exec rubocop
57
+ run: bundle exec rake
data/.gitignore CHANGED
@@ -12,3 +12,5 @@
12
12
  /vendor/bundle
13
13
  /test/dummy/tmp/
14
14
  /test/dummy/log/
15
+ /test/tmp/
16
+ /gemfiles/*.lock
data/.rubocop.yml CHANGED
@@ -6,6 +6,7 @@ AllCops:
6
6
  - 'tmp/**/*'
7
7
  - 'log/**/*'
8
8
  - '*.gemspec'
9
+ - 'test/tmp/**/*'
9
10
 
10
11
  DisplayCopNames: true
11
12
 
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,10 +1,33 @@
1
1
  # Changelog
2
2
 
3
- ## 1.1.22 (2021-11-25)
3
+ ## 1.1.28 (2022-02-16)
4
+
5
+ * [#22](https://github.com/sitrox/rails_ops/issues/22): Fix error with active_type `>= 2`
6
+
7
+ ## 1.1.27 (2022-02-15)
8
+
9
+ * Add `module` option to `operation` generator
10
+
11
+ ## 1.1.26 (2022-01-18)
12
+
13
+ * #25: Add test matrix for unit tests
14
+
15
+ * Add compatibility for Rails 7 and Ruby 3.1.0
16
+
17
+ ## 1.1.25 (2022-01-17)
18
+
19
+ * #24: Add generator `operation` that generates a controller, operations and empty
20
+ view files
21
+
22
+ ## 1.1.24 (2021-11-24)
4
23
 
5
24
  * Add support for STI in model operations
6
25
 
7
- ## 1.1.21 (2021-11-01)
26
+ ## 1.1.23 (2021-11-01)
27
+
28
+ * No changes to previous release
29
+
30
+ ## 1.1.22 (2021-11-01)
8
31
 
9
32
  * Add support for lazy model authorization
10
33
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright © 2017-2021 Sitrox
3
+ Copyright © 2017-2022 Sitrox
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- [![Build](https://github.com/sitrox/rails_ops/actions/workflows/ruby.yml/badge.svg)](https://github.com/sitrox/rails_ops/actions/workflows/ruby.yml)
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 and has been tested with Rails >=
26
- 3.2.0.
27
- - Prior Rails versions may be supported but this has not been verified.
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
- ```ruby
58
- config.paths = Rails::Paths::Root.new(Rails.root)
59
- config.paths.add 'app/models', eager_load: true
60
- config.paths.add 'app', eager_load: true
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
- # WARNING: Skip this if you have any script files in your lib/ directory
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
  ----------------
@@ -1488,6 +1502,85 @@ sub-operations, see section *Calling sub-operations* for more information.
1488
1502
  Operation Inheritance
1489
1503
  ---------------------
1490
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
+
1491
1584
  Caveats
1492
1585
  -------
1493
1586
 
@@ -1509,4 +1602,4 @@ Rails architecture.
1509
1602
 
1510
1603
  ## Copyright
1511
1604
 
1512
- Copyright © 2017 - 2021 Sitrox. See `LICENSE` for further details.
1605
+ Copyright © 2017 - 2022 Sitrox. See `LICENSE` for further details.
data/Rakefile CHANGED
@@ -15,6 +15,7 @@ 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'
@@ -22,6 +23,7 @@ task :gemspec do
22
23
  spec.add_development_dependency 'pry'
23
24
  spec.add_development_dependency 'colorize'
24
25
  spec.add_development_dependency 'rubocop', '0.47.1'
26
+ spec.add_development_dependency 'sprockets-rails'
25
27
  spec.add_dependency 'active_type', '>= 1.3.0'
26
28
  spec.add_dependency 'minitest'
27
29
  spec.add_dependency 'rails'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.24
1
+ 1.1.28
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.1.7"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.2.6"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.0.4"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.1.4"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 7.0.1"
6
+
7
+ gemspec path: "../"
@@ -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
@@ -70,8 +70,6 @@ module RailsOps::Mixins::Model::Authorization
70
70
  # Cast {ActiveType::Record} classes or instances to regular AR models in order
71
71
  # for cancan(can) to work properly. Classes and instances that are no active
72
72
  # type records will be returned as-is.
73
- #
74
- # TODO: Use ModelCasting module instead?
75
73
  def cast_model_for_authorization(model_class_or_instance)
76
74
  if model_class_or_instance.is_a?(Class)
77
75
  if model_class_or_instance.respond_to?(:extended_record_base_class)
@@ -80,7 +78,7 @@ module RailsOps::Mixins::Model::Authorization
80
78
  return model_class_or_instance
81
79
  end
82
80
  elsif model_class_or_instance.class.respond_to?(:extended_record_base_class)
83
- return ActiveType.cast(model_class_or_instance, model_class_or_instance.class.extended_record_base_class)
81
+ model_class_or_instance.becomes(model_class_or_instance.class.extended_record_base_class)
84
82
  else
85
83
  model_class_or_instance
86
84
  end
@@ -5,15 +5,11 @@ module RailsOps
5
5
 
6
6
  class_methods do
7
7
  def finder_needs_type_condition?
8
- superclass.finder_needs_type_condition?
9
- end
10
-
11
- def descendants
12
- superclass.descendants
8
+ base_class.finder_needs_type_condition?
13
9
  end
14
10
 
15
11
  def name
16
- superclass.name
12
+ base_class.name
17
13
  end
18
14
  end
19
15
  end
@@ -6,4 +6,8 @@ class RailsOps::ModelMixins::VirtualAttributes::VirtualColumnWrapper
6
6
  def type
7
7
  @virtual_column.instance_variable_get(:@type_caster).instance_variable_get(:@type)
8
8
  end
9
+
10
+ def default_function
11
+ nil
12
+ end
9
13
  end
data/lib/rails_ops.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'active_type'
1
2
  require 'schemacop'
2
3
  require 'request_store'
3
4
 
@@ -46,18 +47,6 @@ module RailsOps
46
47
  end
47
48
  end
48
49
 
49
- # ---------------------------------------------------------------
50
- # Require Gem active_type and monkey patch
51
- # ---------------------------------------------------------------
52
- require 'active_type'
53
- require 'active_type/type_caster'
54
- require 'rails_ops/patches/active_type_patch'
55
-
56
- # ---------------------------------------------------------------
57
- # Require Schemacop
58
- # ---------------------------------------------------------------
59
- require 'schemacop'
60
-
61
50
  # ---------------------------------------------------------------
62
51
  # Require RailsOps
63
52
  # ---------------------------------------------------------------
@@ -84,7 +73,6 @@ require 'rails_ops/mixins/require_context.rb'
84
73
  require 'rails_ops/mixins/routes.rb'
85
74
  require 'rails_ops/mixins/schema_validation.rb'
86
75
  require 'rails_ops/mixins/sub_ops.rb'
87
- require 'rails_ops/model_casting.rb'
88
76
  require 'rails_ops/model_mixins.rb'
89
77
  require 'rails_ops/model_mixins/ar_extension.rb'
90
78
  require 'rails_ops/model_mixins/parent_op.rb'