Skip to content

Commit

Permalink
Extract Webmachine::Configurable module.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuel committed Jan 3, 2012
1 parent 34ecddc commit f96140c
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/webmachine/configuration.rb
Expand Up @@ -10,21 +10,23 @@ module Webmachine
# @attr [Hash] adapter_options adapter-specific options, defaults to {}
Configuration = Struct.new(:ip, :port, :adapter, :adapter_options)

class << self
module Configurable
# @return [Configuration] the current configuration
attr_accessor :configuration
end

# Sets configuration for the web server via the passed
# block. Returns Webmachine so you can chain it with
# Webmachine.run.
# @yield [config] a block in which to set configuration values
# @yieldparam [Configuration] config the Configuration instance
# @return [Webmachine]
def self.configure
@configuration ||= Configuration.new("0.0.0.0", 8080, :WEBrick, {})
yield @configuration if block_given?
self
# Sets configuration for the web server via the passed
# block. Returns Webmachine so you can chain it with
# Webmachine.run.
# @yield [config] a block in which to set configuration values
# @yieldparam [Configuration] config the Configuration instance
# @return [Webmachine]
def configure
@configuration ||= Configuration.new("0.0.0.0", 8080, :WEBrick, {})
yield @configuration if block_given?
self
end
end

extend Configurable
end

0 comments on commit f96140c

Please sign in to comment.