Class: Whv
- Inherits:
-
Object
- Object
- Whv
- Defined in:
- lib/whv_nz/whv.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#online_services ⇒ Object
readonly
Returns the value of attribute online_services.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
Instance Method Summary collapse
-
#initialize ⇒ Whv
constructor
A new instance of Whv.
- #prestart ⇒ Object
- #save_cookie(cookie) ⇒ Object
- #start ⇒ Object
- #success ⇒ Object
Constructor Details
#initialize ⇒ Whv
Returns a new instance of Whv.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/whv_nz/whv.rb', line 15 def initialize @opts = Slop.parse do on '-n', '--new', 'Generate config file' on '-c', '--config=', 'Config file path' on '-p', '--production', 'Use real account' on '-d', '--daemon', 'In background' on '-h', '--help', 'Show help info' end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
13 14 15 |
# File 'lib/whv_nz/whv.rb', line 13 def data @data end |
#online_services ⇒ Object (readonly)
Returns the value of attribute online_services.
13 14 15 |
# File 'lib/whv_nz/whv.rb', line 13 def online_services @online_services end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
13 14 15 |
# File 'lib/whv_nz/whv.rb', line 13 def pages @pages end |
Instance Method Details
#prestart ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/whv_nz/whv.rb', line 53 def prestart if !Dir.exist?("log") Dir.mkdir("log") end @data_path = Dir.pwd + "/log/data.yml" if !File.exist?(@data_path) File.new(@data_path, "w+") end @env = @opts.production? ? "production" : "development" @file_data = YAML.load(File.read(@data_path)) || {} @data = @file_data[@env] || {} @config = YAML.load(File.read(@opts[:config]))[@env] log_path = Dir.pwd + "/log/whv.log" logdev = @opts.daemon? ? log_path : "| tee #{log_path}" @logger = Logger.new(logdev, 0, 100 * 1024 * 1024) @pages = Pages.new(@data, @config, @logger) @online_services = OnlineServices.new(@data, @config, @logger) Rollbar.configure do |config| config.access_token = @config["rollbar_token"] config.enabled = @config["rollbar_token"] config.use_sucker_punch end Signal.trap("INT") { save_data exit 2 } Signal.trap("TERM") { save_data exit 2 } end |
#save_cookie(cookie) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/whv_nz/whv.rb', line 94 def () @data["cookie"] = save_data @logger.info "updated cookie: #{}" end |
#start ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/whv_nz/whv.rb', line 29 def start begin if @opts.daemon? ::Process.daemon(true, true) start_apply elsif @opts.new? path = File.dirname(__FILE__) + "/config.yml" FileUtils.cp(path, Dir.pwd) elsif @opts[:config] prestart start_apply else puts @opts end exit 0 rescue StandardError => e @logger.fatal(e) Rollbar.critical(e) raise e end end |
#success ⇒ Object
101 102 103 104 105 106 |
# File 'lib/whv_nz/whv.rb', line 101 def success @file_data = YAML.load(File.read(@data_path)) || {} @data = @file_data[@env] || {} @data["success"] end |