scaffold_plus 1.10.1 → 1.10.2

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: 6999276a25f554d0465c602977b1007696b1e5c9
4
- data.tar.gz: 3c4514802495ad426d981617013914a811415dfc
3
+ metadata.gz: 892354dc67fc130674d405fa1cf7d48a0d20fcca
4
+ data.tar.gz: 6505cce490b378beb556bfa5a42a1663a047bc3e
5
5
  SHA512:
6
- metadata.gz: cd0c9c2ff1f758b49a93b8c6941e9bae2d9f33b7962387d8b6c4702c91220c5f69cc34d40b7b10968139d9528d76f15e857baa5d467cc5202db20c5e60113b79
7
- data.tar.gz: c60842afbd7f621e3d36a0229dce5954e3e0c908d5c542372be933a04b71cd1d2a7dcdc2a0f76b80cf18af49a1fc484f86d66b2ebfb603d654e97bfecbaa7c6b
6
+ metadata.gz: 4b2fd31da58d798575a5709defb2943e3e8ec56df75d54638bb5714443a39f2ec8b68c549e1e312faa0765a49c7d05c661047eb54f24528c1caeac691832f9cb
7
+ data.tar.gz: f44bac767b7c586a07af26c615e8dd12d0454f64256e19e24650b00d7429951a328b19a04a86840cc3a63100a7ff3d3efa5cc82d4b69d4a4fe187f7990641d2f
@@ -8,6 +8,8 @@ module ScaffoldPlus
8
8
  desc: 'The object that will be protected'
9
9
  class_option :authorizer, type: :string,
10
10
  desc: 'authorizer (full name) instead of <class name>Authorizer'
11
+ class_option :controller, type: :boolean, default: false,
12
+ desc: 'add standard authorization to controller'
11
13
  class_option :before, type: :boolean, default: false,
12
14
  desc: 'Add a line before generated text in model'
13
15
  class_option :after, type: :boolean, default: false,
@@ -32,6 +34,23 @@ module ScaffoldPlus
32
34
  return if options.authorizer.present?
33
35
  template "authorizer.rb", "app/authorizers/#{name}_authorizer.rb"
34
36
  end
37
+
38
+ def update_controller
39
+ return unless options.controller?
40
+ file = "app/controllers/#{table_name}_controller.rb"
41
+ inject_into_file file, after: /before_action :set_#{name}.*$/ do
42
+ "\n authorize_actions_for #{class_name}, only: [:index, :new, :create]"
43
+ end
44
+ inject_into_file file, after: /private$/ do
45
+ "\n def authority_forbidden(error)" +
46
+ "\n Authority.logger.warn(error.message)" +
47
+ "\n redirect_to breeders_path, alert: 'Forbidden'" +
48
+ "\n end\n"
49
+ end
50
+ inject_into_file file, after: /@#{name} = #{class_name}.find.*$/ do
51
+ "\n authorize_action_for(@#{name})"
52
+ end
53
+ end
35
54
  end
36
55
  end
37
56
  end
@@ -1,3 +1,3 @@
1
1
  module ScaffoldPlus
2
- VERSION = "1.10.1"
2
+ VERSION = "1.10.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scaffold_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.1
4
+ version: 1.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volker Wiegand