Class: Acfs::Configuration
- Inherits:
-
Object
- Object
- Acfs::Configuration
- Defined in:
- lib/acfs/configuration.rb
Overview
Acfs configuration is used to locate services and get their base URLs.
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#locations ⇒ Object
readonly
Returns the value of attribute locations.
Class Method Summary collapse
-
.current ⇒ Configuration
private
Return current configuration object.
-
.set(configuration) ⇒ undefined
private
Swap configuration object with given new one.
Instance Method Summary collapse
-
#configure {|configuration| ... } ⇒ undefined
Configure using given block.
-
#initialize ⇒ Configuration
constructor
private
A new instance of Configuration.
-
#load(filename) ⇒ undefined
Load configuration from given YAML file.
-
#load_services(services) ⇒ Object
private
Load services from configuration YAML.
- #locate(service, uri = nil) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Configuration.
14 15 16 |
# File 'lib/acfs/configuration.rb', line 14 def initialize @locations = {} end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
11 12 13 |
# File 'lib/acfs/configuration.rb', line 11 def adapter @adapter end |
#locations ⇒ Object (readonly)
Returns the value of attribute locations.
10 11 12 |
# File 'lib/acfs/configuration.rb', line 10 def locations @locations end |
Class Method Details
.current ⇒ Configuration
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return current configuration object.
103 104 105 |
# File 'lib/acfs/configuration.rb', line 103 def current @current ||= new end |
.set(configuration) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Swap configuration object with given new one. Must be a Acfs::Configuration object.
115 116 117 |
# File 'lib/acfs/configuration.rb', line 115 def set(configuration) @current = configuration if configuration.is_a? Configuration end |
Instance Method Details
#configure {|configuration| ... } ⇒ undefined
Configure using given block. If block accepts zero arguments bock will be evaluated in context of the configuration instance otherwise the configuration instance will be given as first arguments.
29 30 31 32 33 34 35 |
# File 'lib/acfs/configuration.rb', line 29 def configure(&block) if block.arity.positive? yield self else instance_eval(&block) end end |
#load(filename) ⇒ undefined
Load configuration from given YAML file.
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/acfs/configuration.rb', line 72 def load(filename) config = load_yaml_file(filename) env = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development' config = config[env] if config.key? env config.each do |key, value| case key when 'services' then load_services value end end end |
#load_services(services) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load services from configuration YAML.
88 89 90 91 92 93 94 |
# File 'lib/acfs/configuration.rb', line 88 def load_services(services) services.each do |service, data| if (val = data).is_a?(String) || (val = data['locate']) locate service.to_sym, val end end end |
#locate(service, uri) ⇒ undefined #locate(service) ⇒ URI, NilClass
56 57 58 59 60 61 62 63 |
# File 'lib/acfs/configuration.rb', line 56 def locate(service, uri = nil) service = service.to_s.underscore.to_sym if uri.nil? locations[service] else locations[service] = URI.parse uri end end |