Module: Dockable
- Defined in:
- lib/dockable.rb,
lib/dockable/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
- .load_command(argv, procfile_location: nil) ⇒ Object
- .load_environment_variables(bucket:, key:) ⇒ Object
- .presence(value) ⇒ Object
Class Method Details
.load_command(argv, procfile_location: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dockable.rb', line 20 def self.load_command(argv, procfile_location: nil) procfile_location = presence(procfile_location) || "Procfile" if File.exist?(procfile_location) && argv.size == 1 commands = YAML.load_file(procfile_location) if commands.has_key?(argv[0]) [ commands[argv[0]].to_s ] else argv end elsif argv.size == 0 fail ArgumentError, "No command specified" else argv end end |
.load_environment_variables(bucket:, key:) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/dockable.rb', line 7 def self.load_environment_variables(bucket:, key:) if presence(bucket) && presence(key) require "aws-sdk-s3" client = Aws::S3::Client.new resp = client.get_object(bucket: bucket, key: key) body = resp.body.read YAML.load(body).map { |k, v| [ k.to_s, v.to_s ] }.to_h else STDERR.puts "Dockable warning: No bucket or key found, no environment file loaded." {} end end |
.presence(value) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dockable.rb', line 36 def self.presence(value) case value when nil, false then nil when /\A[[:space:]]*\z/ nil when Array, Hash if value.empty? nil else value end else value end end |