class Pione::Package::PackageReader

PackageReader is a reader for packages.

Public Class Methods

new(location) click to toggle source
# File lib/pione/package/package-reader.rb, line 21
def initialize(location)
  @location = location
  @local = nil
  @package_info = read_package_info
end
read(location) click to toggle source

Read a pacakge from the location.

# File lib/pione/package/package-reader.rb, line 7
def read(location)
  case PackageTypeClassifier.classify(location)
  when :directory
    DirectoryPackageReader.new(location).read
  when :git
    GitPackageReader.new(location).read
  when :archive
    ArchivePackageReader.new(location).read
  when :document
    SingleDocumentPackageReader.new(location).read
  end
end

Public Instance Methods

read() click to toggle source
# File lib/pione/package/package-reader.rb, line 27
def read
  raise NotImplementedError
end

Private Instance Methods

find_scenario_paths(scenarios) click to toggle source

Find scenarios from the package location.

@return [Array<PackageScenario>]

scenarios
# File lib/pione/package/package-reader.rb, line 53
def find_scenario_paths(scenarios)
  return [] if scenarios.nil?
  scenarios.select do |path|
    (@location + path + "scenario.yml").exist?
  end.uniq.compact
end
read_document() click to toggle source

@return [Package]

the package
# File lib/pione/package/package-reader.rb, line 43
def read_document
  opt = {package_name: "Anonymous", filename: @location.basename}
  context = Document.load(@location, opt)
  Package.new(info: {"PackageName" => "Anonymous"}, context: context)
end
read_package_info() click to toggle source

Read informations from the package location.

# File lib/pione/package/package-reader.rb, line 34
def read_package_info
  PackageInfo.load((@location + "pione-package.json").read)
rescue Location::NotFound
  raise InvalidPackage.new(self, "pione-package.json not found in %s" % @location.uri)
end