Sha256: b4473e8095b8a2ff62a6665b4038573f3637c6a4e3dc128185f7a6575417a1fd

Contents?: true

Size: 833 Bytes

Versions: 1

Compression:

Stored size: 833 Bytes

Contents

require 'ns-options'
require 'pathname'
require 'set'

ENV['SANFORD_SERVICES_CONFIG'] ||= 'config/services'

module Sanford

  module Config
    include NsOptions::Proxy

    option :hosts,            Set,      :default => []
    option :services_config,  Pathname, :default => ENV['SANFORD_SERVICES_CONFIG']

    # We want class names to take precedence over a configured name, so that if
    # a user specifies a specific class, they always get it
    def self.find_host(name)
      self.find_host_by_class_name(name) || self.find_host_by_name(name)
    end

    protected

    def self.find_host_by_class_name(class_name)
      self.hosts.detect{|host_class| host_class.to_s == class_name.to_s }
    end

    def self.find_host_by_name(name)
      self.hosts.detect{|host_class| host_class.name == name.to_s }
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sanford-0.1.0 lib/sanford/config.rb