Class: OpenehrRails::TemplateImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/openehr_rails/template_importer.rb

Overview

Fetches an OPT from a URL, validates it, stores it under app/templates/operational and registers it in the template registry. Used by the admin engine's URL-import field (the URL counterpart to TemplateUploader's drag & drop).

Defined Under Namespace

Classes: InvalidTemplate

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, root:, registry:) ⇒ TemplateImporter

Returns a new instance of TemplateImporter.



17
18
19
20
21
# File 'lib/openehr_rails/template_importer.rb', line 17

def initialize(url:, root:, registry:)
  @url = url
  @root = Pathname.new(root)
  @registry = registry
end

Class Method Details

.call(url:, root: ::Rails.root, registry: ::OpenehrTemplate) ⇒ Object



13
14
15
# File 'lib/openehr_rails/template_importer.rb', line 13

def self.call(url:, root: ::Rails.root, registry: ::OpenehrTemplate)
  new(url: url, root: root, registry: registry).call
end

Instance Method Details

#callObject



23
24
25
26
27
28
29
30
31
# File 'lib/openehr_rails/template_importer.rb', line 23

def call
  content = fetch_content
  template_id = OpenehrRails::Opt.parse(content).template_id.value

  path = storage_path(template_id)
  FileUtils.mkdir_p(path.dirname)
  File.binwrite(path, content)
  @registry.from_opt_file(path.to_s)
end