module Crystal class Setting attr_accessor :host, :port, :environment, :server, :session, :static %w{session show_exceptions static}.each do |m| iv = "@#{m}" define_method("#{m}?"){!!instance_variable_get(iv)} end def initialize { :host => '0.0.0.0', :port => 4000, :environment => 'development', :server => 'Mongrel', :session => true, :static => true }.each{|k, v| self.send "#{k}=", v if self.send(k).nil?} end def development?; environment == 'development' end def production?; environment == 'production' end def test?; environment == 'test' end def apply_command_line_arguments! require 'optparse' case ARGV.first when "p" then self.environment = "production" when "d" then self.environment = "development" when "t" then self.environment = "test" end OptionParser.new{|op| op.on('-e env'){|val| self.environment = val} op.on('-s server'){|val| self.server = val} op.on('-p port'){|val| self.port = val.to_i} }.parse!(ARGV.dup) end end end