agent-context 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb68b016f45077bf445632b810e6f73ca397a262ae1baa5b1c151489ddeaa7a1
4
- data.tar.gz: f7e9f38749e95d7561736ec30ba4db9bb3841da2c142f59f70508d8119ee890c
3
+ metadata.gz: 4dd25415ecb31136843810a6455fa0594d134b4fe8c926a8b43f75b18be232d2
4
+ data.tar.gz: bf2d14ca245188f5a878ae6761b5092d69c0c1fc80c90d3bccd5dc16a61459ec
5
5
  SHA512:
6
- metadata.gz: 0daacfbf5d32738df4c426795f7a5f6a1409a30d5da02ce518c9a2bff0b95831765b9477261c76ee16814980fc2614ee6be6be607aff7374d8366ba0f9f7c35f
7
- data.tar.gz: d2dc624eba0c6e3449c62067a1c5e28f6eccd4ed48c57a591fb3d7d5a33dcffe0699d2965b797fb781f149671f65b7ae0865897113e3abd08a8f6f20dfd6be30
6
+ metadata.gz: 5a8e4b97106b8eda55a54ff66a471c1cb272d987bb9359620a7722cd410471abaf7ac0c5b4ebc045410f5a4fc85ff687133a2eaec11ac53873f3fe2c2d7f8877
7
+ data.tar.gz: '002169fa66a2310b8e3c05eb7735165255136141cdb5daf6ad118daf69bb5c283e3ef6dc8ad3a8f39f4c37fa60cdc13f88d0d4a4fca713d85e3bb0652607b8a1'
checksums.yaml.gz.sig CHANGED
Binary file
@@ -10,7 +10,7 @@ include Agent::Context
10
10
  def initialize(context)
11
11
  super(context)
12
12
 
13
- @helper = Helper.new
13
+ @helper = Helper.new(root: context.root)
14
14
  end
15
15
 
16
16
  attr :helper
@@ -10,16 +10,20 @@ require "pathname"
10
10
  module Agent
11
11
  module Context
12
12
  class Helper
13
- def initialize(specifications: ::Gem::Specification)
13
+ def initialize(root: Dir.pwd, specifications: ::Gem::Specification)
14
+ @root = root
14
15
  @context_path = ".context"
15
16
  @specifications = specifications
16
17
  end
17
18
 
18
19
  # Find all gems that have a context directory
19
- def find_gems_with_context
20
+ def find_gems_with_context(skip_local: true)
20
21
  gems_with_context = []
21
22
 
22
23
  @specifications.each do |spec|
24
+ # Skip gems loaded from current working directory if requested:
25
+ next if skip_local && spec.full_gem_path == @root
26
+
23
27
  context_path = File.join(spec.full_gem_path, "context")
24
28
  if Dir.exist?(context_path)
25
29
  gems_with_context << {
@@ -53,22 +57,22 @@ module Agent
53
57
 
54
58
  # List context files for a gem
55
59
  def list_context_files(gem_name)
56
- gem_info = find_gem_with_context(gem_name)
57
- return nil unless gem_info
60
+ gem = find_gem_with_context(gem_name)
61
+ return nil unless gem
58
62
 
59
- Dir.glob(File.join(gem_info[:path], "**/*")).select { |f| File.file?(f) }
63
+ Dir.glob(File.join(gem[:path], "**/*")).select { |f| File.file?(f) }
60
64
  end
61
65
 
62
66
  # Show content of a specific context file
63
67
  def show_context_file(gem_name, file_name)
64
- gem_info = find_gem_with_context(gem_name)
65
- return nil unless gem_info
68
+ gem = find_gem_with_context(gem_name)
69
+ return nil unless gem
66
70
 
67
71
  # Try to find the file with or without extension
68
72
  possible_paths = [
69
- File.join(gem_info[:path], file_name),
70
- File.join(gem_info[:path], "#{file_name}.mdc"),
71
- File.join(gem_info[:path], "#{file_name}.md")
73
+ File.join(gem[:path], file_name),
74
+ File.join(gem[:path], "#{file_name}.mdc"),
75
+ File.join(gem[:path], "#{file_name}.md")
72
76
  ]
73
77
 
74
78
  file_path = possible_paths.find { |path| File.exist?(path) }
@@ -79,26 +83,26 @@ module Agent
79
83
 
80
84
  # Install context from a specific gem
81
85
  def install_gem_context(gem_name)
82
- gem_info = find_gem_with_context(gem_name)
83
- return false unless gem_info
86
+ gem = find_gem_with_context(gem_name)
87
+ return false unless gem
84
88
 
85
89
  target_path = File.join(@context_path, gem_name)
86
90
  FileUtils.mkdir_p(target_path)
87
91
 
88
92
  # Copy all files from the gem's context directory
89
- FileUtils.cp_r(File.join(gem_info[:path], "."), target_path)
93
+ FileUtils.cp_r(File.join(gem[:path], "."), target_path)
90
94
 
91
95
  true
92
96
  end
93
97
 
94
98
  # Install context from all gems
95
- def install_all_context
96
- gems = find_gems_with_context
99
+ def install_all_context(skip_local: true)
100
+ gems = find_gems_with_context(skip_local: skip_local)
97
101
  installed = []
98
102
 
99
- gems.each do |gem_info|
100
- if install_gem_context(gem_info[:name])
101
- installed << gem_info[:name]
103
+ gems.each do |gem|
104
+ if install_gem_context(gem[:name])
105
+ installed << gem[:name]
102
106
  end
103
107
  end
104
108
 
@@ -106,4 +110,4 @@ module Agent
106
110
  end
107
111
  end
108
112
  end
109
- end
113
+ end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Agent
7
7
  module Context
8
- VERSION = "0.0.0"
8
+ VERSION = "0.0.1"
9
9
  end
10
10
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agent-context
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Inc.
metadata.gz.sig CHANGED
Binary file