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.
27 28 29 30 31 |
# File 'lib/senren/rails/component_installer.rb', line 27 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.
17 18 19 |
# File 'lib/senren/rails/component_installer.rb', line 17 def paths @paths end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
17 18 19 |
# File 'lib/senren/rails/component_installer.rb', line 17 def registry @registry end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
17 18 19 |
# File 'lib/senren/rails/component_installer.rb', line 17 def stdout @stdout end |
Class Method Details
.normalize_names(names) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/senren/rails/component_installer.rb', line 19 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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/senren/rails/component_installer.rb', line 33 def install(names:, client_override: nil, force: false) normalized_names = self.class.normalize_names(names) raise ArgumentError, USAGE if normalized_names.empty? # Preflight. Everything below writes to disk, and a failure partway # through leaves components copied, the ledger updated and the guidance # files stale -- which is exactly what the first version of the adapter # collision check did. AgentRulesWriter.new(registry: registry, paths: paths).assert_distinct_adapters! installed = ComponentCopier.new(registry: registry, paths: paths, stdout: stdout) .install(normalized_names, client_override: client_override, force: force) refresh_registry_mirror SkillWriter.new(registry: registry, paths: paths).sync! AgentRulesWriter.new(registry: registry, paths: paths).sync! stdout.puts "Installed: #{installed.join(', ')}" installed end |