Sha256: 681741b5e06660af1979fb5a121bb5215c7a8ea33dd342679fb1d7609ac2d451

Contents?: true

Size: 1017 Bytes

Versions: 17

Compression:

Stored size: 1017 Bytes

Contents

require 'r10k/module'
require 'r10k/semver'
require 'json'

class R10K::Module::Metadata

  # @!attribute [r] name
  #   @return [String] The module name
  attr_reader :name

  # @!attribute [r] author
  #   @return [String] The module author username
  attr_reader :author

  # @!attribute [r] version
  #   @return [R10K::SemVer] The module version
  attr_reader :version

  # @param metadata_path [Pathname] The file path to the metadata
  def initialize(metadata_path)
    @metadata_path = metadata_path

    @version = R10K::SemVer::MIN
  end

  # Does the metadata file itself exist?
  def exist?
    @metadata_path.file? and @metadata_path.readable?
  end

  # Attempt to read the metadata file
  def read
    if self.exist?
      hash = JSON.parse(@metadata_path.read)
      attributes_from_hash(hash)
    end
  rescue JSON::ParserError
    false
  end

  private

  def attributes_from_hash(json)
    @author, _, @name = json['name'].partition('-')
    @version = R10K::SemVer.new(json['version'])
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
r10k-1.4.2 lib/r10k/module/metadata.rb
r10k-1.4.1 lib/r10k/module/metadata.rb
r10k-1.4.0 lib/r10k/module/metadata.rb
r10k-1.3.5 lib/r10k/module/metadata.rb
r10k-1.3.4 lib/r10k/module/metadata.rb
r10k-1.2.4 lib/r10k/module/metadata.rb
r10k-1.3.3 lib/r10k/module/metadata.rb
r10k-1.3.2 lib/r10k/module/metadata.rb
r10k-1.2.3 lib/r10k/module/metadata.rb
r10k-1.3.1 lib/r10k/module/metadata.rb
r10k-1.2.2 lib/r10k/module/metadata.rb
r10k-1.3.0 lib/r10k/module/metadata.rb
r10k-1.3.0rc1 lib/r10k/module/metadata.rb
r10k-1.2.1 lib/r10k/module/metadata.rb
r10k-1.2.0 lib/r10k/module/metadata.rb
r10k-1.2.0rc2 lib/r10k/module/metadata.rb
r10k-1.2.0rc1 lib/r10k/module/metadata.rb