Class: Whisper::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/whisper/config.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

REQUIRED =
[ :whisper_dir, :title, :tagline, :root, :public_url_root, :from_email_address, :comment_mbox ]
OPTIONAL =
[ :post_dir, :comment_dir, :template_dir, :static_dir, :helper_dir, :draft_dir, :sendmail,
:development_port, :port, :page_size, :rack_handler, :mbox_offset_filename, :author_dir,
:x_accel_redirect, :formatter_dir]
ALL =
REQUIRED + OPTIONAL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fn, base_dir, mode = :development) ⇒ Config

Returns a new instance of Config.



16
17
18
19
20
21
22
23
# File 'lib/whisper/config.rb', line 16

def initialize fn, base_dir, mode=:development
  @mode = mode
  @hash = YAML.load_file fn
  @hash[:whisper_dir] = base_dir
  REQUIRED.each { |k| raise Error, "missing required configuration value '#{k}'" unless @hash[k] }
  @hash.keys.each { |k| raise Error, "unknown configuration value '#{k}'" unless ALL.member? k }
  fill_defaults!
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



25
26
27
# File 'lib/whisper/config.rb', line 25

def mode
  @mode
end

Instance Method Details

#use_this_portObject



27
# File 'lib/whisper/config.rb', line 27

def use_this_port; @mode == :development ? @hash[:development_port] : @hash[:port] end