five-two-nw-olivander 0.1.2.4 → 0.1.2.6

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: d551785ee277728e208fb537527d00e201b93b89f796de075295f271c90ff879
4
- data.tar.gz: f079e183a76a7724c16099542aeaef9159f5d4ff64ef227267a8de6dcd03b7c0
3
+ metadata.gz: 8321bd8a5b34a8550a97d74784c9303f430ec4a4417cd8acadf564f8fcd92687
4
+ data.tar.gz: 27697dcd2ca0669e2ad81f770b98760dacadb9d1e0bae849ccc047728a89e0c9
5
5
  SHA512:
6
- metadata.gz: 1abaa3d2a03cb74f5d38077e2070a90ca63a12f27799a6d000fdb3506272c9890b284fbc76a59049bd1b5fe1766d51f11658f96fe28298baf83e80ab7436719e
7
- data.tar.gz: dadd557fabc44933a35bf795173c37d3753b7f40cfae8fa2979978923b78312904e96c8a66e12da01a46fbb24917f22476a5ca72ea815f7358f56fc7766a6a90
6
+ metadata.gz: a9f824c7aa7a5a8356f2eceeb149e91daef1e7d94eb22bce75d70f3584508d2347b65cf66c383b4512bc26809d1052e09b72cda5e9e6d0224c6fe81c928af3c8
7
+ data.tar.gz: 1f0b34e2dc130103bcaacf848e17ab6e76bd5f7db84414160201b265623f0fcdd55e391dcf85acebb2ae2946b97240d06edcace6018b08cd6c21e703d34ca3d9
@@ -25,29 +25,43 @@ module Olivander
25
25
  def initialize(model, crud_actions)
26
26
  self.model = model
27
27
  self.actions = []
28
- crud_actions.each do |ca|
29
- actions << ResourceAction.new(ca, controller: model, crud_action: true)
28
+ %i[index new create edit show update destroy].each do |ca|
29
+ next unless crud_actions.include?(ca)
30
+ actions << ResourceAction.new(ca, controller: model, verb: resolve_crud_action_verb(ca), collection: resolve_crud_action_collection(ca), crud_action: true)
30
31
  end
31
32
  end
32
33
 
33
- def crud_actions
34
- actions.select{ |x| x.crud_action }
34
+ def resolve_crud_action_verb(ca)
35
+ case ca
36
+ when :create
37
+ :post
38
+ when :update
39
+ :patch
40
+ when :destroy
41
+ :delete
42
+ else
43
+ :get
44
+ end
45
+ end
46
+
47
+ def resolve_crud_action_collection(ca)
48
+ %i[index new create].include?(ca)
35
49
  end
36
50
 
37
- def additional_actions
38
- actions.select{ |x| !x.crud_action }
51
+ def crud_actions
52
+ actions.select{ |x| x.crud_action }
39
53
  end
40
54
 
41
55
  def member_actions
42
- additional_actions.select{ |x| !x.collection }
56
+ actions.select{ |x| !x.collection }
43
57
  end
44
58
 
45
59
  def collection_actions
46
- additional_actions.select{ |x| x.collection }
60
+ actions.select{ |x| x.collection }
47
61
  end
48
62
 
49
63
  def datatable_bulk_actions
50
- collection_actions.select{ |x| x.show_in_datatable }
64
+ collection_actions.select{ |x| x.show_in_datatable && !x.crud_action }
51
65
  end
52
66
 
53
67
  def unpersisted_crud_actions
@@ -96,7 +110,25 @@ module Olivander
96
110
  def build_resource_routes(mapper)
97
111
  resources.keys.each do |k|
98
112
  r = resources[k]
99
- mapper.resources r.model, only: r.crud_actions.map{ |ca| ca.action } do
113
+ mapper.resources r.model, only: [] do
114
+ mapper.collection do
115
+ r.collection_actions.each do |ba|
116
+ next if ba.no_route
117
+ next if ba.action == :new
118
+
119
+ if ba.confirm
120
+ mapper.get ba.action, action: "confirm_#{ba.action}"
121
+ mapper.post ba.action
122
+ else
123
+ mapper.send(ba.verb, ba.action)
124
+ end
125
+ end
126
+ end
127
+
128
+ mapper.new do
129
+ mapper.get :new
130
+ end if r.collection_actions.select{ |x| x.action == :new }.size.positive?
131
+
100
132
  mapper.member do
101
133
  r.member_actions.each do |ma|
102
134
  next if ma.no_route
@@ -108,18 +140,6 @@ module Olivander
108
140
  end
109
141
  end
110
142
  end
111
-
112
- mapper.collection do
113
- r.collection_actions.each do |ba|
114
- next if ba.no_route
115
- if ba.confirm
116
- mapper.get ba.action, action: "confirm_#{ba.action}"
117
- mapper.post ba.action
118
- else
119
- mapper.send(ma.verb, ba.action)
120
- end
121
- end
122
- end
123
143
  end
124
144
  end
125
145
  end
@@ -21,8 +21,8 @@ module Olivander
21
21
  plural_name = resource.is_a?(Class) ? resource.table_name : resource.class.table_name
22
22
  routed_resource = route_builder.resources[plural_name.to_sym]
23
23
  actions = resource.is_a?(Class) ?
24
- (routed_resource.unpersisted_crud_actions | routed_resource.collection_actions) :
25
- (resource.persisted? ? (routed_resource.persisted_crud_actions | routed_resource.member_actions): [])
24
+ (routed_resource.unpersisted_crud_actions | routed_resource.collection_actions.select{ |x| !x.crud_action }) :
25
+ (resource.persisted? ? (routed_resource.persisted_crud_actions | routed_resource.member_actions.select{ |x| !x.crud_action }): [])
26
26
  actions.reject{ |a| a.sym == for_action }
27
27
  end
28
28
 
@@ -1,3 +1,7 @@
1
+ - if @context.nil?
2
+ - parts = datatable.class.name.split('::')
3
+ - parts[parts.size-1] = 'Controller'
4
+ - parts.join('::').constantize.new.build_context
1
5
  = dropdown(variation: :dropleft, btn_class: btn_class) do
2
- - authorized_resource_actions(resource, for_action: action_name).select{ |x| x.show_in_datatable }.each do |a|
6
+ - authorized_resource_actions(@context.route_builder, resource, for_action: action_name).select{ |x| x.show_in_datatable }.each do |a|
3
7
  = dropdown_link_to a.sym, { controller: a.controller, action: a.action, id: resource.id }
@@ -1,3 +1,3 @@
1
1
  module Olivander
2
- VERSION = "0.1.2.4"
2
+ VERSION = "0.1.2.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: five-two-nw-olivander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.4
4
+ version: 0.1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dennis