class DataPackage::Registry

Allow loading Data Package profiles from the official registry.

Constants

DEFAULT_REGISTRY_PATH
DEFAULT_REGISTRY_URL

Attributes

path[R]
profiles[R]

Public Class Methods

new() click to toggle source
# File lib/datapackage/registry.rb, line 12
def initialize
  @path = DEFAULT_REGISTRY_PATH
  @profiles = get_registry(DEFAULT_REGISTRY_PATH)
rescue Errno::ENOENT
  raise RegistryException.new 'Registry path is not valid'
rescue OpenURI::HTTPError, SocketError => e
  raise RegistryException.new "Registry URL returned #{e.message}"
rescue JSON::ParserError
  raise RegistryException.new 'Registry descriptor is not valid JSON'
rescue KeyError
  raise RegistryException.new 'Property `id` is mandatory for profiles'
end

Private Instance Methods

get_registry(descriptor) click to toggle source
# File lib/datapackage/registry.rb, line 27
def get_registry(descriptor)
  resources = load_json(descriptor)
  resources.reduce({}) do |registry, resource|
    registry[resource['id']] = resource
    registry
  end
end