Module: Locomotive::API::Helpers::PersistenceHelper
- Defined in:
- app/api/locomotive/api/helpers/persistence_helper.rb
Overview
Sets up model/repository methods. def translation_params
permitted_params[:translation]
end
def auth(meth)
Translation, meth
end
def translations
current_site.translations
end
def translation
@translation ||= translations.find(params[:id])
end
Instance Attribute Summary collapse
-
#resource_name ⇒ Object
Returns the value of attribute resource_name.
-
#use_form_object ⇒ Object
Returns the value of attribute use_form_object.
Instance Method Summary collapse
- #auth(meth) ⇒ Object
-
#current_policy(obj = nil) ⇒ Class
A class constant for the current Pundit policy on the object.
-
#form_klass ⇒ Class
A class constant for the matching form class.
- #persist_from_form(form_object) ⇒ Object
- #setup_resource_methods_for(resource_name) ⇒ Object
Instance Attribute Details
#resource_name ⇒ Object
Returns the value of attribute resource_name.
26 27 28 |
# File 'app/api/locomotive/api/helpers/persistence_helper.rb', line 26 def resource_name @resource_name end |
#use_form_object ⇒ Object
Returns the value of attribute use_form_object.
26 27 28 |
# File 'app/api/locomotive/api/helpers/persistence_helper.rb', line 26 def use_form_object @use_form_object end |
Instance Method Details
#auth(meth) ⇒ Object
60 61 62 |
# File 'app/api/locomotive/api/helpers/persistence_helper.rb', line 60 def auth(meth) persistence_klass, meth end |
#current_policy(obj = nil) ⇒ Class
Returns a class constant for the current Pundit policy on the object.
47 48 49 50 |
# File 'app/api/locomotive/api/helpers/persistence_helper.rb', line 47 def current_policy(obj = nil) obj = obj ? obj : send(singular) policy_klass.new(pundit_user, obj) end |
#form_klass ⇒ Class
Returns a class constant for the matching form class.
40 41 42 |
# File 'app/api/locomotive/api/helpers/persistence_helper.rb', line 40 def form_klass namespaced_klass("#{singular}_form") end |
#persist_from_form(form_object) ⇒ Object
Note:
if the object exists it will be updated
55 56 57 58 |
# File 'app/api/locomotive/api/helpers/persistence_helper.rb', line 55 def persist_from_form(form_object) send(singular).assign_attributes(form_object.serializable_hash) send(singular).save! end |
#setup_resource_methods_for(resource_name) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'app/api/locomotive/api/helpers/persistence_helper.rb', line 28 def setup_resource_methods_for(resource_name) self.resource_name = resource_name.to_s setup_plural_method setup_singular_getter_method setup_singular_setter_method setup_params_method setup_object_auth_method end |