Class: MatViews::Services::BaseService Abstract
- Inherits:
-
Object
- Object
- MatViews::Services::BaseService
- Defined in:
- lib/mat_views/services/base_service.rb
Overview
Base class for service objects that operate on PostgreSQL materialised views (create/refresh/delete, schema discovery, quoting, and common response helpers).
Concrete services (e.g., CreateView, RegularRefresh) should inherit from this class.
Direct Known Subclasses
CheckMatviewExists, ConcurrentRefresh, CreateView, DeleteView, RegularRefresh, SwapRefresh
Constant Summary collapse
- UNKNOWN_ROW_COUNT =
Constant indicating unknown row count
-1- ALLOWED_ROW_STRATEGIES =
Allowed row count strategies
i[none estimated exact].freeze
- DEFAULT_ROW_STRATEGY =
Default row count strategy
:estimated- DEFAULT_NIL_STRATEGY =
Default strategy when nil or unrecognized value is given
:none
Instance Attribute Summary collapse
-
#definition ⇒ MatViews::MatViewDefinition
readonly
The target materialised view definition.
-
#request ⇒ Hash
request hash to be returned in service response.
-
#response ⇒ Hash
response hash to be returned in service response.
-
#row_count_strategy ⇒ Symbol?
readonly
Row count strategy (‘:estimated`, `:exact`, `nil`).
-
#use_transaction ⇒ Boolean
wrap in transaction.
Instance Method Summary collapse
-
#call ⇒ MatViews::ServiceResponse
Execute the service operation.
-
#initialize(definition, row_count_strategy: DEFAULT_ROW_STRATEGY) ⇒ BaseService
constructor
A new instance of BaseService.
Constructor Details
#initialize(definition, row_count_strategy: DEFAULT_ROW_STRATEGY) ⇒ BaseService
Returns a new instance of BaseService.
78 79 80 81 82 83 84 |
# File 'lib/mat_views/services/base_service.rb', line 78 def initialize(definition, row_count_strategy: DEFAULT_ROW_STRATEGY) @definition = definition @row_count_strategy = extract_row_strategy(row_count_strategy) @request = {} @response = {} @use_transaction = true end |
Instance Attribute Details
#definition ⇒ MatViews::MatViewDefinition (readonly)
Returns The target materialised view definition.
51 52 53 |
# File 'lib/mat_views/services/base_service.rb', line 51 def definition @definition end |
#request ⇒ Hash
request hash to be returned in service response
62 63 64 |
# File 'lib/mat_views/services/base_service.rb', line 62 def request @request end |
#response ⇒ Hash
response hash to be returned in service response
67 68 69 |
# File 'lib/mat_views/services/base_service.rb', line 67 def response @response end |
#row_count_strategy ⇒ Symbol? (readonly)
Row count strategy (‘:estimated`, `:exact`, `nil`).
57 58 59 |
# File 'lib/mat_views/services/base_service.rb', line 57 def row_count_strategy @row_count_strategy end |
#use_transaction ⇒ Boolean
wrap in transaction
72 73 74 |
# File 'lib/mat_views/services/base_service.rb', line 72 def use_transaction @use_transaction end |
Instance Method Details
#call ⇒ MatViews::ServiceResponse
Execute the service operation.
Calls #assign_request, #prepare and #_run in order.
Concrete subclasses must implement these methods.
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/mat_views/services/base_service.rb', line 95 def call if use_transaction ActiveRecord::Base.transaction { run_core } else run_core end rescue StandardError => e # finish pending transaction if any # eg: current transaction is aborted, commands ignored until end of transaction block error_response(e) end |