Class: Olivander::Resources::ResourceAction
- Inherits:
-
Object
- Object
- Olivander::Resources::ResourceAction
- Defined in:
- app/controllers/concerns/olivander/resources/route_builder.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#collection ⇒ Object
Returns the value of attribute collection.
-
#confirm ⇒ Object
Returns the value of attribute confirm.
-
#confirm_with ⇒ Object
Returns the value of attribute confirm_with.
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#crud_action ⇒ Object
Returns the value of attribute crud_action.
-
#html_attributes ⇒ Object
Returns the value of attribute html_attributes.
-
#no_route ⇒ Object
Returns the value of attribute no_route.
-
#path_helper ⇒ Object
Returns the value of attribute path_helper.
-
#primary ⇒ Object
Returns the value of attribute primary.
-
#show_in_datatable ⇒ Object
Returns the value of attribute show_in_datatable.
-
#show_in_form ⇒ Object
Returns the value of attribute show_in_form.
-
#sym ⇒ Object
Returns the value of attribute sym.
-
#turbo ⇒ Object
Returns the value of attribute turbo.
-
#turbo_frame ⇒ Object
Returns the value of attribute turbo_frame.
-
#verb ⇒ Object
Returns the value of attribute verb.
Instance Method Summary collapse
- #args_hash(options = nil) ⇒ Object
- #confirm_key ⇒ Object
- #confirmation_message ⇒ Object
- #data_hash ⇒ Object
- #default_if_not_present(value, default) ⇒ Object
-
#initialize(sym, **kwargs) ⇒ ResourceAction
constructor
A new instance of ResourceAction.
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
#action ⇒ Object
Returns the value of attribute action.
4 5 6 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 4 def action @action end |
#collection ⇒ Object
Returns the value of attribute collection.
4 5 6 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 4 def collection @collection end |
#confirm ⇒ Object
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_with ⇒ Object
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 |
#controller ⇒ Object
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_action ⇒ Object
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_attributes ⇒ Object
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_route ⇒ Object
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_helper ⇒ Object
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 |
#primary ⇒ Object
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_datatable ⇒ Object
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_form ⇒ Object
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 |
#sym ⇒ Object
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 ⇒ Object
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_frame ⇒ Object
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 |
#verb ⇒ Object
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( = nil) {}.tap do |h| h.merge!(method: verb) unless turbo h.merge!(data: data_hash) h.merge!(html_attributes) if html_attributes h.merge!() if .present? end end |
#confirm_key ⇒ Object
53 54 55 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 53 def confirm_key turbo ? :turbo_confirm : :confirm end |
#confirmation_message ⇒ Object
57 58 59 60 61 62 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 57 def return confirm_with if confirm_with.present? return O18n.t('activerecord.actions.delete-confirmation') if verb == :delete nil end |
#data_hash ⇒ Object
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? = h.merge!(confirm_key => ) unless .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 |