five-two-nw-olivander 0.1.2.4 → 0.1.2.5

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: d551785ee277728e208fb537527d00e201b93b89f796de075295f271c90ff879
4
- data.tar.gz: f079e183a76a7724c16099542aeaef9159f5d4ff64ef227267a8de6dcd03b7c0
3
+ metadata.gz: c0e0ab6690c2db84473cb79a4287db92eacc150390017c848b84a9297bcf182f
4
+ data.tar.gz: d075048882ce46be84002ee1e14618777bc9d0a3b6ded2709fb002b39b446d2a
5
5
  SHA512:
6
- metadata.gz: 1abaa3d2a03cb74f5d38077e2070a90ca63a12f27799a6d000fdb3506272c9890b284fbc76a59049bd1b5fe1766d51f11658f96fe28298baf83e80ab7436719e
7
- data.tar.gz: dadd557fabc44933a35bf795173c37d3753b7f40cfae8fa2979978923b78312904e96c8a66e12da01a46fbb24917f22476a5ca72ea815f7358f56fc7766a6a90
6
+ metadata.gz: 8310faaad17dcdf36bfdcf63aeb1378ae1b5a630e4cbe8bd1d75ae9745f4d8bfd363514ff4150d0027ac1015487b1febcaa863c9ed86a7f990ab917242f1c440
7
+ data.tar.gz: d033c74985c4e1e963b44932c4cf9a7aabd3b31d1f283d1fd89443e37375dc0343da80300d7608c3069b89e7f776f8718979538bd8163628ca94a49182d7e123
@@ -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
@@ -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.5"
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.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dennis