Module: Escualo::Env
- Defined in:
- lib/escualo/env.rb
Class Method Summary collapse
- .clean(ssh, options) ⇒ Object
- .environment_variables(environment) ⇒ Object
- .get(ssh, variable) ⇒ Object
- .list(ssh) ⇒ Object
- .locale_export ⇒ Object
- .locale_variables ⇒ Object
- .present?(ssh, variable) ⇒ Boolean
- .set(ssh, variables) ⇒ Object
- .set_builtins(ssh, options) ⇒ Object
- .set_command(key, value) ⇒ Object
- .setup(ssh) ⇒ Object
- .unset(ssh, variable_names) ⇒ Object
Class Method Details
.clean(ssh, options) ⇒ Object
23 24 25 26 27 |
# File 'lib/escualo/env.rb', line 23 def self.clean(ssh, ) .env = get(ssh, 'RACK_ENV').split('=').second.strip ssh.exec!("rm ~/.escualo/vars/*") set_builtins ssh, end |
.environment_variables(environment) ⇒ Object
62 63 64 65 66 |
# File 'lib/escualo/env.rb', line 62 def self.environment_variables(environment) %w{RAILS_ENV NODE_ENV RACK_ENV}.map do |it| [it, environment] end.to_h end |
.get(ssh, variable) ⇒ Object
36 37 38 |
# File 'lib/escualo/env.rb', line 36 def self.get(ssh, variable) ssh.exec!("cat ~/.escualo/vars/#{variable}") end |
.list(ssh) ⇒ Object
19 20 21 |
# File 'lib/escualo/env.rb', line 19 def self.list(ssh) ssh.exec!("cat ~/.escualo/vars/*").gsub("export ", '') end |
.locale_export ⇒ Object
68 69 70 |
# File 'lib/escualo/env.rb', line 68 def self.locale_export locale_variables.map { |key, value| "#{key}=#{value}" }.join(' ') end |
.locale_variables ⇒ Object
56 57 58 59 60 |
# File 'lib/escualo/env.rb', line 56 def self.locale_variables %w{LANG LC_ALL LC_NAME LC_IDENTIFICATION LC_PAPER LC_ADDRESS LC_TIME LC_NUMERIC LC_MONETARY LC_TELEPHONE LC_MEASUREMENT}.map do |it| [it, 'en_US.UTF-8'] end.to_h end |
.present?(ssh, variable) ⇒ Boolean
29 30 31 32 33 34 |
# File 'lib/escualo/env.rb', line 29 def self.present?(ssh, variable) value = get(ssh, variable) value.present? rescue false end |
.set(ssh, variables) ⇒ Object
40 41 42 43 44 |
# File 'lib/escualo/env.rb', line 40 def self.set(ssh, variables) variables.each do |key, value| ssh.exec!(set_command key, value) end end |
.set_builtins(ssh, options) ⇒ Object
13 14 15 16 17 |
# File 'lib/escualo/env.rb', line 13 def self.set_builtins(ssh, ) set ssh, ESCUALO_BASE_VERSION: Escualo::BASE_VERSION set ssh, Escualo::Env.locale_variables set ssh, Escualo::Env.environment_variables(.env) end |
.set_command(key, value) ⇒ Object
46 47 48 |
# File 'lib/escualo/env.rb', line 46 def self.set_command(key, value) "echo export #{key}=#{value} > ~/.escualo/vars/#{key}" end |
.setup(ssh) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/escualo/env.rb', line 3 def self.setup(ssh) source_escualorc = "'source ~/.escualorc'" ssh.exec! %Q{ mkdir -p ~/.escualo/vars && \ echo 'for var in ~/.escualo/vars/*; do source $var; done' > ~/.escualorc && \ chmod u+x ~/.escualorc && \ grep -q #{source_escualorc} ~/.bashrc || echo #{source_escualorc} >> ~/.bashrc } end |
.unset(ssh, variable_names) ⇒ Object
50 51 52 53 54 |
# File 'lib/escualo/env.rb', line 50 def self.unset(ssh, variable_names) variable_names.each do |name| ssh.exec!("rm ~/.escualo/vars/#{name}") end end |