Sha256: 7e0ebe47eb9ba26e1b556c02399afe7827b30ea88a6d8891e69336528fe761b1

Contents?: true

Size: 1.05 KB

Versions: 42

Compression:

Stored size: 1.05 KB

Contents

require "json"

class RepoMetadata
  attr_accessor :data

  def initialize data
    @data = data
    normalize_data!
  end

  def allowed_fields
    [
      "name", "version", "language", "distribution-name",
      "product-page", "github-repository", "issue-tracker"
    ]
  end

  def build output_directory
    fields = @data.to_a.map { |kv| "--#{kv[0]} #{kv[1]}" }
    Dir.chdir output_directory do
      cmd "python3 -m docuploader create-metadata #{fields.join ' '}"
    end
  end

  def normalize_data!
    @data.delete_if { |k, _| !allowed_fields.include?(k) }
  end

  def [] key
    data[key]
  end

  def []= key, value
    @data[key] = value
  end

  def cmd line
    puts line
    output = `#{line}`
    puts output
    output
  end

  def self.from_source source
    if source.is_a? RepoMetadata
      data = source.data
    elsif source.is_a? Hash
      data = source
    elsif File.file? source
      data = JSON.parse File.read(source)
    else
      raise "Source must be a path, hash, or RepoMetadata instance"
    end
    RepoMetadata.new data
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
google-api-client-0.52.0 rakelib/devsite/repo_metadata.rb
google-api-client-0.51.0 rakelib/devsite/repo_metadata.rb
google-api-client-0.50.0 rakelib/devsite/repo_metadata.rb
google-api-client-0.49.0 rakelib/devsite/repo_metadata.rb
google-api-client-0.48.0 rakelib/devsite/repo_metadata.rb
google-api-client-0.47.0 rakelib/devsite/repo_metadata.rb
google-api-client-0.46.2 rakelib/devsite/repo_metadata.rb
google-api-client-0.46.1 rakelib/devsite/repo_metadata.rb
google-api-client-0.46.0 rakelib/devsite/repo_metadata.rb
google-api-client-0.45.1 rakelib/devsite/repo_metadata.rb
google-api-client-0.45.0 rakelib/devsite/repo_metadata.rb
google-api-client-0.44.2 rakelib/devsite/repo_metadata.rb
google-api-client-0.44.1 rakelib/devsite/repo_metadata.rb
google-api-client-0.44.0 rakelib/devsite/repo_metadata.rb
google-api-client-0.43.0 rakelib/devsite/repo_metadata.rb
google-api-client-0.42.2 rakelib/devsite/repo_metadata.rb
google-api-client-0.42.1 rakelib/devsite/repo_metadata.rb
google-api-client-0.42.0 rakelib/devsite/repo_metadata.rb
google-api-client-0.41.2 rakelib/devsite/repo_metadata.rb
google-api-client-0.41.1 rakelib/devsite/repo_metadata.rb