Class: Serialbench::RubyBuildManager
- Inherits:
-
Object
- Object
- Serialbench::RubyBuildManager
- Defined in:
- lib/serialbench/ruby_build_manager.rb
Overview
Manages Ruby-Build definitions from the official ruby-build repository
Constant Summary collapse
- GITHUB_API_URL =
'https://api.github.com/repos/rbenv/ruby-build/contents/share/ruby-build'- CACHE_DIR =
File.('~/.serialbench')
- CACHE_FILE =
File.join(CACHE_DIR, 'ruby-build-definitions.yaml')
Class Method Summary collapse
- .cache_age ⇒ Object
- .cache_exists? ⇒ Boolean
- .ensure_cache_exists! ⇒ Object
- .list_definitions ⇒ Object
- .show_definition(tag) ⇒ Object
- .suggest_current_ruby_tag ⇒ Object
- .update_definitions ⇒ Object
- .validate_tag(tag) ⇒ Object
Class Method Details
.cache_age ⇒ Object
81 82 83 84 85 |
# File 'lib/serialbench/ruby_build_manager.rb', line 81 def cache_age return nil unless cache_exists? Time.now - File.mtime(CACHE_FILE) end |
.cache_exists? ⇒ Boolean
77 78 79 |
# File 'lib/serialbench/ruby_build_manager.rb', line 77 def cache_exists? File.exist?(CACHE_FILE) end |
.ensure_cache_exists! ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/serialbench/ruby_build_manager.rb', line 87 def ensure_cache_exists! return if cache_exists? raise <<~ERROR Ruby-Build definitions cache not found. Update the cache first: serialbench ruby-build update ERROR end |
.list_definitions ⇒ Object
29 30 31 |
# File 'lib/serialbench/ruby_build_manager.rb', line 29 def list_definitions load_definitions_from_cache end |
.show_definition(tag) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/serialbench/ruby_build_manager.rb', line 33 def show_definition(tag) definitions = load_definitions_from_cache raise "Ruby-Build definition '#{tag}' not found. Available definitions: #{definitions.length}" unless definitions.include?(tag) { tag: tag, available: true, source: 'ruby-build', cache_file: CACHE_FILE } end |
.suggest_current_ruby_tag ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/serialbench/ruby_build_manager.rb', line 56 def suggest_current_ruby_tag ruby_version = RUBY_VERSION # Try exact match first return ruby_version if validate_tag(ruby_version) # Try common variations variations = [ ruby_version, "#{ruby_version}.0", "#{ruby_version.split('.')[0..1].join('.')}.0" ] variations.each do |variation| return variation if validate_tag(variation) end # Return the Ruby version even if not found, user can adjust ruby_version end |
.update_definitions ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/serialbench/ruby_build_manager.rb', line 15 def update_definitions puts '🔄 Fetching Ruby-Build definitions from GitHub...' definitions = fetch_definitions_from_github save_definitions_to_cache(definitions) puts "✅ Updated #{definitions.length} Ruby-Build definitions" puts "📁 Cache location: #{CACHE_FILE}" definitions rescue StandardError => e raise "Failed to update Ruby-Build definitions: #{e.}" end |
.validate_tag(tag) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/serialbench/ruby_build_manager.rb', line 46 def validate_tag(tag) puts "🔍 Validating Ruby-Build tag: #{tag} against #{CACHE_FILE}" return false if tag.nil? || tag.strip.empty? definitions = load_definitions_from_cache definitions.include?(tag) rescue StandardError false end |