module Dump::Env
Working with environment variables
Constants
- DICTIONARY
- EXPLANATIONS
Public Class Methods
[](key)
click to toggle source
# File lib/dump/env.rb, line 65 def [](key) if DICTIONARY[key] ENV.values_at(*DICTIONARY[key]).compact.first else ENV[key] end end
downcase(key)
click to toggle source
# File lib/dump/env.rb, line 86 def downcase(key) self[key].to_s.downcase.strip end
explain_variables_for_command(command)
click to toggle source
# File lib/dump/env.rb, line 128 def explain_variables_for_command(command) ".\n" + variable_names_for_command(command).map do |variable_name| " #{DICTIONARY[variable_name].join(', ')} — #{EXPLANATIONS[variable_name]}\n" end.join('') end
filter(key, splitter = nil)
click to toggle source
# File lib/dump/env.rb, line 73 def filter(key, splitter = nil) @filters ||= Hash.new{ |h, k| h[k] = Filter.new(*k) } @filters[[self[key], splitter]] end
for_command(command, strings = false)
click to toggle source
# File lib/dump/env.rb, line 112 def for_command(command, strings = false) env = {} variable_names_for_command(command).each do |variable| if (value = self[variable]) env[strings ? DICTIONARY[variable].first : variable] = value end end env end
no?(key)
click to toggle source
# File lib/dump/env.rb, line 82 def no?(key) %w[0 n f].include?(first_char(key)) end
stringify!(hash)
click to toggle source
# File lib/dump/env.rb, line 122 def stringify!(hash) hash.keys.each do |key| hash[DICTIONARY[key] ? DICTIONARY[key].first : key.to_s] = hash.delete(key) end end
variable_names_for_command(command)
click to toggle source
# File lib/dump/env.rb, line 90 def variable_names_for_command(command) m = { :select => [:like, :tags], :assets => [:assets], :restore_options => [:migrate_down, :restore_schema, :restore_tables, :restore_assets], :transfer_options => [:transfer_via], } m[:versions] = m[:select] | [:summary] m[:create] = [:desc, :tags, :tables] | m[:assets] m[:restore] = m[:select] | m[:restore_options] m[:cleanup] = m[:select] | [:leave] m[:transfer] = m[:select] | m[:transfer_options] m[:mirror] = [:backup] | m[:create] | m[:transfer_options] | m[:restore_options] m[:backup] = m[:create] | [:transfer_via] m[:backup_restore] = m[:transfer] | m[:restore_options] m[command] || [] end
with_clean_env(hash = {}, &block)
click to toggle source
# File lib/dump/env.rb, line 59 def with_clean_env(hash = {}, &block) empty_env = {} DICTIONARY.keys.each{ |key| empty_env[key] = nil } with_env(empty_env.merge(hash), &block) end
with_env(hash) { || ... }
click to toggle source
# File lib/dump/env.rb, line 43 def with_env(hash) old = {} hash.each do |key, value| key = DICTIONARY[key].first if DICTIONARY[key] old[key] = ENV[key] ENV[key] = value end begin yield ensure old.each do |key, value| ENV[key] = value end end end
yes?(key)
click to toggle source
# File lib/dump/env.rb, line 78 def yes?(key) %w[1 y t].include?(first_char(key)) end
Private Class Methods
first_char(key)
click to toggle source
# File lib/dump/env.rb, line 137 def first_char(key) downcase(key)[0, 1] end