Class: Markabb::Config

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

Overview

The config class, inherits from Hash Based on the config class from mina (github.com/nadarei/mina)

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



5
6
7
8
# File 'lib/markabb/config.rb', line 5

def initialize
    super
    load_default_config
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object

Allows access to the hash though methods Provides all getter, setter and query methods for any key in the hash



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/markabb/config.rb', line 12

def method_missing(meth, *args, &blk)
    name = meth.to_s
    return evaluate(self[meth])  if name.size == 1
    # Ruby 1.8.7 doesn't let you do string[-1]
    key, suffix = name[0..-2].to_sym, name[-1..-1]
    case suffix
        when '='
            self[key] = args.first
        when '?'
            include? key
        when '!'
            raise Error, "Setting :#{key} is not set" unless include?(key)
            evaluate self[key]
        else
            evaluate self[meth]
    end
end

Instance Method Details

#evaluate(value) ⇒ Object

Returns a value or runs a proc depending on the value in the hash



31
32
33
34
35
36
37
# File 'lib/markabb/config.rb', line 31

def evaluate(value)
    if value.is_a?(Proc)
        value.call
    else
        value
    end
end

#load_default_configObject

Sets the default config values



40
41
42
43
44
45
46
47
# File 'lib/markabb/config.rb', line 40

def load_default_config
    self[:disable_html] ||= true
    self[:url_target] ||= "_BLANK"
    self[:image_alt] ||= "Posted Image"
    self[:table_width] ||= "100%"
    self[:syntax_highlighter] ||= :raw
    self[:coderay_options] ||= {}
end