Class: AgentC::Context
- Inherits:
-
Object
- Object
- AgentC::Context
- Defined in:
- lib/agent_c/context.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(store:, session:, repo: nil, workspace: nil) ⇒ Context
constructor
A new instance of Context.
- #session ⇒ Object
- #store ⇒ Object
- #workspace ⇒ Object
- #workspaces ⇒ Object
Constructor Details
#initialize(store:, session:, repo: nil, workspace: nil) ⇒ Context
Returns a new instance of Context.
6 7 8 9 10 11 12 13 |
# File 'lib/agent_c/context.rb', line 6 def initialize(store:, session:, repo: nil, workspace: nil) raise ArgumentError.new("must pass workspace or repo") unless workspace || repo @store_config = store @session_config = session @workspace_config = workspace @repo_config = repo end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/agent_c/context.rb', line 5 def config @config end |
Instance Method Details
#session ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/agent_c/context.rb', line 46 def session @session ||= ( if @session_config.is_a?(Hash) Session.new(**@session_config) else @session_config end ) end |
#store ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/agent_c/context.rb', line 15 def store @store ||= ( if @store_config.is_a?(Hash) @store_config.fetch(:class).new(**@store_config.fetch(:config)) else @store_config end ) end |
#workspace ⇒ Object
25 26 27 28 29 |
# File 'lib/agent_c/context.rb', line 25 def workspace raise "Multiple workspaces configured" unless workspaces.count == 1 workspaces.first end |
#workspaces ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/agent_c/context.rb', line 31 def workspaces @workspaces ||= ( if @workspace_config.is_a?(Hash) [store.workspace.ensure_created!(**@workspace_config)] elsif @repo_config # Note: This method provision the worktrees if they don't exist Configs::Repo.new(logger: session.logger, **@repo_config).workspaces(store) elsif @workspace_config.is_a?(Array) @workspace_config else [@workspace_config] end ) end |