Class: Ginatra::Config

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

Constant Summary collapse

CONFIG_PATH =
File.expand_path("~/.ginatra/config.yml")
DEFAULT_CONFIG =
{
  :git_dirs => [File.expand_path("#{current_path}/../../repos/*")],
  :ignored_files => ['README.md'],
  :description => "View My Git Repositories",
  :port => 9797
}

Class Method Summary collapse

Class Method Details

.dump!Object



28
29
30
31
32
# File 'lib/ginatra/config.rb', line 28

def self.dump!
  File.open(CONFIG_PATH, 'w') do |f|
    YAML.dump(@config, f)
  end
end

.load!Object



19
20
21
22
23
24
25
26
# File 'lib/ginatra/config.rb', line 19

def self.load!
  @config = {}
  begin
    @config = YAML.load_file(CONFIG_PATH)
  rescue Errno::ENOENT
  end
  @config = DEFAULT_CONFIG.merge(@config)
end

.method_missing(sym, *args, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/ginatra/config.rb', line 34

def self.method_missing(sym, *args, &block)
  if @config.respond_to?(sym)
    @config.send(sym, *args, &block)
  elsif @config.has_key?(sym)
    @config[sym]
  else
    super
  end
end

.respond_to?(name) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
# File 'lib/ginatra/config.rb', line 44

def self.respond_to?(name)
  if @config.respond_to?(name)
    true
  elsif @config.has_key?(name)
    true
  else
    super
  end
end

.setup!Object

Very Destructive Method. Use with care!



13
14
15
16
17
# File 'lib/ginatra/config.rb', line 13

def self.setup! # Very Destructive Method. Use with care!
  File.open(CONFIG_PATH, 'w') do |f|
    YAML.dump(DEFAULT_CONFIG, f)
  end
end