Class: Tanuki::Universe::Commands::Generate
- Inherits:
-
Object
- Object
- Tanuki::Universe::Commands::Generate
- Defined in:
- lib/tanuki/universe/commands/generate.rb
Instance Method Summary collapse
-
#initialize(config_file) ⇒ Generate
constructor
A new instance of Generate.
- #parse_metadata(metadata) ⇒ Object
- #type_gitlab(endpoint) ⇒ Object
Constructor Details
#initialize(config_file) ⇒ Generate
Returns a new instance of Generate.
12 13 14 15 16 17 18 19 20 |
# File 'lib/tanuki/universe/commands/generate.rb', line 12 def initialize(config_file) config = Tanuki::Universe::Config.new(config_file) config.endpoints.each do |endpoint| case endpoint['type'] when 'gitlab' then type_gitlab(endpoint) end end end |
Instance Method Details
#parse_metadata(metadata) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/tanuki/universe/commands/generate.rb', line 64 def () @dependencies = {} .each_line do |line| @cookbook_name = line.gsub(/^name|'/, '').strip if line.match(/^name/) @version = line.gsub(/^version|'/, '').strip if line.match(/^version/) if line.match(/^depends/) depends_cookbook_name = line.split(',')[0].gsub(/^depends|'/, '').strip depends_version = line.split(',')[1].to_s.gsub(/'/, '').strip @dependencies = @dependencies.update({depends_cookbook_name => depends_version}) end end end |
#type_gitlab(endpoint) ⇒ Object
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 |
# File 'lib/tanuki/universe/commands/generate.rb', line 22 def type_gitlab(endpoint) universe = {} gitlab = Tanuki::Universe::GitlabClient.new(endpoint['options']) groups = gitlab.get_groups groups.each do |g| group = gitlab.get_projects(g.id) projects = group.projects projects.each do |project| versions = {} = gitlab.(project['id']) next if .count == 0 .each do |tag| begin = gitlab.(project['id'], tag.name) rescue Exception => e next if e. == "undefined method `message' for {\"message\"=>\"404 File Not Found\"}:Hash" end () dependencies_hash = Hash.new { |h,k| h[k] = {} } if @dependencies.count == 0 dependencies_hash["dependencies"] = {} end @dependencies.each do |k, v| v = '>= 0.0.0' if v.empty? dependencies_hash["dependencies"] = dependencies_hash["dependencies"].update({k => v}) end @location_path = project['web_url'] + '/repository/archive.tar.gz?ref=v' + @version versions = versions.update({ @version => { "location_path" => @location_path, "location_type" => endpoint['type'] }.update(dependencies_hash)}) end universe = universe.update({@cookbook_name => versions }) end end json_str = JSON.pretty_generate(universe) puts json_str end |