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/tracing.rb,
lib/vault-tools/version.rb,
lib/vault-tools/pipeline.rb,
lib/vault-tools/statement_store.rb,
lib/vault-tools/tracing/sidekiq_client.rb,
lib/vault-tools/tracing/sidekiq_server.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, Tracing, User Classes: Pipeline, StatementStore, Web

Class Method Summary collapse

Class Method Details

.hack_time_classObject



47
48
49
50
51
52
53
# File 'lib/vault-tools.rb', line 47

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



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

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



35
36
37
38
# File 'lib/vault-tools.rb', line 35

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

.load_shared_configObject



61
62
63
64
65
66
67
# File 'lib/vault-tools.rb', line 61

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



55
56
57
58
59
# File 'lib/vault-tools.rb', line 55

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



28
29
30
31
32
# File 'lib/vault-tools.rb', line 28

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



41
42
43
44
45
# File 'lib/vault-tools.rb', line 41

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



78
79
80
81
82
83
84
85
86
87
# File 'lib/vault-tools.rb', line 78

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
  Tracing.configure
end