Class: RubyCms::FileInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_cms/file_installer.rb

Overview

Copies the template files belonging to a set of modules into a host app.

Instance Method Summary collapse

Constructor Details

#initialize(templates_root:, app_root:) ⇒ FileInstaller

Returns a new instance of FileInstaller.



10
11
12
13
# File 'lib/ruby_cms/file_installer.rb', line 10

def initialize(templates_root:, app_root:)
  @templates_root = Pathname.new(templates_root)
  @app_root = Pathname.new(app_root)
end

Instance Method Details

#install(modules) ⇒ Object

modules: array of Manifest::Module. Returns array of app-relative paths written.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ruby_cms/file_installer.rb', line 16

def install(modules)
  written = []
  modules.flat_map(&:files).uniq.each do |template_glob|
    expand(template_glob).each do |template_rel|
      src = @templates_root.join(template_rel)
      next unless src.file?

      dest = @app_root.join(PathMap.to_app(template_rel))
      FileUtils.mkdir_p(dest.dirname)
      FileUtils.cp(src, dest)
      written << dest.relative_path_from(@app_root).to_s
    end
  end
  written
end