Module: BetterAuth::Env

Defined in:
lib/better_auth/env.rb

Class Method Summary collapse

Class Method Details

.csv(name) ⇒ Object



23
24
25
# File 'lib/better_auth/env.rb', line 23

def csv(name)
  fetch(name, "").split(",").map(&:strip).reject(&:empty?)
end

.fetch(name, default = nil) ⇒ Object



18
19
20
21
# File 'lib/better_auth/env.rb', line 18

def fetch(name, default = nil)
  value = get(name)
  value.nil? ? default : value
end

.get(name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/better_auth/env.rb', line 7

def get(name)
  open_auth_name = open_auth_name(name)
  return nil unless open_auth_name

  value = ENV[open_auth_name]
  return value if present?(value)

  value = ENV[name]
  present?(value) ? value : nil
end

.open_auth_name(name) ⇒ Object



27
28
29
30
31
32
# File 'lib/better_auth/env.rb', line 27

def open_auth_name(name)
  text = name.to_s
  return nil unless text.start_with?("BETTER_AUTH_")

  text.sub(/\ABETTER_AUTH_/, "OPEN_AUTH_")
end

.present?(value) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/better_auth/env.rb', line 34

def present?(value)
  value && !value.empty?
end