Sha256: 0c06c6c44d16b837960965f3b04ff59cb712857754b53c9c7bed5d654ff5a323

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

require 'natives/catalog/loader'
require 'natives/catalog/selector'

module Natives
  class Catalog

    CATALOG_PATH_IN_GEM = File.absolute_path(File.join(
                            File.dirname(__FILE__), '..', '..', 'catalogs'))
    CATALOG_PATH_IN_WORKING_DIR = File.absolute_path(File.join('.', 'natives-catalogs'))

    CATALOG_PATHS = [
      CATALOG_PATH_IN_GEM,
      CATALOG_PATH_IN_WORKING_DIR
    ].freeze

    attr_reader :platform, :platform_version, :package_provider, :name

    def initialize(catalog_name, platform, platform_version, package_provider)
      reload

      @name = catalog_name.to_s
      @platform = platform.to_s
      @platform_version = platform_version.to_s
      @package_provider = package_provider.to_s
    end

    def reload
      @catalogs = Loader.new.load_from_paths(CATALOG_PATHS)
    end

    def to_hash
      @catalogs.fetch(self.name, {})
    end

    def native_packages_for(*entry_names)
      packages = Array(entry_names).flatten.map do |entry_name|
        Selector.new(self.to_hash.fetch(entry_name, {})).
          value_for(@platform, @platform_version, @package_provider)
      end
      packages.flatten.compact
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
natives-catalog-0.3.0 lib/natives/catalog.rb