effective_resources 1.9.3 → 1.9.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 598341ec405c5f865bd47dd20eb3ac0260243a753bebc3ebe6c113364be41c20
4
- data.tar.gz: 17fdbbf3cd41afa8342b6443c646d7082c052706e3995c4a0a0279ed8e063ae9
3
+ metadata.gz: 72da4b1b0ca72429a3a32b29cfb4f6fa3e8861b0c5ca4e5243b5f9b6405c55fd
4
+ data.tar.gz: a145acc8a26f9e13aa237bce6519f0d5f6e9964d6c3db556324876dca5fdf2e7
5
5
  SHA512:
6
- metadata.gz: f1b7daf92008549871a27f404f56f6c24554d49f5d8a33659fe5428af05544cc051b5824e682bce143ad459755b317d39866e2a770c916c0ca9e882d23a9349a
7
- data.tar.gz: 4f1815a0e2f563687c78422623c20bef18143b33e01e2fa49d61681583233f8fb40884f5fba98261fb3c7b32dfb4d810f2ffab95d2f241b614ca24d50c1a6180
6
+ metadata.gz: 6bb00698226acb546365464870767a22e235310a9128d2fa7a80df17dca9697d9f58bfb2810744657591d0c80605a836d507cfe9f9d79abd5cffb6a712ddc4d1
7
+ data.tar.gz: 329869f907f76bd54bd506e41433a40e1fd95837b81219cf80c2f349fc448d081080e4e73558c42207c90b576f0c0a1a1f31698a7e05378674a048f13486cc17
@@ -9,7 +9,7 @@ module Effective
9
9
  @page_title ||= resource_plural_name.titleize
10
10
 
11
11
  self.resources ||= resource_scope.all if resource_scope.respond_to?(:all)
12
- @datatable = resource_datatable(:index)
12
+ @datatable = resource_datatable()
13
13
 
14
14
  run_callbacks(:resource_render)
15
15
  end
@@ -214,7 +214,7 @@ module Effective
214
214
  @page_title ||= "#{action.to_s.titleize} #{resource_plural_name.titleize}"
215
215
 
216
216
  if request.get?
217
- @datatable = resource_datatable(action)
217
+ @datatable = resource_datatable()
218
218
  run_callbacks(:resource_render)
219
219
 
220
220
  view = lookup_context.template_exists?(action, _prefixes) ? action : :index
@@ -61,7 +61,20 @@ module Effective
61
61
  raise 'expected a label or block' unless (label || block_given?)
62
62
 
63
63
  instance_exec do
64
- before_action(opts) { @page_title ||= (block_given? ? instance_exec(&block) : label).to_s }
64
+ before_action(opts) do
65
+ @page_title ||= (block_given? ? instance_exec(&block) : label).to_s
66
+ end
67
+ end
68
+ end
69
+
70
+ # datatable -> { MyDatatable.new }, only: [:index]
71
+ def datatable(obj = nil, opts = {}, &block)
72
+ raise 'expected a proc or block' unless (obj.respond_to?(:call) || block_given?)
73
+
74
+ instance_exec do
75
+ before_action(opts) do
76
+ @datatable ||= (block_given? ? instance_exec(&block) : obj.call)
77
+ end
65
78
  end
66
79
  end
67
80
 
@@ -84,7 +97,6 @@ module Effective
84
97
  else
85
98
  define_method(:resource_scope_relation) { return obj }
86
99
  end
87
-
88
100
  end
89
101
 
90
102
  end
@@ -108,15 +108,16 @@ module Effective
108
108
  resource_scope.where_values_hash.symbolize_keys
109
109
  end
110
110
 
111
- def resource_datatable(action)
112
- datatable_klass = if action == :index
113
- effective_resource.datatable_klass
114
- else # Admin::ActionDatatable.new
115
- "#{[effective_resource.namespace.to_s.classify.presence, action.to_s.classify].compact.join('::')}Datatable".safe_constantize ||
116
- "#{[effective_resource.namespace.to_s.classify.presence, action.to_s.pluralize.classify].compact.join('::')}Datatable".safe_constantize ||
117
- "#{[effective_resource.namespace.to_s.classify.presence, action.to_s.singularize.classify].compact.join('::')}Datatable".safe_constantize
111
+ def resource_datatable
112
+ # This might have been done from a before action or dsl method
113
+ unless @datatable.nil?
114
+ raise('expected @datatable to be an Effective::Datatable') unless @datatable.kind_of?(Effective::Datatable)
115
+
116
+ @datatable.effective_resource = effective_resource
117
+ return @datatable
118
118
  end
119
119
 
120
+ datatable_klass = effective_resource.datatable_klass
120
121
  return unless datatable_klass.present?
121
122
 
122
123
  datatable = datatable_klass.new(resource_datatable_attributes)
@@ -76,7 +76,11 @@ module ActsAsWizard
76
76
  end
77
77
 
78
78
  def next_step
79
- required_steps.reverse.find { |step| can_visit_step?(step) } || required_steps.first
79
+ first_uncompleted_step ||
80
+ last_completed_step ||
81
+ required_steps.reverse.find { |step| can_visit_step?(step) } ||
82
+ required_steps.first ||
83
+ :start
80
84
  end
81
85
 
82
86
  def previous_step(step)
@@ -89,6 +93,13 @@ module ActsAsWizard
89
93
  previous.blank? || has_completed_step?(previous)
90
94
  end
91
95
 
96
+ def has_completed_all_previous_steps?(step)
97
+ index = required_steps.index(step).to_i
98
+ previous = required_steps[0...index]
99
+
100
+ previous.blank? || previous.all? { |step| has_completed_step?(step) }
101
+ end
102
+
92
103
  def has_completed_last_step?
93
104
  has_completed_step?(required_steps.last)
94
105
  end
@@ -97,12 +108,12 @@ module ActsAsWizard
97
108
 
98
109
  def can_revisit_completed_steps(step)
99
110
  return (step == required_steps.last) if has_completed_last_step?
100
- has_completed_previous_step?(step)
111
+ has_completed_all_previous_steps?(step)
101
112
  end
102
113
 
103
114
  def cannot_revisit_completed_steps(step)
104
115
  return (step == required_steps.last) if has_completed_last_step?
105
- has_completed_previous_step?(step) && !has_completed_step?(step)
116
+ has_completed_all_previous_steps?(step) && !has_completed_step?(step)
106
117
  end
107
118
 
108
119
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.9.3'.freeze
2
+ VERSION = '1.9.4'.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.9.3
4
+ version: 1.9.4
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-11-05 00:00:00.000000000 Z
11
+ date: 2021-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails