Class: Pedia::Config

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

Defined Under Namespace

Classes: Option

Constant Summary collapse

CONFIG_DIR =

Constants #########################################################

File.expand_path "~/.config/pedia"
CACHE_DIR =
File.expand_path "~/.cache/pedia"
CONFIG_FILE =
File.join CONFIG_DIR, "config.yml"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = "config.yml") ⇒ Config

Methods ###########################################################



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/wp/config.rb', line 54

def initialize(filename="config.yml")
  Dir.mkdir CONFIG_DIR unless File.exists? CONFIG_DIR

  unless File.exists? CONFIG_FILE

  end

  yaml = YAML.load open(CONFIG_FILE)

  @options = {}

  yaml.each do |key, val|
    p [key, val]
    if opt = @@spec[key]
      @options[key] = opt.with(value: val)
    end
  end
end

Class Method Details

.option(*args) ⇒ Object



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

def self.option(*args)
  opt = Option.new(*args)

  attr_accessor opt.name

  @@spec ||= {}
  @@spec[opt.name] = opt
end

Instance Method Details

#optionsObject



74
75
76
# File 'lib/wp/config.rb', line 74

def options
  @options
end