Class: Foruiman::Configuration
- Inherits:
-
Object
- Object
- Foruiman::Configuration
- Defined in:
- lib/foruiman/configuration.rb
Constant Summary collapse
- OPTIONS =
%w[procfile root env dotenv port log_lines timeout exit_on tui].freeze
- BOOLEAN_OPTIONS =
%w[dotenv tui].freeze
- PATH_OPTIONS =
%w[procfile root env].freeze
Instance Method Summary collapse
- #environment ⇒ Object
- #exit_on ⇒ Object
-
#initialize(options, directory: Dir.pwd) ⇒ Configuration
constructor
A new instance of Configuration.
- #log_lines ⇒ Object
- #port(env) ⇒ Object
- #procfile ⇒ Object
- #root ⇒ Object
- #timeout ⇒ Object
- #tui? ⇒ Boolean
Constructor Details
#initialize(options, directory: Dir.pwd) ⇒ Configuration
Returns a new instance of Configuration.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/foruiman/configuration.rb', line 10 def initialize(, directory: Dir.pwd) @directory = directory = defaults.merge(.to_h.transform_keys { |key| key.to_s.tr("-", "_") }) BOOLEAN_OPTIONS.each do |key| next unless .key?(key) next if [true, false].include?([key]) raise Foruiman::Error, "#{key}: expected true or false" end PATH_OPTIONS.each do |key| next unless .key?(key) next if [key].is_a?(String) && ![key].empty? raise Foruiman::Error, "#{key}: expected a nonempty path" end end |
Instance Method Details
#environment ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/foruiman/configuration.rb', line 36 def environment # Foreman loads the default environment before inferring a root from -f. env_root = File.(.fetch("root", "."), @directory) files = ["env"]&.split(",", -1)&.map do |file| raise Foruiman::Error, "env: expected comma-separated file paths" if file.empty? File.(file, @directory) end Foruiman::Env.load(root: env_root, file: files, dotenv: .fetch("dotenv", true)) end |
#exit_on ⇒ Object
62 63 64 65 66 67 |
# File 'lib/foruiman/configuration.rb', line 62 def exit_on value = .fetch("exit_on", "all") return value.to_sym if %w[all any failure].include?(value) raise Foruiman::Error, "exit-on must be all, any, or failure" end |
#log_lines ⇒ Object
51 52 53 |
# File 'lib/foruiman/configuration.rb', line 51 def log_lines integer("log_lines", .fetch("log_lines", "10000")) end |
#port(env) ⇒ Object
47 48 49 |
# File 'lib/foruiman/configuration.rb', line 47 def port(env) integer("port", .fetch("port") { env.fetch("PORT", "5000") }) end |
#procfile ⇒ Object
27 28 29 30 |
# File 'lib/foruiman/configuration.rb', line 27 def procfile # Foreman's explicit -f is relative to invocation, independently of -d. File.(.fetch("procfile", File.join(.fetch("root", "."), "Procfile")), @directory) end |
#root ⇒ Object
32 33 34 |
# File 'lib/foruiman/configuration.rb', line 32 def root File.(.fetch("root", File.dirname(procfile)), @directory) end |
#timeout ⇒ Object
55 56 57 58 59 60 |
# File 'lib/foruiman/configuration.rb', line 55 def timeout value = Float(.fetch("timeout", 5), exception: false) return value if value&.finite? && value >= 0 raise Foruiman::Error, "timeout must be a finite nonnegative number" end |
#tui? ⇒ Boolean
69 70 71 |
# File 'lib/foruiman/configuration.rb', line 69 def tui? .fetch("tui", true) end |