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 <<-EOT
Would you like to resolve Java dependencies? (No/yes)
  EOT

  case gets.chomp.downcase
  when "yes", "y"
    flag = true
  when "no", "n"
    exit 1
  else
    puts "Invalid input. Exiting..."
    exit 1
  end

  puts <<-EOT
Set recommended Java library version? (No/yes)
  EOT

  case gets.chomp.downcase
  when "yes", "y"
    flag = true
  end

  downloads = load_settings(ENV['HOME'] + "/.glycobook/jar.yml", flag)

  # Execute the downloads
  downloads["libraries"].each do |download|
    url = URI(download["url"])
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = (url.scheme == 'https')

    request = Net::HTTP::Get.new(url.request_uri)
    response = http.request(request)

    if response.code.to_i == 302
      new_location = response['Location']
      url = URI.parse(new_location)
      http = Net::HTTP.new(url.host, url.port)
      http.use_ssl = (url.scheme == 'https')
      request = Net::HTTP::Get.new(url.request_uri)
      response = http.request(request)
    end

    if response.code.to_i == 200
      begin
        File.open(File.dirname(__FILE__) + "/" + download["file"], 'wb') do |file|
          file.write(response.body)
          puts "Installed " + download["file"]
        end
      rescue StandardError => e
        puts "Failed to save file: #{download["file"]}. Error: #{e.message}"
      end
    else
      puts "Failed to download file: #{download["file"]}"
    end
  end
end

.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