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 =
["claude", "codex"].freeze
- SCOPES =
["local", "global"].freeze
Instance Method Summary collapse
-
#initialize(root: Dir.pwd, home: Dir.home, env: ENV) ⇒ Installer
constructor
A new instance of Installer.
- #install(agents:, scope:) ⇒ Object
- #path_for(agent, scope) ⇒ Object
- #status(agents:, scope:) ⇒ Object
- #uninstall(agents:, scope:) ⇒ Object
Constructor Details
Instance Method Details
#install(agents:, scope:) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/all_in_ruby/installer.rb', line 27 def install(agents:, scope:) each_target(agents, scope) do |path| content = File.exist?(path) ? File.read(path) : nil if content && Instruction.installed?(content) :already_installed elsif content separator = content.empty? || content.end_with?("\n\n") ? "" : (content.end_with?("\n") ? "\n" : "\n\n") File.write(path, content + separator + Instruction.block) :updated else FileUtils.mkdir_p(File.dirname(path)) File.write(path, Instruction.block) :created end end end |
#path_for(agent, scope) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/all_in_ruby/installer.rb', line 16 def path_for(agent, scope) case [agent, scope] when ["claude", "local"] then File.join(@root, "CLAUDE.md") when ["claude", "global"] then File.join(@home, ".claude", "CLAUDE.md") when ["codex", "local"] then File.join(@root, "AGENTS.md") when ["codex", "global"] then File.join(codex_home, "AGENTS.md") else raise ArgumentError, "unknown agent or scope: #{agent}, #{scope}" end end |
#status(agents:, scope:) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/all_in_ruby/installer.rb', line 58 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:) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/all_in_ruby/installer.rb', line 45 def uninstall(agents:, scope:) each_target(agents, scope) do |path| content = File.exist?(path) ? File.read(path) : nil if content && Instruction.installed?(content) File.write(path, Instruction.remove(content)) :removed else :not_installed end end end |