Class: Senren::Rails::ComponentInstaller
- Inherits:
-
Object
- Object
- Senren::Rails::ComponentInstaller
- Defined in:
- lib/senren/rails/component_installer.rb
Overview
Installs one or more registered Senren components into the host app and refreshes the generated guidance files afterward.
Constant Summary collapse
- USAGE =
'Usage: bin/rails senren:add NAME [NAME...] [--client | --no-client]'
Instance Attribute Summary collapse
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(registry: Registry.load!, paths: HostPaths.new, stdout: $stdout) ⇒ ComponentInstaller
constructor
A new instance of ComponentInstaller.
- #install(names:, client_override: nil, force: false) ⇒ Object
Constructor Details
#initialize(registry: Registry.load!, paths: HostPaths.new, stdout: $stdout) ⇒ ComponentInstaller
Returns a new instance of ComponentInstaller.
26 27 28 29 30 |
# File 'lib/senren/rails/component_installer.rb', line 26 def initialize(registry: Registry.load!, paths: HostPaths.new, stdout: $stdout) @registry = registry @paths = paths @stdout = stdout end |
Instance Attribute Details
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
16 17 18 |
# File 'lib/senren/rails/component_installer.rb', line 16 def paths @paths end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
16 17 18 |
# File 'lib/senren/rails/component_installer.rb', line 16 def registry @registry end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
16 17 18 |
# File 'lib/senren/rails/component_installer.rb', line 16 def stdout @stdout end |
Class Method Details
.normalize_names(names) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/senren/rails/component_installer.rb', line 18 def self.normalize_names(names) Array(names) .flatten .flat_map { |entry| entry.to_s.split(/[,\s]+/) } .reject { |entry| entry.empty? || entry.start_with?('-') } .uniq end |
Instance Method Details
#install(names:, client_override: nil, force: false) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/senren/rails/component_installer.rb', line 32 def install(names:, client_override: nil, force: false) normalized_names = self.class.normalize_names(names) raise ArgumentError, USAGE if normalized_names.empty? installed = ComponentCopier.new(registry: registry, paths: paths, stdout: stdout) .install(normalized_names, client_override: client_override, force: force) SkillWriter.new(registry: registry, paths: paths).sync! AgentRulesWriter.new(registry: registry, paths: paths).sync! stdout.puts "Installed: #{installed.join(', ')}" installed end |