Class: Natives::Catalog

Inherits:
Object
  • Object
show all
Defined in:
lib/natives/catalog.rb,
lib/natives/catalog/loader.rb,
lib/natives/catalog/merger.rb,
lib/natives/catalog/selector.rb,
lib/natives/catalog/validator.rb,
lib/natives/catalog/normalizer.rb

Defined Under Namespace

Classes: Loader, Merger, Normalizer, Selector, Validator

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(catalog_name, platform, platform_version, package_provider, opts = {}) ⇒ Catalog

Returns a new instance of Catalog.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/natives/catalog.rb', line 14

def initialize(catalog_name,
               platform, platform_version,
               package_provider,
               opts={})

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

  @loader = opts.fetch(:loader, Loader.new)
  @working_dir = opts.fetch(:working_dir, Dir.pwd)

  reload
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/natives/catalog.rb', line 12

def name
  @name
end

#package_providerObject (readonly)

Returns the value of attribute package_provider.



12
13
14
# File 'lib/natives/catalog.rb', line 12

def package_provider
  @package_provider
end

#platformObject (readonly)

Returns the value of attribute platform.



12
13
14
# File 'lib/natives/catalog.rb', line 12

def platform
  @platform
end

#platform_versionObject (readonly)

Returns the value of attribute platform_version.



12
13
14
# File 'lib/natives/catalog.rb', line 12

def platform_version
  @platform_version
end

Instance Method Details

#native_packages_for(*entry_names) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/natives/catalog.rb', line 38

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

#reloadObject



30
31
32
# File 'lib/natives/catalog.rb', line 30

def reload
  @catalogs = @loader.load_from_paths(catalog_paths)
end

#to_hashObject



34
35
36
# File 'lib/natives/catalog.rb', line 34

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