Module: Escualo::Env

Defined in:
lib/escualo/env.rb

Class Method Summary collapse

Class Method Details

.clean(session, options) ⇒ Object



17
18
19
20
21
# File 'lib/escualo/env.rb', line 17

def self.clean(session, options)
  session.clean_environment_variables!

  set_builtins session, options
end

.clean_commandObject



45
46
47
# File 'lib/escualo/env.rb', line 45

def self.clean_command
  'rm ~/.escualo/vars/*'
end

.environment_variables(environment) ⇒ Object



65
66
67
68
69
# File 'lib/escualo/env.rb', line 65

def self.environment_variables(environment)
  %w{RAILS_ENV NODE_ENV RACK_ENV}.map do |it|
    [it, environment]
  end.to_h
end

.get(session, variable) ⇒ Object



29
30
31
# File 'lib/escualo/env.rb', line 29

def self.get(session, variable)
  session.ask("cat ~/.escualo/vars/#{variable}")
end

.list(session) ⇒ Object



13
14
15
# File 'lib/escualo/env.rb', line 13

def self.list(session)
  session.ask('cat ~/.escualo/vars/*').gsub('export ', '')
end

.localeObject



61
62
63
# File 'lib/escualo/env.rb', line 61

def self.locale
  'en_US.UTF-8'
end

.locale_exportObject



71
72
73
# File 'lib/escualo/env.rb', line 71

def self.locale_export
  locale_variables.map { |key, value| "#{key}=#{value}" }.join(' ')
end

.locale_variablesObject



53
54
55
56
57
58
59
# File 'lib/escualo/env.rb', line 53

def self.locale_variables
  %w{LANG LANGUAGE
    LC_ALL LC_NAME LC_IDENTIFICATION LC_PAPER LC_ADDRESS LC_TIME
    LC_NUMERIC LC_MONETARY LC_TELEPHONE LC_MEASUREMENT}.map do |it|
    [it, locale]
  end.to_h
end

.present?(session, variable) ⇒ Boolean



23
24
25
26
27
# File 'lib/escualo/env.rb', line 23

def self.present?(session, variable)
  get(session, variable).present?
rescue
  false
end

.set(session, variables) ⇒ Object



33
34
35
# File 'lib/escualo/env.rb', line 33

def self.set(session, variables)
  session.set_environment_variables! variables
end

.set_builtins(session, options) ⇒ Object



7
8
9
10
11
# File 'lib/escualo/env.rb', line 7

def self.set_builtins(session, options)
  set session, ESCUALO_BASE_VERSION: Escualo::BASE_VERSION
  set session, Escualo::Env.locale_variables
  set session, Escualo::Env.environment_variables(options.env)
end

.set_command(key, value) ⇒ Object



49
50
51
# File 'lib/escualo/env.rb', line 49

def self.set_command(key, value)
  "echo export #{key}=#{value} > ~/.escualo/vars/#{key}"
end

.setup(session) ⇒ Object



3
4
5
# File 'lib/escualo/env.rb', line 3

def self.setup(session)
  session.setup_environment_variables!
end

.unset(session, variable_names) ⇒ Object



37
38
39
# File 'lib/escualo/env.rb', line 37

def self.unset(session, variable_names)
  session.unset_environment_variables! variable_names
end

.unset_command(name) ⇒ Object



41
42
43
# File 'lib/escualo/env.rb', line 41

def self.unset_command(name)
  "rm ~/.escualo/vars/#{name}"
end