Class: Golden::QueryFormOperator
- Inherits:
-
ApplicationOperator
- Object
- ApplicationOperator
- Golden::QueryFormOperator
- Extended by:
- ActiveModel::Callbacks
- Defined in:
- lib/golden/objects/query/query_form_operator.rb
Instance Attribute Summary collapse
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
-
.has_query_form(form: nil, form_presenter: nil, result_presenter: nil, record_presenter: nil) ⇒ Object
rubocop:disable Naming/PredicateName.
Instance Method Summary collapse
- #form_presenter ⇒ Object
-
#initialize(params, accessors = {}) ⇒ QueryFormOperator
constructor
A new instance of QueryFormOperator.
- #perform ⇒ Object
- #result_presenter ⇒ Object
Methods included from DatepickerConcern
#filter_dates_of_datepicker, #filter_duration_of_datepicker
Constructor Details
#initialize(params, accessors = {}) ⇒ QueryFormOperator
Returns a new instance of QueryFormOperator.
42 43 44 45 46 |
# File 'lib/golden/objects/query/query_form_operator.rb', line 42 def initialize(params, accessors = {}) @params = params assign_attributes(accessors || {}) run_callbacks(:build_form) { @form ||= build_form } end |
Instance Attribute Details
#form ⇒ Object (readonly)
Returns the value of attribute form.
40 41 42 |
# File 'lib/golden/objects/query/query_form_operator.rb', line 40 def form @form end |
#mode ⇒ Object
Returns the value of attribute mode.
39 40 41 |
# File 'lib/golden/objects/query/query_form_operator.rb', line 39 def mode @mode end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
40 41 42 |
# File 'lib/golden/objects/query/query_form_operator.rb', line 40 def params @params end |
Class Method Details
.has_query_form(form: nil, form_presenter: nil, result_presenter: nil, record_presenter: nil) ⇒ Object
rubocop:disable Naming/PredicateName
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/golden/objects/query/query_form_operator.rb', line 7 def has_query_form(form: nil, form_presenter: nil, result_presenter: nil, record_presenter: nil) define_method :form_class do return form.to_s.constantize if form.present? "#{self.class.parent.name}::QueryForm".constantize end define_method :form_presenter_class do return form_presenter.to_s.constantize if form_presenter.present? "#{self.class.parent.name}::QueryFormPresenter".constantize end define_method :result_presenter_class do return result_presenter.to_s.constantize if result_presenter.present? "#{self.class.parent.name}::QueryResultPresenter".constantize end define_method :record_presenter_class do return record_presenter.to_s.constantize if record_presenter.present? "#{self.class.parent.name}::QueryRecordPresenter".constantize end end |
Instance Method Details
#form_presenter ⇒ Object
54 55 56 |
# File 'lib/golden/objects/query/query_form_operator.rb', line 54 def form_presenter @form_presenter ||= form_presenter_class.new form end |
#perform ⇒ Object
48 49 50 51 52 |
# File 'lib/golden/objects/query/query_form_operator.rb', line 48 def perform form.save errors.merge! form.errors errors.empty? end |
#result_presenter ⇒ Object
58 59 60 |
# File 'lib/golden/objects/query/query_form_operator.rb', line 58 def result_presenter @result_presenter ||= result_presenter_class.collect query_result, record_presenter_class.name end |