public
Created — forked from chad/configuration.rb

  • Download Gist
configuration.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
class Configuration
attr_accessor :tail_logs, :max_connections, :admin_password
attr_accessor :app_server
 
def app_server
@app_server_config ||= AppServer.new
yield @app_server_config if block_given?
@app_server_config
end
end
 
class AppServer
attr_accessor :port, :admin_password
end
 
def configure
c = Configuration.new
yield c if block_given?
c
end
 
configuration = configure do |config|
config.tail_logs = true
config.max_connections = 55
config.admin_password = 'secret'
config.app_server do |app_server_config|
app_server_config.port = 8808
app_server_config.admin_password = config.admin_password
end
end
 
puts configuration.class # => Configuration
puts configuration.tail_logs # => true
puts configuration.app_server.admin_password # => 'secret'

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.