Class: JadePug::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/jade-pug/config.rb

Overview

Defines template engine compiler configuration.

Direct Known Subclasses

Jade::Config, Pug::Config

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Allows to dynamically set config attributes.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jade-pug/config.rb', line 14

def method_missing(name, *args, &block)
  return super if block

  case args.size
    when 0

      # config.client?
      if name =~ /\A(\w+)\?\z/
        !!(respond_to?($1) ? send($1) : instance_variable_get("@#{ $1 }"))

      # config.client
      elsif name =~ /\A(\w+)\z/
        instance_variable_get("@#{ $1 }")

      else
        super
      end

    when 1
      # config.client=
      if name =~ /\A(\w+)=\z/
        instance_variable_set("@#{ $1 }", args.first)
      else
        super
      end
    else
      super
  end
end

Instance Method Details

#respond_to_missing?(name, include_all) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/jade-pug/config.rb', line 44

def respond_to_missing?(name, include_all)
  name.match?(/\A\w+[=?]?\z/)
end

#to_hashHash Also known as: to_h

Transforms config to the hash with all keys symbolized.

Returns:

  • (Hash)


52
53
54
55
56
# File 'lib/jade-pug/config.rb', line 52

def to_hash
  instance_variables.each_with_object({}) do |var, h|
    h[var[1..-1].to_sym] = instance_variable_get(var)
  end
end