Module: Markify::Settings

Defined in:
lib/markify/settings.rb

Overview

Copyright Daniel Meißner <[email protected]>, 2013

This file is part of Markify.

Markify is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Markify is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Markify. If not, see <www.gnu.org/licenses/>.

Constant Summary collapse

DEFAULT_CONFIG_PATH =
Pathname(ENV['HOME'] + "/markify/config.yml")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



25
26
27
# File 'lib/markify/settings.rb', line 25

def config
  @config
end

Class Method Details

.create_example_config(file = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/markify/settings.rb', line 40

def self.create_example_config(file = nil)
  config_file = file || DEFAULT_CONFIG_PATH

  if config_file.exist?
    puts "Configuration file #{config_file} already exists."
    exit
  else
    Dir.mkdir(config_file.dirname) unless config_file.dirname.exist?

    File.open(config_file, 'a+', 0600) do |file|
      file.puts <<CONTENT
university:
acronym: hbrs
login_name: "foobaz2s"
login_password: "fnord2000"

xmpp:
bot_id: "[email protected]"
bot_password: "möpmöp"

recipients: [[email protected], müp@möp.blap.ba]

general:
verbose: false
database_file: "#{ENV['HOME'] + '/markify/hashes.txt'}"
CONTENT
    end

    puts "#{config_file} created."

    exit
  end
end

.load!(file = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/markify/settings.rb', line 27

def self.load!(file = nil)
  config_file = file || DEFAULT_CONFIG_PATH

  if config_file.exist?
    config = YAML::load_file(config_file)
    validate(config)
  else
    puts 'Config file does not exist. Please create it.'
    puts "  $ #{$0} --init"
    exit
  end
end

.test_settings(config, scraper) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/markify/settings.rb', line 74

def self.test_settings(config, scraper)
  scraper.

  begin
    Markify::Bot.new(config['xmpp']['bot_id'],
                   config['xmpp']['bot_password']).send_message(config['xmpp']['recipients'],
                                                               "#{Markify::NAME} Test #{Time.now}")
  rescue Jabber::ClientAuthenticationFailure
    puts "XMPP: Bot authentication failed."
  else
    puts "XMPP: Bot works."
  end
end