Module: Vault

Defined in:
lib/vault-tools.rb,
lib/vault-tools/app.rb,
lib/vault-tools/hid.rb,
lib/vault-tools/log.rb,
lib/vault-tools/web.rb,
lib/vault-tools/user.rb,
lib/vault-tools/config.rb,
lib/vault-tools/product.rb,
lib/vault-tools/version.rb,
lib/vault-tools/pipeline.rb,
lib/vault-tools/statement_store.rb,
lib/vault-tools/sinatra_helpers/html_serializer.rb

Overview

Yes, there's a lot of stuff on STDERR. But its on stderr and not stdout so you can pipe to /dev/null if you hate it. These methods do some pretty heavy-handed environment munging and could lead to some hair-pulling errors if you're not aware of whats going on.

Defined Under Namespace

Modules: App, Config, HID, Log, Product, SinatraHelpers, Tools, User Classes: Pipeline, StatementStore, Web

Class Method Summary collapse

Class Method Details

.hack_time_classObject



36
37
38
39
40
41
42
# File 'lib/vault-tools.rb', line 36

def self.hack_time_class
  $stderr.puts "Modifying Time#to_s to use #iso8601..." if ENV['DEBUG']
  # use send to call private method
  Time.send(:define_method, :to_s) do
    self.iso8601
  end
end

.init_scrollsObject



58
59
60
61
62
63
64
# File 'lib/vault-tools.rb', line 58

def self.init_scrolls
  # Scrolls 0.9.0+ requires an init
  Scrolls.init(
    global_context: {app: Vault::Config.app_name},
    time_unit: 'milliseconds'
  )
end

.load_pathObject

adds ./lib dir to the load path



24
25
26
27
# File 'lib/vault-tools.rb', line 24

def self.load_path
  $stderr.puts "Adding './lib' to path..." if ENV['DEBUG']
  $LOAD_PATH.unshift(File.expand_path('./lib'))
end

.load_shared_configObject



50
51
52
53
54
55
56
# File 'lib/vault-tools.rb', line 50

def self.load_shared_config
  return unless Config.production?
  if Config[:config_app]
    $stderr.puts "Loading shared config from app: #{Config[:config_app]}..."
    Config.load_shared!(Config[:config_app])
  end
end

.override_global_configObject



44
45
46
47
48
# File 'lib/vault-tools.rb', line 44

def self.override_global_config
  $stderr.puts "Set Config to Vault::Config..." if ENV['DEBUG']
  Object.send(:remove_const, :Config) if defined? Object::Config
  Object.const_set(:Config, Vault::Config)
end

.requireObject

require bundler and the proper gems for the ENV



17
18
19
20
21
# File 'lib/vault-tools.rb', line 17

def self.require
  Kernel.require 'bundler'
  $stderr.puts "Loading #{ENV['RACK_ENV']} environment..."
  Bundler.require :default, ENV['RACK_ENV'].to_sym
end

.set_timezonesObject

sets TZ to UTC and Sequel timezone to :utc



30
31
32
33
34
# File 'lib/vault-tools.rb', line 30

def self.set_timezones
  $stderr.puts "Setting timezones to UTC..." if ENV['DEBUG']
  Sequel.default_timezone = :utc if defined? Sequel
  ENV['TZ'] = 'UTC'
end

.setupObject

all in one go



67
68
69
70
71
72
73
74
75
# File 'lib/vault-tools.rb', line 67

def self.setup
  self.require
  self.load_path
  self.set_timezones
  self.hack_time_class
  self.override_global_config
  self.load_shared_config
  self.init_scrolls
end