Class: Senren::Rails::ComponentCopier

Inherits:
Object
  • Object
show all
Defined in:
lib/senren/rails/component_copier.rb

Overview

Copies component files from the gem's templates/ tree into the host Rails app, and updates .senren/installed_components.yml.

Defined Under Namespace

Classes: MissingTemplate

Constant Summary collapse

INSTALL_GENERATOR_TEMPLATES =
File.expand_path(
  '../../generators/senren/install/templates', __dir__
).freeze
BASE_COMPONENT_TEMPLATE =
File.join(INSTALL_GENERATOR_TEMPLATES, 'base_component.rb.tt').freeze
BASE_URL_HELPER_PATCH =
BaseComponentPatch::URL_HELPERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry: Registry.load!, paths: HostPaths.new, stdout: $stdout) ⇒ ComponentCopier

Returns a new instance of ComponentCopier.



25
26
27
28
29
# File 'lib/senren/rails/component_copier.rb', line 25

def initialize(registry: Registry.load!, paths: HostPaths.new, stdout: $stdout)
  @registry = registry
  @paths    = paths
  @stdout   = stdout
end

Instance Attribute Details

#pathsObject (readonly)

Returns the value of attribute paths.



23
24
25
# File 'lib/senren/rails/component_copier.rb', line 23

def paths
  @paths
end

#registryObject (readonly)

Returns the value of attribute registry.



23
24
25
# File 'lib/senren/rails/component_copier.rb', line 23

def registry
  @registry
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



23
24
25
# File 'lib/senren/rails/component_copier.rb', line 23

def stdout
  @stdout
end

Instance Method Details

#install(component_names, client_override: nil, force: false) ⇒ Object

Installs a list of components (with deps), respecting the override flag. Returns the ordered list of component names actually installed.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/senren/rails/component_copier.rb', line 33

def install(component_names, client_override: nil, force: false)
  wanted = registry.dependencies(*component_names)
  validate_client_override!(component_names, client_override)
  paths.ensure_dirs!
  ensure_base_component_url_helpers!

  requested = Array(component_names).map(&:to_s)
  wanted.each do |name|
    comp = registry.fetch(name)
    install_component(comp, client_override: override_for(name, requested, client_override), force: force)
  end

  update_installed_ledger(wanted, requested: requested, client_override: client_override)
  wanted
end