Class: CurationConcerns::Workflow::WorkflowImporter
- Inherits:
-
Object
- Object
- CurationConcerns::Workflow::WorkflowImporter
- Extended by:
- Forwardable
- Defined in:
- app/services/curation_concerns/workflow/workflow_importer.rb
Defined Under Namespace
Modules: SchemaValidator
Class Method Summary collapse
-
.generate_from_json_file(path:, **keywords) ⇒ Array<Sipity::Workflow>
Responsible for generating the work type and corresponding processing entries based on given pathname or JSON document.
-
.load_workflows ⇒ TrueClass
Load all the workflows in config/workflows/*.json.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(data:, schema: default_schema, validator: default_validator) ⇒ WorkflowImporter
constructor
A new instance of WorkflowImporter.
Constructor Details
#initialize(data:, schema: default_schema, validator: default_validator) ⇒ WorkflowImporter
Returns a new instance of WorkflowImporter.
30 31 32 33 34 35 |
# File 'app/services/curation_concerns/workflow/workflow_importer.rb', line 30 def initialize(data:, schema: default_schema, validator: default_validator) self.data = data self.schema = schema self.validator = validator validate! end |
Class Method Details
.generate_from_json_file(path:, **keywords) ⇒ Array<Sipity::Workflow>
Responsible for generating the work type and corresponding processing entries based on given pathname or JSON document.
21 22 23 24 25 |
# File 'app/services/curation_concerns/workflow/workflow_importer.rb', line 21 def self.generate_from_json_file(path:, **keywords) contents = path.respond_to?(:read) ? path.read : File.read(path) data = JSON.parse(contents) new(data: data, **keywords).call end |
.load_workflows ⇒ TrueClass
Load all the workflows in config/workflows/*.json
8 9 10 11 12 13 14 |
# File 'app/services/curation_concerns/workflow/workflow_importer.rb', line 8 def self.load_workflows Dir.glob(Rails.root + "config/workflows/*.json") do |config| Rails.logger.info "Loading workflow: #{config}" generate_from_json_file(path: config) end true end |
Instance Method Details
#call ⇒ Object
63 64 65 66 67 |
# File 'app/services/curation_concerns/workflow/workflow_importer.rb', line 63 def call Array.wrap(data.fetch(:workflows)).map do |configuration| find_or_create_from(configuration: configuration) end end |