Class: PackageCloud::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/package_cloud/validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Validator

Returns a new instance of Validator.


3
4
5
# File 'lib/package_cloud/validator.rb', line 3

def initialize(client)
  @client = client
end

Instance Method Details

#distribution_id(repo, filenames, package_type) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/package_cloud/validator.rb', line 7

def distribution_id(repo, filenames, package_type)
  if distributions[package_type]
    _,_,dist_sel,ver_sel = repo.split("/")

    # These are all 'single version' distros
    if (dist_sel == "python" || dist_sel == "java" || dist_sel == "node" || dist_sel == "anyfile")
      dist = distributions[package_type].detect { |d| d["index_name"] == dist_sel }
      dist["versions"].first["id"]
    elsif dist_sel && ver_sel
      dist = distributions[package_type].detect { |d| d["index_name"] == dist_sel }

      if dist
        ver = dist["versions"].detect { |v| v["index_name"] == ver_sel || v["version_number"] == ver_sel }

        if ver
          ver["id"]
        else
          puts "#{ver_sel} isn't a valid version of #{dist["display_name"]}\n\n"
          select_dist(repo, filenames, package_type)
        end
      else
        puts "#{dist_sel} isn't a valid operating system.\n\n"
        select_dist(repo, filenames, package_type)
      end
    else
      puts "#{package_type} packages require an operating system and version to be selected.\n\n"
      select_dist(repo, filenames, package_type)
    end
  else
    nil
  end
end