Skip to content

Instantly share code, notes, and snippets.

@sneeu
Created April 7, 2011 10:48
Show Gist options
  • Save sneeu/907541 to your computer and use it in GitHub Desktop.
Save sneeu/907541 to your computer and use it in GitHub Desktop.
Small DSL for SRC charity tutorial.
class AppServer
attr_accessor :port, :admin_password
end
class Configuration
attr_reader :app_server
attr_accessor :tail_logs, :max_connections, :admin_password
def app_server(&block)
if block
if not @app_server
@app_server = AppServer.new
end
yield @app_server
end
@app_server
end
end
def configure
c = Configuration.new
yield c
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.admin_password = config.admin_password
app_server_config.port = 8808
end
end
p configuration.class # => Configuration
p configuration.tail_logs # => true
p configuration.app_server.class # => 'AppServer'
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