five-two-nw-olivander 0.2.0.36 → 0.2.0.37

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: 20a2a1f0d91b619aa91cb6e5670939246a5471a40a1fdcc772934f11de447c7c
4
- data.tar.gz: 010f45ad72e71c350fbbcf73385fe2b39b47458e613a7da714dfd9dd378a367d
3
+ metadata.gz: c981a57d42b00be64a2c6916e9407f6359be57a12286db6d107dcd53723ccb51
4
+ data.tar.gz: e4a4b83c85c99d775c66930ab1b3873faa16e5ba3da090e8d6ef3e97153fa1fa
5
5
  SHA512:
6
- metadata.gz: 7175c69a12f98b0b31e6525b87b8e51a2fe9a8c3a02b577617acfc741b184edcdd1323d896fe5317278a238ae71c97905e4f0a49270efdfa6ce837f6acd4ed14
7
- data.tar.gz: 2fb042867661f164131bcdd36ebc74e8f7ed62e2711b20b2b0ee9f5c1290f85db9947ca8f745ca1cf1d3048bb4b901418c15337b014f9ce80564a8bd66a574af
6
+ metadata.gz: aa2450a62d515a7cb15f1fccacab6da0225fbdf7a52d9839f846bd2d7fc65d5420dd2257dd9847873208865454885fd13b9e6285f2e903be5ae54f8963d09ce0
7
+ data.tar.gz: da063e58ceefc6c15684199222f15cacd501dbc781f6d247d5bae47c5a710a7a6b4fc5d85595ac9994cb353f46d4b3caac79c6bd728120c92a89227765aba40a
@@ -3,39 +3,41 @@ module Olivander
3
3
  class ResourceAction
4
4
  attr_accessor :sym, :action, :verb, :confirm, :turbo_frame, :collection,
5
5
  :controller, :crud_action, :show_in_form, :show_in_datatable,
6
- :no_route, :path_helper, :confirm_with, :primary
6
+ :no_route, :path_helper, :confirm_with, :primary,
7
+ :turbo, :html_attributes
7
8
 
8
- def initialize(sym, action: nil, controller: nil, verb: :get, confirm: false,
9
- turbo_frame: nil, collection: false, crud_action: false,
10
- show_in_form: true, show_in_datatable: true, no_route: false,
11
- path_helper: nil, confirm_with: nil, primary: nil)
9
+ def initialize(sym, **kwargs)
12
10
  self.sym = sym
13
- self.action = action || sym
14
- self.controller = controller
15
- self.verb = verb
16
- self.confirm = confirm
17
- self.turbo_frame = turbo_frame
18
- self.collection = collection
19
- self.crud_action = crud_action
20
- self.show_in_form = show_in_form
21
- self.show_in_datatable = show_in_datatable
22
- self.no_route = no_route
23
- self.path_helper = path_helper
24
- self.confirm_with = confirm_with
25
- self.primary = primary || crud_action
11
+ self.action = kwargs[:action] || sym
12
+ self.controller = kwargs[:controller]
13
+ self.verb = kwargs[:verb] || :get
14
+ self.confirm = kwargs[:confirm] || false
15
+ self.turbo_frame = kwargs[:turbo_frame]
16
+ self.turbo = kwargs[:turbo] == true ? true : !turbo_frame.blank?
17
+ self.collection = kwargs[:collection] || false
18
+ self.crud_action = kwargs[:crud_action] || false
19
+ self.show_in_form = kwargs[:show_in_form] || true
20
+ self.show_in_datatable = kwargs[:show_in_datatable] || true
21
+ self.no_route = kwargs[:no_route] || false
22
+ self.path_helper = kwargs[:path_helper]
23
+ self.confirm_with = kwargs[:confirm_with]
24
+ self.primary = kwargs[:primary] || crud_action
25
+ self.html_attributes = kwargs[:html_attributes]
26
26
  end
27
27
 
28
28
  def args_hash(options = nil)
29
29
  {}.tap do |h|
30
- h.merge!(method: verb) if turbo_frame.blank?
30
+ h.merge!(method: verb) unless turbo
31
31
  h.merge!(data: data_hash)
32
+ h.merge!(html_attributes) if html_attributes
32
33
  h.merge!(options) if options.present?
33
34
  end
34
35
  end
35
36
 
36
37
  def data_hash
37
38
  {}.tap do |h|
38
- h.merge!(turbo: true, turbo_method: verb, turbo_frame: turbo_frame) if turbo_frame.present?
39
+ h.merge!(turbo: true, turbo_method: verb) if turbo
40
+ h.merge!(turbo_frame: turbo_frame) if turbo_frame.present?
39
41
 
40
42
  message = confirmation_message
41
43
  h.merge!(confirm_key => message) unless message.blank?
@@ -43,7 +45,7 @@ module Olivander
43
45
  end
44
46
 
45
47
  def confirm_key
46
- turbo_frame.present? ? :turbo_confirm : :confirm
48
+ turbo ? :turbo_confirm : :confirm
47
49
  end
48
50
 
49
51
  def confirmation_message
@@ -63,7 +65,9 @@ module Olivander
63
65
  self.actions = []
64
66
  %i[index new create edit show update destroy].each do |ca|
65
67
  next unless crud_actions.include?(ca)
66
- actions << ResourceAction.new(ca, controller: model, verb: resolve_crud_action_verb(ca), collection: resolve_crud_action_collection(ca), crud_action: true)
68
+
69
+ actions << ResourceAction.new(ca, controller: model, verb: resolve_crud_action_verb(ca),
70
+ collection: resolve_crud_action_collection(ca), crud_action: true)
67
71
  end
68
72
  end
69
73
 
@@ -85,29 +89,29 @@ module Olivander
85
89
  end
86
90
 
87
91
  def crud_actions
88
- actions.select{ |x| x.crud_action }
92
+ actions.select { |x| x.crud_action }
89
93
  end
90
94
 
91
95
  def member_actions
92
- actions.select{ |x| !x.collection }
96
+ actions.select { |x| !x.collection }
93
97
  end
94
98
 
95
99
  def collection_actions
96
- actions.select{ |x| x.collection }
100
+ actions.select { |x| x.collection }
97
101
  end
98
102
 
99
103
  def datatable_bulk_actions
100
- collection_actions.select{ |x| x.show_in_datatable && !x.crud_action }
104
+ collection_actions.select { |x| x.show_in_datatable && !x.crud_action }
101
105
  end
102
106
 
103
107
  def unpersisted_crud_actions
104
108
  allowed = %i[index new]
105
- crud_actions.select{ |x| allowed.include?(x.sym) }
109
+ crud_actions.select { |x| allowed.include?(x.sym) }
106
110
  end
107
111
 
108
112
  def persisted_crud_actions
109
113
  allowed = %i[show edit destroy]
110
- crud_actions.select{ |x| allowed.include?(x.sym) }
114
+ crud_actions.select { |x| allowed.include?(x.sym) }
111
115
  end
112
116
  end
113
117
 
@@ -123,25 +127,18 @@ module Olivander
123
127
  end
124
128
 
125
129
  class_methods do
126
- def resource(model, only: DEFAULT_CRUD_ACTIONS, except: [], namespaces: [], &block)
130
+ def resource(model, only: DEFAULT_CRUD_ACTIONS, except: [], namespaces: [])
127
131
  self.current_resource = RoutedResource.new(model, namespaces, DEFAULT_CRUD_ACTIONS & (only - except))
128
132
  yield if block_given?
129
133
  resources[model] = current_resource
130
134
  self.current_resource = nil
131
135
  end
132
136
 
133
- def action(sym, verb: :get, confirm: false, turbo_frame: nil, collection: false, show_in_datatable: true,
134
- show_in_form: true, no_route: false, controller: nil, action: nil, path_helper: nil,
135
- confirm_with: nil, primary: nil
136
- )
137
+ def action(sym, **kwargs)
137
138
  raise 'Must be invoked in a resource block' unless current_resource.present?
138
139
 
139
140
  controller ||= current_resource.model
140
- current_resource.actions << ResourceAction.new(
141
- sym, action: action, controller: controller, verb: verb, confirm: confirm, turbo_frame: turbo_frame, collection: collection,
142
- show_in_datatable: show_in_datatable, show_in_form: show_in_form, no_route: no_route, path_helper: path_helper,
143
- confirm_with: confirm_with, primary: primary
144
- )
141
+ current_resource.actions << ResourceAction.new(sym, **kwargs)
145
142
  end
146
143
 
147
144
  def build_routes(mapper)
@@ -185,13 +182,16 @@ module Olivander
185
182
  end
186
183
  end
187
184
 
188
- mapper.new do
189
- mapper.get :new
190
- end if r.collection_actions.select{ |x| x.action == :new }.size.positive?
185
+ if r.collection_actions.select { |x| x.action == :new }.size.positive?
186
+ mapper.new do
187
+ mapper.get :new
188
+ end
189
+ end
191
190
 
192
191
  mapper.member do
193
192
  r.member_actions.each do |ma|
194
193
  next if ma.no_route
194
+
195
195
  if ma.confirm
196
196
  mapper.get ma.action, action: "confirm_#{ma.action}"
197
197
  set_controller_and_helper(ma)
@@ -2,5 +2,5 @@
2
2
 
3
3
  # needed for gem
4
4
  module Olivander
5
- VERSION = '0.2.0.36'
5
+ VERSION = '0.2.0.37'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: five-two-nw-olivander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.36
4
+ version: 0.2.0.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dennis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-23 00:00:00.000000000 Z
11
+ date: 2024-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chartkick