Class: Feed2Email::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/feed2email/config.rb

Constant Summary collapse

CONFIG_FILE =
File.join(CONFIG_DIR, 'config.yml')

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/feed2email/config.rb', line 9

def config
  @config
end

Instance Method Details

#read!Object



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

def read!
  FileUtils.mkdir_p(CONFIG_DIR)

  @config = YAML.load(open(CONFIG_FILE)) rescue nil

  if !@config.is_a? Hash
    STDERR.puts "Error: missing or invalid config file #{CONFIG_FILE}"
    exit 1
  end

  if '%o' % (File.stat(CONFIG_FILE).mode & 0777) != '600'
    STDERR.puts "Error: invalid permissions for config file #{CONFIG_FILE}"
    exit 2
  end

  if @config['recipient'].nil?
    STDERR.puts "Error: recipient missing from config file #{CONFIG_FILE}"
    exit 3
  end
end