effective_resources 1.8.11 → 1.8.16

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
  SHA256:
3
- metadata.gz: 2703faba8c8b14643c0e0f75e958bf27471b5d54fba6461d24e583156f7badae
4
- data.tar.gz: 917291289d6e5530f04ddf65d03da2f828d0bf00dce53d79fc6e3f67c7d7a421
3
+ metadata.gz: a854fdf544ea77faf7d45b251f8161b54ef66685c71730d6b4bdef42298ac371
4
+ data.tar.gz: 22d0141d18a049ed853d2ba54197758e46817ffdf6704c1facee7850cad5bef6
5
5
  SHA512:
6
- metadata.gz: 7033816b0b5c53b7f6ebccf7269aa635effb7f792e6dbbf55d83d546980612ecba3f3d18b160c46c5f6e353724763e63efb55e8ffa23c2f360eea1d3e1057635
7
- data.tar.gz: e7b77545e441aec916ecbe3ca0fc35e8c9d14eeb6b7d3553e8b8e5be7af7ef71b735c89b480d5a91a3288f03a48b2846ac6f7f05a744a6bdb1d758d83630e08b
6
+ metadata.gz: fa64174fb405b2499a303ed87d64b8e32aa4d7c48388875c811919526935679a4c98bfef973e0f41b2124257b5d9d46207e906f85776d5eb5c0bf487ee086179
7
+ data.tar.gz: e00c2e31e5430de0a3e19d2f0d607fa73426edbbe8f7d31c0936f60a418a4bf92206fef2d904d2ba78dab1bfffc132235056ad138ede924642cabdeffd8a6408
@@ -96,6 +96,10 @@ module Effective
96
96
  effective_resource.klass
97
97
  end
98
98
 
99
+ def resource_human_name
100
+ effective_resource.human_name
101
+ end
102
+
99
103
  def resource_plural_name # 'things'
100
104
  effective_resource.plural_name
101
105
  end
@@ -27,7 +27,6 @@ module Effective
27
27
 
28
28
  format.js do
29
29
  flash.now[:success] ||= resource_flash(:success, resource, action)
30
- #reload_resource unless action == :destroy # Removed.
31
30
  render(action) # action.js.erb
32
31
  end
33
32
  end
@@ -96,9 +95,7 @@ module Effective
96
95
  end
97
96
 
98
97
  def template_present?(action)
99
- #lookup_context.template_exists?("#{action}.#{request.format.symbol.to_s.sub('json', 'js').presence || 'html'}", _prefixes)
100
-
101
- formats = [request.format.symbol.to_s.sub('json', 'js').presence || 'html']
98
+ formats = [(request.format.symbol.to_s.sub('json', 'js').presence || 'html').to_sym]
102
99
  lookup_context.template_exists?(action, _prefixes, formats: formats)
103
100
  end
104
101
 
@@ -9,9 +9,9 @@ module Effective
9
9
  raise 'expected an ActiveRecord resource' unless (name || resource.class.respond_to?(:model_name))
10
10
 
11
11
  name ||= if resource.respond_to?(:destroyed?) && resource.destroyed?
12
- resource.class.model_name.to_s.downcase.split('::').last
12
+ resource_human_name
13
13
  else
14
- resource.to_s.presence
14
+ resource.to_s.presence || resource_human_name
15
15
  end
16
16
 
17
17
  "Successfully #{action_verb(action)} #{name || 'resource'}".html_safe
@@ -27,9 +27,9 @@ module Effective
27
27
  messages = flash_errors(resource, e: e)
28
28
 
29
29
  name ||= if resource.respond_to?(:destroyed?) && resource.destroyed?
30
- resource.class.model_name.to_s.downcase.split('::').last
30
+ resource_human_name
31
31
  else
32
- resource.to_s.presence
32
+ resource.to_s.presence || resource_human_name
33
33
  end
34
34
 
35
35
  ["Unable to #{action}", (" #{name}" if name), (": #{messages}" if messages)].compact.join.html_safe
@@ -46,9 +46,9 @@ module Effective
46
46
  end
47
47
  end
48
48
 
49
- def resource_wizard_step_title(step)
49
+ def resource_wizard_step_title(resource, step)
50
50
  return if step == 'wicked_finish'
51
- effective_resource.klass.const_get(:WIZARD_STEPS).fetch(step)
51
+ resource.wizard_step_title(step)
52
52
  end
53
53
 
54
54
  def resource_wizard_steps
@@ -8,7 +8,7 @@ module Effective
8
8
  self.resource ||= resource_scope.new
9
9
  EffectiveResources.authorize!(self, :new, resource)
10
10
 
11
- redirect_to resource_wizard_path(:new, resource_wizard_steps.first)
11
+ redirect_to resource_wizard_path(:new, resource.first_uncompleted_step || resource_wizard_steps.first)
12
12
  end
13
13
 
14
14
  def show
@@ -49,7 +49,7 @@ module Effective
49
49
  Rails.logger.info " Unable to visit step :#{step}. Last can_visit_step? is :#{next_step}. Change the acts_as_wizard model's can_visit_step?(step) function to change this."
50
50
  end
51
51
 
52
- flash[:success] = "You have been redirected to the #{resource_wizard_step_title(next_step)} step."
52
+ flash[:success] = "You have been redirected to the #{resource_wizard_step_title(resource, next_step)} step."
53
53
  redirect_to wizard_path(next_step)
54
54
  end
55
55
 
@@ -66,7 +66,7 @@ module Effective
66
66
  # before_action :assign_page_title, only: [:show, :update]
67
67
  # Assign page title
68
68
  def assign_page_title
69
- @page_title ||= resource_wizard_step_title(step)
69
+ @page_title ||= resource_wizard_step_title(resource, step)
70
70
  end
71
71
 
72
72
  end
@@ -116,7 +116,6 @@ module EffectiveResourcesHelper
116
116
  locals = {
117
117
  resource: resource,
118
118
  effective_resource: effective_resource,
119
- formats: [:html],
120
119
  format_block: (block if block_given?),
121
120
  namespace: namespace,
122
121
  actions: actions,
@@ -133,7 +132,7 @@ module EffectiveResourcesHelper
133
132
  spacer_template: spacer_template
134
133
  )
135
134
  else
136
- render(partial, locals)
135
+ render(partial: partial, formats: [:html], locals: locals)
137
136
  end
138
137
  end
139
138
 
@@ -20,7 +20,7 @@ module EffectiveResourcesWizardHelper
20
20
  def render_wizard_sidebar_item(resource, nav_step, index = nil)
21
21
  # From Controller
22
22
  current = (nav_step == step)
23
- title = resource_wizard_step_title(nav_step)
23
+ title = resource_wizard_step_title(resource, nav_step)
24
24
 
25
25
  # From Model
26
26
  disabled = !resource.can_visit_step?(nav_step)
@@ -43,6 +43,7 @@ module ActsAsWizard
43
43
  wizard_steps[current_step.to_sym] ||= Time.zone.now
44
44
  end
45
45
 
46
+ # Use can_visit_step? required_steps and wizard_step_title(step) to control the wizard behaviour
46
47
  def can_visit_step?(step)
47
48
  can_revisit_completed_steps(step)
48
49
  end
@@ -52,6 +53,10 @@ module ActsAsWizard
52
53
  self.class.const_get(:WIZARD_STEPS).keys
53
54
  end
54
55
 
56
+ def wizard_step_title(step)
57
+ self.class.const_get(:WIZARD_STEPS).fetch(step)
58
+ end
59
+
55
60
  def first_completed_step
56
61
  required_steps.find { |step| has_completed_step?(step) }
57
62
  end
@@ -65,7 +70,7 @@ module ActsAsWizard
65
70
  end
66
71
 
67
72
  def has_completed_step?(step)
68
- wizard_steps[step].present?
73
+ (errors.present? ? wizard_steps_was : wizard_steps)[step].present?
69
74
  end
70
75
 
71
76
  def next_step
@@ -78,8 +78,20 @@ module Effective
78
78
  # acpa/admin/shirts
79
79
  (names.length).downto(1).each do |n|
80
80
  names.combination(n).to_a.each do |pieces|
81
- klass_pieces = pieces.map { |piece| piece.classify } * '::'
82
- klass = klass_pieces.safe_constantize
81
+ klass = begin
82
+ klass_pieces = pieces.map { |piece| piece.classify } * '::'
83
+ klass_pieces.safe_constantize
84
+ end
85
+
86
+ klass ||= if pieces.length > 1
87
+ klass_pieces = ([pieces.first.classify] + pieces[1..-1].map { |piece| piece.classify }) * '::'
88
+ klass_pieces.safe_constantize
89
+ end
90
+
91
+ klass ||= if pieces.length > 1
92
+ klass_pieces = ([pieces.first.classify.pluralize] + pieces[1..-1].map { |piece| piece.classify }) * '::'
93
+ klass_pieces.safe_constantize
94
+ end
83
95
 
84
96
  if klass.present? && klass.class != Module
85
97
  @namespaces ||= (names - pieces)
@@ -31,14 +31,14 @@ module Effective
31
31
  end
32
32
 
33
33
  def route_name_fallbacks
34
- mod = class_name.split('::').first.downcase
34
+ mod = class_name.split('::').first.to_s.downcase
35
35
 
36
36
  matches = [
37
37
  route_name.singularize,
38
38
  [*namespace, plural_name].join('/'),
39
39
  [*namespace, name].join('/'),
40
- [mod, *namespace, plural_name].join('/'),
41
- [mod, *namespace, name].join('/')
40
+ [*mod, *namespace, plural_name].join('/'),
41
+ [*mod, *namespace, name].join('/')
42
42
  ]
43
43
  end
44
44
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.8.11'.freeze
2
+ VERSION = '1.8.16'.freeze
3
3
  end
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.8.11
4
+ version: 1.8.16
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: 2021-04-08 00:00:00.000000000 Z
11
+ date: 2021-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails