Module: DataShifter::Internal::Env

Defined in:
lib/data_shifter/internal/env.rb

Overview

Environment variable parsing utilities. All methods are stateless module functions.

Constant Summary collapse

TRUTHY =
%w[1 true t yes y on].freeze
FALSEY =
%w[0 false f no n off].freeze

Class Method Summary collapse

Class Method Details

.boolean!(var) ⇒ Object

Raises on anything unrecognized rather than picking a side. The old DRY_RUN == "true" compare silently read DRY_RUN=1 as "not dry" and committed the shift — a value that is truthy in every other tool has to mean dry run here or it means data loss.



24
25
26
27
28
29
30
31
32
# File 'lib/data_shifter/internal/env.rb', line 24

def boolean!(var)
  raw = ENV.fetch(var, nil)
  case raw.to_s.strip.downcase
  when *TRUTHY then true
  when *FALSEY then false
  else
    raise ArgumentError, "#{var}=#{raw.inspect} is not a boolean — use one of: #{(TRUTHY + FALSEY).join(", ")}"
  end
end

.continue_from_idObject

Get CONTINUE_FROM environment variable value. Returns nil if not set or empty.



48
49
50
# File 'lib/data_shifter/internal/env.rb', line 48

def continue_from_id
  ENV.fetch("CONTINUE_FROM", nil).presence
end

.dry_run?Boolean

COMMIT= means commit. Otherwise DRY_RUN decides, defaulting to a dry run.

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/data_shifter/internal/env.rb', line 14

def dry_run?
  return !boolean!("COMMIT") if ENV["COMMIT"].present?
  return true if ENV["DRY_RUN"].blank?

  boolean!("DRY_RUN")
end

.status_interval_secondsObject

Parse STATUS_INTERVAL environment variable, falling back to config. Returns nil if not set/invalid and config is nil.



36
37
38
39
40
41
42
43
44
# File 'lib/data_shifter/internal/env.rb', line 36

def status_interval_seconds
  if ENV["STATUS_INTERVAL"].present?
    Integer(ENV.fetch("STATUS_INTERVAL", nil), 10)
  else
    DataShifter.config.status_interval_seconds
  end
rescue ArgumentError
  DataShifter.config.status_interval_seconds
end