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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/bake/agent/context.rb +1 -1
- data/lib/agent/context/helper.rb +23 -19
- data/lib/agent/context/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4dd25415ecb31136843810a6455fa0594d134b4fe8c926a8b43f75b18be232d2
|
4
|
+
data.tar.gz: bf2d14ca245188f5a878ae6761b5092d69c0c1fc80c90d3bccd5dc16a61459ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a8e4b97106b8eda55a54ff66a471c1cb272d987bb9359620a7722cd410471abaf7ac0c5b4ebc045410f5a4fc85ff687133a2eaec11ac53873f3fe2c2d7f8877
|
7
|
+
data.tar.gz: '002169fa66a2310b8e3c05eb7735165255136141cdb5daf6ad118daf69bb5c283e3ef6dc8ad3a8f39f4c37fa60cdc13f88d0d4a4fca713d85e3bb0652607b8a1'
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/bake/agent/context.rb
CHANGED
data/lib/agent/context/helper.rb
CHANGED
@@ -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
|
-
|
57
|
-
return nil unless
|
60
|
+
gem = find_gem_with_context(gem_name)
|
61
|
+
return nil unless gem
|
58
62
|
|
59
|
-
Dir.glob(File.join(
|
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
|
-
|
65
|
-
return nil unless
|
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(
|
70
|
-
File.join(
|
71
|
-
File.join(
|
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
|
-
|
83
|
-
return false unless
|
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(
|
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 |
|
100
|
-
if install_gem_context(
|
101
|
-
installed <<
|
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
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|