Class: AllInRuby::Installer
- Inherits:
-
Object
- Object
- AllInRuby::Installer
- Defined in:
- lib/all_in_ruby/installer.rb
Defined Under Namespace
Classes: Result
Constant Summary collapse
- AGENTS =
%w[claude codex opencode cursor].freeze
- SCOPES =
%w[local global].freeze
Instance Method Summary collapse
-
#initialize(root: Dir.pwd, home: Dir.home, env: ENV, clock: -> { Time.now }) ⇒ Installer
constructor
A new instance of Installer.
- #install(agents:, scope:, dry_run: false, backup: true) ⇒ Object
- #path_for(agent, scope) ⇒ Object
- #status(agents:, scope:) ⇒ Object
- #uninstall(agents:, scope:, dry_run: false, backup: true) ⇒ Object
Constructor Details
#initialize(root: Dir.pwd, home: Dir.home, env: ENV, clock: -> { Time.now }) ⇒ Installer
Returns a new instance of Installer.
12 13 14 15 16 17 |
# File 'lib/all_in_ruby/installer.rb', line 12 def initialize(root: Dir.pwd, home: Dir.home, env: ENV, clock: -> { Time.now }) @root = root @home = home @env = env @clock = clock end |
Instance Method Details
#install(agents:, scope:, dry_run: false, backup: true) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/all_in_ruby/installer.rb', line 35 def install(agents:, scope:, dry_run: false, backup: true) planned = {} each_target(agents, scope) do |path| content = current_content(path, planned) if content && Instruction.installed?(content) :already_installed elsif content new_content = content + separator_for(content) + Instruction.block apply(path, content, new_content, :updated, dry_run, backup, planned) else apply(path, nil, Instruction.block, :created, dry_run, backup, planned) end end end |
#path_for(agent, scope) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/all_in_ruby/installer.rb', line 19 def path_for(agent, scope) case [agent, scope] when %w[claude local] then File.join(@root, "CLAUDE.md") when %w[claude global] then File.join(@home, ".claude", "CLAUDE.md") when %w[codex local] then File.join(@root, "AGENTS.md") when %w[codex global] then File.join(codex_home, "AGENTS.md") when %w[opencode local] then File.join(@root, "AGENTS.md") when %w[opencode global] then File.join(@home, ".config", "opencode", "AGENTS.md") when %w[cursor local] then File.join(@root, "AGENTS.md") # Cursor has no documented global rules file; User Rules live in the app settings when %w[cursor global] then nil else raise ArgumentError, "unknown agent or scope: #{agent}, #{scope}" end end |
#status(agents:, scope:) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/all_in_ruby/installer.rb', line 64 def status(agents:, scope:) each_target(agents, scope) do |path| content = File.exist?(path) ? File.read(path) : nil content && Instruction.installed?(content) ? :installed : :not_installed end end |
#uninstall(agents:, scope:, dry_run: false, backup: true) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/all_in_ruby/installer.rb', line 51 def uninstall(agents:, scope:, dry_run: false, backup: true) planned = {} each_target(agents, scope) do |path| content = current_content(path, planned) if content && Instruction.installed?(content) apply(path, content, Instruction.remove(content), :removed, dry_run, backup, planned) else :not_installed end end end |