Class: Practical::Loaders::Base
- Inherits:
-
Object
- Object
- Practical::Loaders::Base
- Includes:
- Pagy::Method
- Defined in:
- app/lib/practical/loaders/base.rb
Instance Attribute Summary collapse
-
#base_relation ⇒ Object
Returns the value of attribute base_relation.
-
#datatable_form ⇒ Object
Returns the value of attribute datatable_form.
-
#pagy_instance ⇒ Object
Returns the value of attribute pagy_instance.
-
#records ⇒ Object
Returns the value of attribute records.
-
#relation_builder ⇒ Object
Returns the value of attribute relation_builder.
-
#request ⇒ Object
Returns the value of attribute request.
Class Method Summary collapse
Instance Method Summary collapse
- #build_datatable_form ⇒ Object
- #build_relation_builder ⇒ Object
- #datatable_params ⇒ Object
- #datatable_payload ⇒ Object
- #default_payload ⇒ Object
-
#initialize(request:, base_relation:) ⇒ Base
constructor
A new instance of Base.
- #load ⇒ Object
- #params ⇒ Object
Constructor Details
#initialize(request:, base_relation:) ⇒ Base
Returns a new instance of Base.
11 12 13 14 |
# File 'app/lib/practical/loaders/base.rb', line 11 def initialize(request:, base_relation:) self.request = request self.base_relation = base_relation end |
Instance Attribute Details
#base_relation ⇒ Object
Returns the value of attribute base_relation.
6 7 8 |
# File 'app/lib/practical/loaders/base.rb', line 6 def base_relation @base_relation end |
#datatable_form ⇒ Object
Returns the value of attribute datatable_form.
6 7 8 |
# File 'app/lib/practical/loaders/base.rb', line 6 def datatable_form @datatable_form end |
#pagy_instance ⇒ Object
Returns the value of attribute pagy_instance.
6 7 8 |
# File 'app/lib/practical/loaders/base.rb', line 6 def pagy_instance @pagy_instance end |
#records ⇒ Object
Returns the value of attribute records.
6 7 8 |
# File 'app/lib/practical/loaders/base.rb', line 6 def records @records end |
#relation_builder ⇒ Object
Returns the value of attribute relation_builder.
6 7 8 |
# File 'app/lib/practical/loaders/base.rb', line 6 def relation_builder @relation_builder end |
#request ⇒ Object
Returns the value of attribute request.
6 7 8 |
# File 'app/lib/practical/loaders/base.rb', line 6 def request @request end |
Class Method Details
.load(request:, base_relation:) ⇒ Object
16 17 18 19 20 |
# File 'app/lib/practical/loaders/base.rb', line 16 def self.load(request:, base_relation:) instance = self.new(request: request, base_relation: base_relation) instance.load return instance end |
Instance Method Details
#build_datatable_form ⇒ Object
36 37 38 |
# File 'app/lib/practical/loaders/base.rb', line 36 def build_datatable_form raise NotImplementedError end |
#build_relation_builder ⇒ Object
40 41 42 |
# File 'app/lib/practical/loaders/base.rb', line 40 def build_relation_builder raise NotImplementedError end |
#datatable_params ⇒ Object
32 33 34 |
# File 'app/lib/practical/loaders/base.rb', line 32 def datatable_params params.permit(datatable: [:sort_key, :sort_direction, filters: {}]) end |
#datatable_payload ⇒ Object
28 29 30 |
# File 'app/lib/practical/loaders/base.rb', line 28 def datatable_payload (datatable_params[:datatable] || default_payload) end |
#default_payload ⇒ Object
44 45 46 |
# File 'app/lib/practical/loaders/base.rb', line 44 def default_payload raise NotImplementedError end |
#load ⇒ Object
22 23 24 25 26 |
# File 'app/lib/practical/loaders/base.rb', line 22 def load self.datatable_form = build_datatable_form self.relation_builder = build_relation_builder self.pagy_instance, self.records = pagy(relation_builder.applied_relation) end |
#params ⇒ Object
48 49 50 51 |
# File 'app/lib/practical/loaders/base.rb', line 48 def params return request.params if request.params.kind_of?(ActionController::Parameters) return ActionController::Parameters.new(request.params) end |