Module: Init

Defined in:
lib/init.rb

Class Method Summary collapse

Class Method Details

.runObject

Runs the initialization process to resolve Java dependencies.

Prompts the user for input on whether to resolve dependencies and set recommended versions. Downloads the necessary libraries based on the settings in the YAML file.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/init.rb', line 16

def self.run
  puts "Would you like to resolve Java dependencies? (No/yes)\n  EOT\n\n  case gets.chomp.downcase\n  when \"yes\", \"y\"\n    flag = true\n  when \"no\", \"n\"\n    exit 1\n  else\n    puts \"Invalid input. Exiting...\"\n    exit 1\n  end\n\n  puts <<-EOT\nSet recommended Java library version? (No/yes)\n  EOT\n\n  case gets.chomp.downcase\n  when \"yes\", \"y\"\n    flag = true\n  end\n\n  downloads = load_settings(ENV['HOME'] + \"/.glycobook/jar.yml\", flag)\n\n  # Execute the downloads\n  downloads[\"libraries\"].each do |download|\n    url = URI(download[\"url\"])\n    http = Net::HTTP.new(url.host, url.port)\n    http.use_ssl = (url.scheme == 'https')\n\n    request = Net::HTTP::Get.new(url.request_uri)\n    response = http.request(request)\n\n    if response.code.to_i == 302\n      new_location = response['Location']\n      url = URI.parse(new_location)\n      http = Net::HTTP.new(url.host, url.port)\n      http.use_ssl = (url.scheme == 'https')\n      request = Net::HTTP::Get.new(url.request_uri)\n      response = http.request(request)\n    end\n\n    if response.code.to_i == 200\n      begin\n        File.open(File.dirname(__FILE__) + \"/\" + download[\"file\"], 'wb') do |file|\n          file.write(response.body)\n          puts \"Installed \" + download[\"file\"]\n        end\n      rescue StandardError => e\n        puts \"Failed to save file: \#{download[\"file\"]}. Error: \#{e.message}\"\n      end\n    else\n      puts \"Failed to download file: \#{download[\"file\"]}\"\n    end\n  end\nend\n"

.show_dependenciesObject



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/init.rb', line 111

def self.show_dependencies
    yaml_data = File.read(Dir.home+'/.glycobook/jar.yml')
    parsed_data = YAML.load(yaml_data)
    rows = []
    #rows.push(["name","version","Link"])
    rows.push(["name","version"])
    parsed_data["libraries"].each{|item|
      #rows.push([item["name"].to_s , item["version"].to_s , item["info"].to_s ])
      rows.push([item["name"].to_s , item["version"].to_s] )
    }
    puts Terminal::Table.new rows: rows
end

.show_WFW_versionObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/init.rb', line 93

def self.show_WFW_version()
  target_file_path = File.dirname(__FILE__) + '/jar/wurcsframework.jar'  
  folder_path = File.dirname(__FILE__) + '/jar' 

  matching_files = find_matching_files(target_file_path, folder_path)

  unless matching_files.empty?
    matching_files.each do |file|
      version = extract_version_from_filename(file)
      if version
        puts "version number: #{version}"
      else
        puts ""
      end
    end
  end
end

.switch_WFW_version(version) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/init.rb', line 75

def self.switch_WFW_version(version)
  base = File.dirname(__FILE__) + "/jar/"
  
  source_file = File.join(base, "wurcsframework-#{version}.jar")
  destination_file = File.join(base, "wurcsframework.jar")

  if File.exist?(source_file)
    begin
      FileUtils.cp(source_file, destination_file)
      puts "Switched to version #{version} successfully!"
    rescue StandardError => e
      puts "Failed to switch versions: #{e.message}"
    end
  else
    puts "Source file #{source_file} does not exist."
  end
end