Class: ElasticGraph::Support::FromYamlFile::ForRakeTasks
- Inherits:
-
Module
- Object
- Module
- ElasticGraph::Support::FromYamlFile::ForRakeTasks
- Defined in:
- lib/elastic_graph/support/from_yaml_file.rb
Overview
An extension module that provides a from_yaml_file factory method on a RakeTasks class.
This is designed for a RakeTasks class that needs an ElasticGraph component (e.g. an ElasticGraph::GraphQL, ElasticGraph::Admin, or ElasticGraph::Indexer instance). When the schema artifacts are out of date, loading those components can fail. This gracefully handles that for you, giving you clear instructions of what to do when this happens.
This requires the RakeTasks class to accept the ElasticGraph component instance via a block so that it happens lazily.
Instance Method Summary collapse
-
#initialize(component_class) ⇒ ForRakeTasks
constructor
A new instance of ForRakeTasks.
Constructor Details
#initialize(component_class) ⇒ ForRakeTasks
Returns a new instance of ForRakeTasks.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/elastic_graph/support/from_yaml_file.rb', line 39 def initialize(component_class) define_method :from_yaml_file do |yaml_file, *args, **| __skip__ = new(*args, **) do component_class.from_yaml_file(yaml_file) rescue => e raise <<~EOS Failed to load `#{component_class}` with `#{yaml_file}`. This can happen if the schema artifacts are out of date. Run `rake schema_artifacts:dump` and try again. #{e.class}: #{e.} EOS end end end |