Skip to content

Instantly share code, notes, and snippets.

@urfolomeus
Created March 26, 2009 11:59
Show Gist options
  • Save urfolomeus/86044 to your computer and use it in GitHub Desktop.
Save urfolomeus/86044 to your computer and use it in GitHub Desktop.
class Configuration
attr_accessor :tail_logs, :max_connections, :admin_password, :app_server
def app_server
@app_server ||= AppServerConfiguration.new
if block_given?
yield(@app_server)
end
@app_server
end
end
class AppServerConfiguration
attr_accessor :port, :admin_password
end
def configure
configuration = Configuration.new
yield(configuration)
configuration
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
p configuration.class # => Configuration
p configuration.tail_logs # => true
p configuration.app_server.admin_password # => 'secret'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment