Class: Olivander::Resources::ResourceAction

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/concerns/olivander/resources/route_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sym, action: nil, controller: nil, verb: :get, confirm: false, turbo_frame: nil, collection: false, crud_action: false, show_in_form: true, show_in_datatable: true, no_route: false, path_helper: nil, confirm_with: nil, primary: nil) ⇒ ResourceAction

Returns a new instance of ResourceAction.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 8

def initialize(sym, action: nil, controller: nil, verb: :get, confirm: false,
               turbo_frame: nil, collection: false, crud_action: false,
               show_in_form: true, show_in_datatable: true, no_route: false,
               path_helper: nil, confirm_with: nil, primary: nil)
  self.sym = sym
  self.action = action || sym
  self.controller = controller
  self.verb = verb
  self.confirm = confirm
  self.turbo_frame = turbo_frame
  self.collection = collection
  self.crud_action = crud_action
  self.show_in_form = show_in_form
  self.show_in_datatable = show_in_datatable
  self.no_route = no_route
  self.path_helper = path_helper
  self.confirm_with = confirm_with
  self.primary = primary || crud_action
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



4
5
6
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 4

def action
  @action
end

#collectionObject

Returns the value of attribute collection.



4
5
6
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 4

def collection
  @collection
end

#confirmObject

Returns the value of attribute confirm.



4
5
6
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 4

def confirm
  @confirm
end

#confirm_withObject

Returns the value of attribute confirm_with.



4
5
6
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 4

def confirm_with
  @confirm_with
end

#controllerObject

Returns the value of attribute controller.



4
5
6
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 4

def controller
  @controller
end

#crud_actionObject

Returns the value of attribute crud_action.



4
5
6
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 4

def crud_action
  @crud_action
end

#no_routeObject

Returns the value of attribute no_route.



4
5
6
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 4

def no_route
  @no_route
end

#path_helperObject

Returns the value of attribute path_helper.



4
5
6
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 4

def path_helper
  @path_helper
end

#primaryObject

Returns the value of attribute primary.



4
5
6
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 4

def primary
  @primary
end

#show_in_datatableObject

Returns the value of attribute show_in_datatable.



4
5
6
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 4

def show_in_datatable
  @show_in_datatable
end

#show_in_formObject

Returns the value of attribute show_in_form.



4
5
6
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 4

def show_in_form
  @show_in_form
end

#symObject

Returns the value of attribute sym.



4
5
6
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 4

def sym
  @sym
end

#turbo_frameObject

Returns the value of attribute turbo_frame.



4
5
6
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 4

def turbo_frame
  @turbo_frame
end

#verbObject

Returns the value of attribute verb.



4
5
6
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 4

def verb
  @verb
end

Instance Method Details

#args_hash(options = nil) ⇒ Object



28
29
30
31
32
33
34
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 28

def args_hash(options = nil)
  {}.tap do |h|
    h.merge!(method: verb) if turbo_frame.blank?
    h.merge!(data: data_hash)
    h.merge!(options) if options.present?
  end
end

#confirm_keyObject



45
46
47
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 45

def confirm_key
  turbo_frame.present? ? :turbo_confirm : :confirm
end

#confirmation_messageObject



49
50
51
52
53
54
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 49

def confirmation_message
  return confirm_with if confirm_with.present?
  return I18n.t('activerecord.actions.delete-confirmation') if verb == :delete

  nil
end

#data_hashObject



36
37
38
39
40
41
42
43
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 36

def data_hash
  {}.tap do |h|
    h.merge!(turbo: true, turbo_method: verb, turbo_frame: turbo_frame) if turbo_frame.present?

    message = confirmation_message
    h.merge!(confirm_key => message) unless message.blank?
  end
end