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, **kwargs) ⇒ ResourceAction

Returns a new instance of ResourceAction.



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 9

def initialize(sym, **kwargs)
  self.sym = sym
  self.action = kwargs[:action] || sym
  self.controller = kwargs[:controller]
  self.verb = kwargs[:verb] || :get
  self.confirm = kwargs[:confirm] || false
  self.turbo_frame = kwargs[:turbo_frame]
  self.turbo = kwargs[:turbo] == true ? true : !turbo_frame.blank?
  self.collection = default_if_not_present(kwargs[:collection], false)
  self.crud_action = default_if_not_present(kwargs[:crud_action], false)
  self.show_in_form = default_if_not_present(kwargs[:show_in_form], true)
  self.show_in_datatable = default_if_not_present(kwargs[:show_in_datatable], true)
  self.no_route = default_if_not_present(kwargs[:no_route], false)
  self.path_helper = kwargs[:path_helper]
  self.confirm_with = kwargs[:confirm_with]
  self.primary = kwargs[:primary] || crud_action
  self.html_attributes = kwargs[:html_attributes]
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

#html_attributesObject

Returns the value of attribute html_attributes.



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

def html_attributes
  @html_attributes
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

#turboObject

Returns the value of attribute turbo.



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

def turbo
  @turbo
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



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

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

#confirm_keyObject



53
54
55
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 53

def confirm_key
  turbo ? :turbo_confirm : :confirm
end

#confirmation_messageObject



57
58
59
60
61
62
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 57

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

  nil
end

#data_hashObject



43
44
45
46
47
48
49
50
51
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 43

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

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

#default_if_not_present(value, default) ⇒ Object



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

def default_if_not_present(value, default)
  return value unless value.nil?

  default
end