Module: Munola::Catalogue
- Defined in:
- lib/munola/catalogue.rb
Overview
The recipes munola ships built in, read from the enola-guides gem so the content has one version line; the template carries a value the installer fills in from what the app shows.
Constant Summary collapse
- RECIPES =
%w[ember-conventions data-ownership api-boundaries background-work tenant-foreign-key].freeze
- TEMPLATES =
%w[tenant-foreign-key].freeze
- PLACEHOLDERS =
{ column: "TENANT_COLUMN", table: "TENANT_TABLE" }.freeze
Class Method Summary collapse
- .fill(body, tenant) ⇒ Object
- .source(name) ⇒ Object
- .source_dir ⇒ Object
-
.write(root, tenant: nil) ⇒ Object
Writes every catalogue recipe the project does not already have into enola/recipes/, the template with its values filled or, without them, left as it is so the placeholders show what to decide.
Class Method Details
.fill(body, tenant) ⇒ Object
43 44 45 |
# File 'lib/munola/catalogue.rb', line 43 def self.fill(body, tenant) body.gsub(PLACEHOLDERS[:column], tenant.fetch(:column)).gsub(PLACEHOLDERS[:table], tenant.fetch(:table)) end |
.source(name) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/munola/catalogue.rb', line 19 def self.source(name) path = File.join(source_dir, "#{name}.yaml") raise Enola::Unavailable, "the installed enola-guides gem has no recipe #{name}; it needs 0.3.1 or later" unless File.exist?(path) path end |
.source_dir ⇒ Object
14 15 16 17 |
# File 'lib/munola/catalogue.rb', line 14 def self.source_dir require "enola-rb" File.join(EnolaRb::Guides.root, "recipes") end |
.write(root, tenant: nil) ⇒ Object
Writes every catalogue recipe the project does not already have into enola/recipes/, the template with its values filled or, without them, left as it is so the placeholders show what to decide.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/munola/catalogue.rb', line 29 def self.write(root, tenant: nil) dir = File.join(root, "enola", "recipes") FileUtils.mkdir_p(dir) RECIPES.each_with_object([]) do |name, written| target = File.join(dir, "#{name}.yaml") next if File.exist?(target) body = File.read(source(name)) body = fill(body, tenant) if TEMPLATES.include?(name) && tenant File.write(target, body) written << target end end |