Class: Golden::ActionFormOperator
- Inherits:
-
ApplicationOperator
- Object
- ApplicationOperator
- Golden::ActionFormOperator
- Extended by:
- ActiveModel::Callbacks
- Defined in:
- lib/golden/objects/form/action_form_operator.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#form ⇒ Object
Returns the value of attribute form.
-
#params ⇒ Object
Returns the value of attribute params.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
-
.has_actions(actions, form: nil, presenter: nil) ⇒ Object
rubocop:disable Naming/PredicateName.
Instance Method Summary collapse
- #form_presenter ⇒ Object
-
#initialize(params, accessors = {}) ⇒ ActionFormOperator
constructor
A new instance of ActionFormOperator.
- #perform ⇒ Object
- #valid?(context = nil) ⇒ Boolean
Methods included from DatepickerConcern
#filter_dates_of_datepicker, #filter_duration_of_datepicker
Constructor Details
#initialize(params, accessors = {}) ⇒ ActionFormOperator
Returns a new instance of ActionFormOperator.
39 40 41 42 43 44 |
# File 'lib/golden/objects/form/action_form_operator.rb', line 39 def initialize(params, accessors = {}) @params = params @action = params[:action]&.to_sym assign_attributes(accessors || {}) run_callbacks(:build_form) { @form ||= build_form } end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
30 31 32 |
# File 'lib/golden/objects/form/action_form_operator.rb', line 30 def action @action end |
#form ⇒ Object
Returns the value of attribute form.
29 30 31 |
# File 'lib/golden/objects/form/action_form_operator.rb', line 29 def form @form end |
#params ⇒ Object
Returns the value of attribute params.
30 31 32 |
# File 'lib/golden/objects/form/action_form_operator.rb', line 30 def params @params end |
#user ⇒ Object
Returns the value of attribute user.
29 30 31 |
# File 'lib/golden/objects/form/action_form_operator.rb', line 29 def user @user end |
Class Method Details
.has_actions(actions, form: nil, presenter: nil) ⇒ Object
rubocop:disable Naming/PredicateName
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/golden/objects/form/action_form_operator.rb', line 7 def has_actions(actions, form: nil, presenter: nil) define_method :actions do actions end define_method :form_class do return form.to_s.constantize if form.present? "#{action.capitalize}Form".constantize end define_method :presenter_class do return presenter.to_s.constantize if presenter.present? "#{action.capitalize}FormPresenter".constantize end end |
Instance Method Details
#form_presenter ⇒ Object
59 60 61 |
# File 'lib/golden/objects/form/action_form_operator.rb', line 59 def form_presenter @form_presenter ||= presenter_class.new(form) end |
#perform ⇒ Object
52 53 54 55 56 57 |
# File 'lib/golden/objects/form/action_form_operator.rb', line 52 def perform return if invalid? run_callbacks(:save_form) { save_form } errors.empty? end |
#valid?(context = nil) ⇒ Boolean
46 47 48 49 50 |
# File 'lib/golden/objects/form/action_form_operator.rb', line 46 def valid?(context = nil) super run_callbacks(:validate_form) { validate_form } errors.empty? end |