Class: Jets::Dotenv::Convention

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/jets/dotenv/convention.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.jets_env_pathObject

Does not use the envs.fallbakc and envs.unique settings.



41
42
43
44
45
46
# File 'lib/jets/dotenv/convention.rb', line 41

def jets_env_path
  project = config.dotenv.ssm.project_name || Jets.project.name
  ssm_env = config.dotenv.ssm.long_env_name ? (long_env_map[Jets.env.to_sym] || Jets.env) : Jets.env

  "/#{project}/#{ssm_env}/"
end

.long_envObject

Jets 5.0 legacy



72
73
74
75
# File 'lib/jets/dotenv/convention.rb', line 72

def long_env
  short_env = Jets.env.to_s
  long_env_map[short_env.to_sym] || short_env
end

.long_env_mapObject



77
78
79
80
81
82
83
# File 'lib/jets/dotenv/convention.rb', line 77

def long_env_map
  {
    dev: "development",
    prod: "production",
    stag: "staging"
  }
end

.resolved_envObject



52
53
54
55
56
57
58
# File 'lib/jets/dotenv/convention.rb', line 52

def resolved_env
  if unique_env?(env)
    env # IE: dev or prod
  else
    config.dotenv.ssm.envs.fallback # IE: dev
  end
end

.resolved_long_envObject



66
67
68
69
# File 'lib/jets/dotenv/convention.rb', line 66

def resolved_long_env
  short_env = resolved_env
  long_env_map[short_env.to_sym] || short_env
end

.ssm_envObject



48
49
50
# File 'lib/jets/dotenv/convention.rb', line 48

def ssm_env
  config.dotenv.ssm.long_env_helper ? resolved_long_env : resolved_env
end

.ssm_pathObject



32
33
34
35
36
37
38
# File 'lib/jets/dotenv/convention.rb', line 32

def ssm_path
  project = config.dotenv.ssm.project_name || Jets.project.name
  # consider long_env config in the ssm_name only
  ssm_env = config.dotenv.ssm.long_env_name ? resolved_long_env : resolved_env

  "/#{project}/#{ssm_env}/"
end

.unique_env?(env) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
64
# File 'lib/jets/dotenv/convention.rb', line 60

def unique_env?(env)
  config.dotenv.ssm.envs.unique.nil? ||
    config.dotenv.ssm.envs.unique == :all ||
    config.dotenv.ssm.envs.unique.include?(env)
end

Instance Method Details

#ssm_name(ssm_leaf_name) ⇒ Object

ssm leaf name is the name of the leaf in the SSM parameter store. It can come from the key or the value.

DATABASE_URL=SSM        => DATABASE_URL
DATABASE_URL=SSM:DB_URL => DB_URL

Full SSM name. Example:

/project/dev/DATABASE_URL
/project/dev/DB_URL


19
20
21
22
23
24
25
# File 'lib/jets/dotenv/convention.rb', line 19

def ssm_name(ssm_leaf_name)
  if config.dotenv.ssm.convention_resolver
    config.dotenv.ssm.convention_resolver.call(ssm_leaf_name)
  else
    "#{self.class.ssm_path}#{ssm_leaf_name}"
  end
end