Module: Environment
- Defined in:
- lib/docker_rack/dev_environment.rb
Class Method Summary collapse
- .get_data(url) ⇒ Object
-
.get_env(environment) ⇒ Object
def self.docker_host host_ip = ENV return host_ip unless host_ip.nil? host_ip = ENV return nil if host_ip.nil? host_ip[/tcp://(+)/,1] end.
- .post_data(url, payload) ⇒ Object
- .validate! ⇒ Object
- .work_dir ⇒ Object
Class Method Details
.get_data(url) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/docker_rack/dev_environment.rb', line 27 def self.get_data(url) command = "curl #{url}" command += " 2> /dev/null" unless LOG_LEVEL == 'DEBUG' puts command if LOG_LEVEL == 'DEBUG' if Gem.win_platform? uri = URI(url) result = Net::HTTP.get(uri) else result = `#{command}` end puts result validate! puts "Result: #{result}" if LOG_LEVEL == 'DEBUG' return result end |
.get_env(environment) ⇒ Object
def self.docker_host
host_ip = ENV['HOST_IP']
return host_ip unless host_ip.nil?
host_ip = ENV['DOCKER_HOST']
return nil if host_ip.nil?
host_ip[/tcp:\/\/([^:]+)/,1]
end
def self.hostip
@host_ip = @host_ip || docker_host || (`ifconfig docker0 | grep inet | grep 'inet\s' | awk '{print $2}'`).strip
puts "#{@host_ip}."
@host_ip
end
22 23 24 25 |
# File 'lib/docker_rack/dev_environment.rb', line 22 def self.get_env(environment) env = environment || 'development' env.to_sym end |
.post_data(url, payload) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/docker_rack/dev_environment.rb', line 43 def self.post_data(url, payload) command = "curl -X PUT -d '#{payload}' #{url}" command += " 2> /dev/null" unless LOG_LEVEL == 'DEBUG' puts command if LOG_LEVEL == 'DEBUG' if Gem.win_platform? uri = URI(url) http = Net::HTTP.new(uri.host, uri.port) # http.set_debug_output($stdout) header = {'Content-Type' => 'text/json'} request = Net::HTTP::Put.new(uri.request_uri, initheader = header) # request.add_field('Content-Type', 'application/json') # request.add_field('Content-Type', 'text/plain; charset=utf-8') request.body = payload # .to_json response = http.request(request) result = response.body else result = `#{command}` end validate! puts "Result: #{result}" if LOG_LEVEL == 'DEBUG' return result end |
.validate! ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/docker_rack/dev_environment.rb', line 66 def self.validate! if $?.to_i == 0 puts 'OK' if LOG_LEVEL == 'DEBUG' else puts 'Failed' if LOG_LEVEL == 'DEBUG' end end |
.work_dir ⇒ Object
4 5 6 |
# File 'lib/docker_rack/dev_environment.rb', line 4 def self.work_dir @work_dir = @work_dir || ENV['WORK_DIR'] || Dir.pwd end |