Class: Legion::CLI::LexCliManifest
- Inherits:
-
Object
- Object
- Legion::CLI::LexCliManifest
- Defined in:
- lib/legion/cli/lex_cli_manifest.rb
Instance Attribute Summary collapse
-
#cache_dir ⇒ Object
readonly
Returns the value of attribute cache_dir.
Instance Method Summary collapse
- #all_manifests ⇒ Object
-
#initialize(cache_dir: File.expand_path('~/.legionio/cache/cli')) ⇒ LexCliManifest
constructor
A new instance of LexCliManifest.
- #read_manifest(gem_name) ⇒ Object
- #resolve_alias(name) ⇒ Object
- #stale?(gem_name, current_version) ⇒ Boolean
- #write_manifest(gem_name:, gem_version:, alias_name:, commands:) ⇒ Object
Constructor Details
#initialize(cache_dir: File.expand_path('~/.legionio/cache/cli')) ⇒ LexCliManifest
Returns a new instance of LexCliManifest.
11 12 13 14 |
# File 'lib/legion/cli/lex_cli_manifest.rb', line 11 def initialize(cache_dir: File.('~/.legionio/cache/cli')) @cache_dir = cache_dir FileUtils.mkdir_p(@cache_dir) end |
Instance Attribute Details
#cache_dir ⇒ Object (readonly)
Returns the value of attribute cache_dir.
9 10 11 |
# File 'lib/legion/cli/lex_cli_manifest.rb', line 9 def cache_dir @cache_dir end |
Instance Method Details
#all_manifests ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/legion/cli/lex_cli_manifest.rb', line 36 def all_manifests Dir.glob(File.join(@cache_dir, 'lex-*.json')).map do |path| ::JSON.parse(File.read(path)) rescue StandardError => e Legion::Logging.warn("LexCliManifest#all_manifests failed to parse #{path}: #{e.}") if defined?(Legion::Logging) nil end.compact end |
#read_manifest(gem_name) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/legion/cli/lex_cli_manifest.rb', line 22 def read_manifest(gem_name) path = manifest_path(gem_name) return nil unless File.exist?(path) ::JSON.parse(File.read(path)) end |
#resolve_alias(name) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/legion/cli/lex_cli_manifest.rb', line 29 def resolve_alias(name) all_manifests.each do |m| return m['gem'] if m['alias'] == name end nil end |
#stale?(gem_name, current_version) ⇒ Boolean
45 46 47 48 49 50 |
# File 'lib/legion/cli/lex_cli_manifest.rb', line 45 def stale?(gem_name, current_version) m = read_manifest(gem_name) return true unless m m['version'] != current_version end |
#write_manifest(gem_name:, gem_version:, alias_name:, commands:) ⇒ Object
16 17 18 19 20 |
# File 'lib/legion/cli/lex_cli_manifest.rb', line 16 def write_manifest(gem_name:, gem_version:, alias_name:, commands:) data = { 'gem' => gem_name, 'version' => gem_version, 'alias' => alias_name, 'commands' => serialize_commands(commands) } File.write(manifest_path(gem_name), ::JSON.pretty_generate(data)) end |