class RGovData::Catalog

Attributes

realm[RW]

Public Class Methods

get(key) click to toggle source

Returns the object specified by the key Key specification: //<realm>/<service-key>/<data-set-name> All key components are optional - you will get the best matching object for the key spec //sg - will return RGovData::Catalog for realm=:sg //sg/nlb - will return RGovData::ServiceListing for the nlb service in SG /nlb - will return RGovData::ServiceListing for the nlb service in SG (assuming SG is the default realm) //sg/nlb/Library - will return RGovData::OdataService for the nlb Library service in SG

# File lib/rgovdata/catalog/catalog.rb, line 14
def get(key)
  key ||= '//'
  key.gsub!(':','/') # handle alternate encoding
  keypart = Regexp.new(/(?:\/\/([^\/]+))?(?:\/([^\/]+))?(?:\/([^\/]+))?/).match(key)
  found = catalog = self.new(keypart[1])
  if keypart[2]
    found = service = catalog.get_service(keypart[2])
    if keypart[3]
      found = service.get_dataset(keypart[3])
    end
  end
  found
end
new(default_realm=nil) click to toggle source
# File lib/rgovdata/catalog/catalog.rb, line 29
def initialize(default_realm=nil)
  @realm = default_realm && default_realm.to_sym
end

Public Instance Methods

get_service(key) click to toggle source

Returns the service(s) matching key

# File lib/rgovdata/catalog/catalog.rb, line 45
def get_service(key)
  return nil unless services && !services.empty?
  matches = services.select {|s| s.key =~ /#{key}/}
  matches.count == 1 ? matches.first : matches
end
realm=(value) click to toggle source

override realm setter to clear state when realm changed

# File lib/rgovdata/catalog/catalog.rb, line 52
def realm=(value)
  clear
  @realm = value
end
realms() click to toggle source

Returns available realms

# File lib/rgovdata/catalog/catalog.rb, line 34
def realms
  # TODO: currently hard-coded
  [:sg,:us].map{|realm| self.class.new(realm) }
end
records() click to toggle source

Generic interface to return the currently applicable record set

> overrides RGovData::Dn.records

# File lib/rgovdata/catalog/catalog.rb, line 65
def records
  if realm.present?
    services
  else
    realms
  end
end
services() click to toggle source

Returns an array of ServiceListings for the current realm

# File lib/rgovdata/catalog/catalog.rb, line 40
def services
  @services ||= registry_strategy.load_services
end

Protected Instance Methods

clear() click to toggle source

Clears current state TODO: move to Dn

# File lib/rgovdata/catalog/catalog.rb, line 75
def clear
  @realm = @services = nil
end
registry_strategy() click to toggle source

Returns the registry strategy class for the current realm

# File lib/rgovdata/catalog/catalog.rb, line 58
def registry_strategy
  RGovData::RegistryStrategy.instance_for_realm(realm)
end