effective_resources 1.2.10 → 1.2.11
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 +4 -4
- data/app/controllers/concerns/effective/crud_controller.rb +1 -1
- data/app/controllers/concerns/effective/crud_controller/dsl.rb +4 -0
- data/app/controllers/concerns/effective/crud_controller/permitted_params.rb +5 -1
- data/app/controllers/concerns/effective/crud_controller/respond.rb +3 -0
- data/app/controllers/concerns/effective/crud_controller/save.rb +7 -5
- data/app/helpers/effective_resources_helper.rb +4 -1
- data/app/models/concerns/acts_as_archived.rb +1 -1
- data/app/models/effective/resources/init.rb +6 -2
- data/lib/effective_resources/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0117aeab19438c015a73b6b2bc942ff97a4e5db
|
4
|
+
data.tar.gz: 3415edf3209e6c044cd78e0797e540368396512b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c2561f4d6256068aa36ac4f9cd69e34d67f0d5807eca9b7b56d6275277f6069d96958978a02afe1e81a784f7145377baf0bc832e8aaab0cb4ad6c526b8c1ddb
|
7
|
+
data.tar.gz: c35bee54d8ba06c58db0a6dccc2d963590d0830b97fd1956aef6b6927ba5710cdee6de7e6e735a41abb82d75bfa633dc507dcd3630b2607e4e23a7a804d62efe
|
@@ -12,7 +12,7 @@ module Effective
|
|
12
12
|
included do
|
13
13
|
define_actions_from_routes
|
14
14
|
define_permitted_params_from_model
|
15
|
-
define_callbacks :resource_render, :resource_before_save, :resource_after_save, :resource_error
|
15
|
+
define_callbacks :resource_render, :resource_before_save, :resource_after_save, :resource_after_commit, :resource_error
|
16
16
|
end
|
17
17
|
|
18
18
|
module ClassMethods
|
@@ -15,6 +15,10 @@ module Effective
|
|
15
15
|
_insert_callbacks(names, blk) { |name, options| set_callback(:resource_after_save, :after, name, options) }
|
16
16
|
end
|
17
17
|
|
18
|
+
def after_commit(*names, &blk)
|
19
|
+
_insert_callbacks(names, blk) { |name, options| set_callback(:resource_after_commit, :after, name, options) }
|
20
|
+
end
|
21
|
+
|
18
22
|
def after_error(*names, &blk)
|
19
23
|
_insert_callbacks(names, blk) { |name, options| set_callback(:resource_error, :after, name, options) }
|
20
24
|
end
|
@@ -27,7 +27,11 @@ module Effective
|
|
27
27
|
Rails.logger.info "params.require(:#{effective_resource.name}).permit!"
|
28
28
|
end
|
29
29
|
|
30
|
-
params
|
30
|
+
if params[effective_resource.name].present?
|
31
|
+
params.require(effective_resource.name).permit!
|
32
|
+
else
|
33
|
+
params.require((effective_resource.namespaces + [effective_resource.name]).join('_')).permit!
|
34
|
+
end
|
31
35
|
end
|
32
36
|
|
33
37
|
private
|
@@ -23,6 +23,9 @@ module Effective
|
|
23
23
|
#reload_resource unless action == :destroy # Removed.
|
24
24
|
render(action) # action.js.erb
|
25
25
|
end
|
26
|
+
elsif response_body.present? # We might have done something weird like send_data in an after_save
|
27
|
+
format.html { flash.now[:success] ||= resource_flash(:success, resource, action) }
|
28
|
+
format.js { flash.now[:success] ||= resource_flash(:success, resource, action) }
|
26
29
|
else # Default
|
27
30
|
format.html do
|
28
31
|
flash[:success] ||= resource_flash(:success, resource, action)
|
@@ -20,11 +20,12 @@ module Effective
|
|
20
20
|
# This calls the appropriate member action, probably save!, on the resource.
|
21
21
|
def save_resource(resource, action = :save, &block)
|
22
22
|
save_action = ([:create, :update].include?(action) ? :save : action)
|
23
|
-
|
24
23
|
raise "expected @#{resource_name} to respond to #{save_action}!" unless resource.respond_to?("#{save_action}!")
|
25
24
|
|
26
25
|
resource.current_user ||= current_user if resource.respond_to?(:current_user=)
|
27
26
|
|
27
|
+
success = false
|
28
|
+
|
28
29
|
ActiveRecord::Base.transaction do
|
29
30
|
begin
|
30
31
|
run_callbacks(:resource_before_save)
|
@@ -37,7 +38,7 @@ module Effective
|
|
37
38
|
|
38
39
|
run_callbacks(:resource_after_save)
|
39
40
|
|
40
|
-
|
41
|
+
success = true
|
41
42
|
rescue => e
|
42
43
|
if Rails.env.development?
|
43
44
|
Rails.logger.info " \e[31m\e[1mFAILED\e[0m\e[22m" # bold red
|
@@ -60,12 +61,13 @@ module Effective
|
|
60
61
|
else
|
61
62
|
raise(e) # This is a real error that should be sent to 500. Client should not see the message.
|
62
63
|
end
|
63
|
-
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
run_callbacks(:resource_error)
|
68
|
-
|
67
|
+
run_callbacks(:resource_error) unless success
|
68
|
+
run_callbacks(:resource_after_commit)
|
69
|
+
|
70
|
+
success
|
69
71
|
end
|
70
72
|
|
71
73
|
def resource_flash(status, resource, action, e: nil)
|
@@ -57,7 +57,10 @@ module EffectiveResourcesHelper
|
|
57
57
|
# locals: {} render locals
|
58
58
|
# you can also pass all action names and true/false such as edit: true, show: false
|
59
59
|
def render_resource_actions(resource, atts = {}, &block)
|
60
|
-
|
60
|
+
unless resource.kind_of?(ActiveRecord::Base) || resource.kind_of?(Class) || resource.kind_of?(Array) || resource.class.ancestors.include?(ActiveModel::Model)
|
61
|
+
raise 'expected first argument to be an ActiveRecord::Base object or Array of objects'
|
62
|
+
end
|
63
|
+
|
61
64
|
raise 'expected attributes to be a Hash' unless atts.kind_of?(Hash)
|
62
65
|
|
63
66
|
btn_class = atts[:btn_class]
|
@@ -62,7 +62,7 @@ module ActsAsArchived
|
|
62
62
|
|
63
63
|
included do
|
64
64
|
scope :archived, -> { where(archived: true) }
|
65
|
-
scope :unarchived, -> { where(archived: false) }
|
65
|
+
scope :unarchived, -> { where(archived: [false, nil]) }
|
66
66
|
|
67
67
|
effective_resource do
|
68
68
|
archived :boolean, permitted: false
|
@@ -49,10 +49,14 @@ module Effective
|
|
49
49
|
names = input.split('/')
|
50
50
|
|
51
51
|
0.upto(names.length-1) do |index|
|
52
|
-
class_name =
|
53
|
-
|
52
|
+
class_name = names[index..-1].map { |name| name.classify } * '::'
|
54
53
|
klass = class_name.safe_constantize
|
55
54
|
|
55
|
+
if klass.blank? && index > 0
|
56
|
+
class_name = (names[0..index-1].map { |name| name.classify.pluralize } + names[index..-1].map { |name| name.classify }) * '::'
|
57
|
+
klass = class_name.safe_constantize
|
58
|
+
end
|
59
|
+
|
56
60
|
if klass.present?
|
57
61
|
@namespaces ||= names[0...index]
|
58
62
|
@model_klass = klass
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|