Class: Eco::API::UseCases::GraphQL::Samples::Pages::Page::Base
- Inherits:
-
Base
- Object
- Loaders::Base
- Common::Loaders::CaseBase
- Common::Loaders::UseCase
- Base
- Eco::API::UseCases::GraphQL::Samples::Pages::Page::Base
- Includes:
- DSL
- Defined in:
- lib/eco/api/usecases/graphql/samples/pages/page/base.rb
Overview
Base class for register-scoped page processing use cases.
Provides the iteration + KPI scaffolding mirroring RegisterUpdateCase from OozeSamples, but working natively with the GraphQL stack.
== Subclass interface
class Custom::UseCase::UpdateRiskRating < Eco::API::UseCases::GraphQL::Samples::Pages::Page::Base name 'update-risk-rating' register_id 'REG_ABC123' batch_size 50
# Add filters on top of the default register scope.
def search_conf
super.filter(state_is(:active))
.filter(updated_since(.dig(:filters, :from).to_s))
end
# Transform or act on each page; call update_page(page) to persist.
def process_page(page)
field = page.components.get_by_name('Risk Level')
return skip('no risk field') unless field
page.name = "[HIGH] #{page.name}" if field.value == 'High'
update_page(page)
end
end
== What the base provides
- process_page(page) — override point (required)
- search_conf — override point (optional; default scopes to register_id)
- update_page(page) — from_model + simulate? guard + error tracking
- skip(reason) — record a non-error skip
- each_page — cursor-paginated org search
- KPI tracking — total / processed / updated / skipped / failed
Direct Known Subclasses
Instance Attribute Summary collapse
-
#failed_pages ⇒ Object
readonly
Returns the value of attribute failed_pages.
-
#processed_pages ⇒ Object
readonly
Returns the value of attribute processed_pages.
-
#skipped_pages ⇒ Object
readonly
Returns the value of attribute skipped_pages.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
-
#updated_pages ⇒ Object
readonly
Returns the value of attribute updated_pages.
Attributes included from Lib::ErrorHandling
Attributes included from Language::AuxiliarLogger
Class Method Summary collapse
Instance Method Summary collapse
-
#process ⇒ Object
Entry point — called by GraphQL::Base#main.
-
#process_page(_page) ⇒ Object
Transform or act on one page.
-
#search_conf ⇒ Object
Return a SearchConf for the page search.
Methods inherited from Base
Methods included from Language::Methods::CallDetector
Methods included from Language::AuxiliarLogger
Methods inherited from Common::Loaders::UseCase
#cli_apply!, #initialize, #main
Methods included from Common::Loaders::UseCase::CliIdentify
Methods included from Common::Loaders::UseCase::TargetModel
Methods included from Common::Loaders::UseCase::Type
Methods inherited from Common::Loaders::CaseBase
#name, name_only_once!, original_name
Constructor Details
This class inherits a constructor from Eco::API::Common::Loaders::UseCase
Instance Attribute Details
#failed_pages ⇒ Object (readonly)
Returns the value of attribute failed_pages.
57 58 59 |
# File 'lib/eco/api/usecases/graphql/samples/pages/page/base.rb', line 57 def failed_pages @failed_pages end |
#processed_pages ⇒ Object (readonly)
Returns the value of attribute processed_pages.
56 57 58 |
# File 'lib/eco/api/usecases/graphql/samples/pages/page/base.rb', line 56 def processed_pages @processed_pages end |
#skipped_pages ⇒ Object (readonly)
Returns the value of attribute skipped_pages.
57 58 59 |
# File 'lib/eco/api/usecases/graphql/samples/pages/page/base.rb', line 57 def skipped_pages @skipped_pages end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
56 57 58 |
# File 'lib/eco/api/usecases/graphql/samples/pages/page/base.rb', line 56 def total_pages @total_pages end |
#updated_pages ⇒ Object (readonly)
Returns the value of attribute updated_pages.
56 57 58 |
# File 'lib/eco/api/usecases/graphql/samples/pages/page/base.rb', line 56 def updated_pages @updated_pages end |
Class Method Details
.batch_size(size = nil) ⇒ Object
44 45 46 47 48 |
# File 'lib/eco/api/usecases/graphql/samples/pages/page/base.rb', line 44 def batch_size(size = nil) @batch_size ||= 50 return @batch_size unless size @batch_size = size end |
.register_id(id = nil) ⇒ Object
50 51 52 53 |
# File 'lib/eco/api/usecases/graphql/samples/pages/page/base.rb', line 50 def register_id(id = nil) @register_id = id if id @register_id end |
Instance Method Details
#process ⇒ Object
Entry point — called by GraphQL::Base#main.
60 61 62 63 64 65 66 67 |
# File 'lib/eco/api/usecases/graphql/samples/pages/page/base.rb', line 60 def process init_kpis each_page do |page| process_page(page) @processed_pages += 1 end log_kpis end |
#process_page(_page) ⇒ Object
Transform or act on one page. Call update_page(page) to persist changes.
72 73 74 |
# File 'lib/eco/api/usecases/graphql/samples/pages/page/base.rb', line 72 def process_page(_page) raise NotImplementedError, "Implement #process_page in #{self.class}" end |
#search_conf ⇒ Object
Return a SearchConf for the page search. Override to add filters. Default: scoped to register_id when set, otherwise all pages.
78 79 80 81 82 83 |
# File 'lib/eco/api/usecases/graphql/samples/pages/page/base.rb', line 78 def search_conf conf = sc.new reg = self.class.register_id conf = conf.filter(in_register(reg)) if reg conf end |