Module: ComplyanceSDK::Models::Environment
- Defined in:
- lib/complyance_sdk/models/environment.rb
Overview
Environment enumeration with direct URL mapping Matches the Java SDK’s Environment enum
Constant Summary collapse
- DEV =
Development environment
:dev- TEST =
Test environment
:test- STAGE =
Staging environment
:stage- LOCAL =
Local environment
:local- SANDBOX =
Sandbox environment (maps to DEV URL)
:sandbox- SIMULATION =
Simulation environment (maps to PROD URL)
:simulation- PRODUCTION =
Production environment
:production
Class Method Summary collapse
-
.all ⇒ Array<Symbol>
Get all valid environments.
-
.base_url(environment) ⇒ String
Get the base URL for the given environment URLs are dynamically constructed based on the ENV environment variable.
-
.development_environment?(environment) ⇒ Boolean
Check if environment is a development environment Development environments allow all countries.
-
.from_string(str) ⇒ Symbol
Parse string to environment symbol.
-
.get_env_value ⇒ Object
Gets the ENV value from system environment variable or .env files.
-
.legacy_base_url(environment) ⇒ Object
deprecated
Deprecated.
Use the specific environment constants instead
-
.production_environment?(environment) ⇒ Boolean
Check if environment is a production environment Production environments have country restrictions.
-
.read_env_from_file(file_path) ⇒ Object
Reads the ENV variable from a .env file.
-
.to_api_value(environment) ⇒ String
Map environment to API value (for backend compatibility) The API expects “sandbox”, “simulation”, or “prod”.
-
.to_string(environment) ⇒ String
Convert environment to string format.
-
.valid?(environment) ⇒ Boolean
Check if environment is valid.
Class Method Details
.all ⇒ Array<Symbol>
Get all valid environments
115 116 117 |
# File 'lib/complyance_sdk/models/environment.rb', line 115 def self.all URL_MAPPING.keys end |
.base_url(environment) ⇒ String
Get the base URL for the given environment URLs are dynamically constructed based on the ENV environment variable. If ENV is set to “dev”, “test”, or “stage”, that subdomain is used. If not set, defaults to “prod” (production). LOCAL environment always uses localhost.
40 41 42 43 44 45 46 47 48 |
# File 'lib/complyance_sdk/models/environment.rb', line 40 def self.base_url(environment) if environment == LOCAL return 'http://127.0.0.1:4000/unify' end env_value = get_env_value subdomain = (env_value && !env_value.strip.empty?) ? env_value.downcase.strip : 'prod' "https://#{subdomain}.gets.complyance.io/unify" end |
.development_environment?(environment) ⇒ Boolean
Check if environment is a development environment Development environments allow all countries
166 167 168 |
# File 'lib/complyance_sdk/models/environment.rb', line 166 def self.development_environment?(environment) [DEV, TEST, STAGE, LOCAL].include?(environment) end |
.from_string(str) ⇒ Symbol
Parse string to environment symbol
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/complyance_sdk/models/environment.rb', line 132 def self.from_string(str) return str if str.is_a?(Symbol) env = str.to_s.downcase.to_sym unless valid?(env) raise ArgumentError, "Invalid environment: #{str}. Valid environments: #{all.join(', ')}" end env end |
.get_env_value ⇒ Object
Gets the ENV value from system environment variable or .env files
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/complyance_sdk/models/environment.rb', line 51 def self.get_env_value return @cached_env_value if @env_value_loaded # First, check system environment variable env_value = ENV['ENV'] if env_value && !env_value.strip.empty? @cached_env_value = env_value @env_value_loaded = true return env_value end # Try to read from .env files in common locations env_file_paths = [ '.env', '../.env', '../../.env', '../services/encore/.env', '../../services/encore/.env', 'services/encore/.env' ] env_file_paths.each do |file_path| env_value = read_env_from_file(file_path) if env_value && !env_value.strip.empty? @cached_env_value = env_value @env_value_loaded = true return env_value end end # No ENV found, cache nil and return nil @env_value_loaded = true @cached_env_value = nil nil end |
.legacy_base_url(environment) ⇒ Object
Use the specific environment constants instead
Legacy support - maintain backward compatibility
190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/complyance_sdk/models/environment.rb', line 190 def self.legacy_base_url(environment) case environment when :production URL_MAPPING[PRODUCTION] when :sandbox URL_MAPPING[SANDBOX] when :local URL_MAPPING[LOCAL] else base_url(environment) end end |
.production_environment?(environment) ⇒ Boolean
Check if environment is a production environment Production environments have country restrictions
157 158 159 |
# File 'lib/complyance_sdk/models/environment.rb', line 157 def self.production_environment?(environment) [SANDBOX, SIMULATION, PRODUCTION].include?(environment) end |
.read_env_from_file(file_path) ⇒ Object
Reads the ENV variable from a .env file
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/complyance_sdk/models/environment.rb', line 88 def self.read_env_from_file(file_path) return nil unless File.exist?(file_path) && File.file?(file_path) begin File.readlines(file_path).each do |line| line = line.strip next if line.empty? || line.start_with?('#') if line.start_with?('ENV=') value = line[4..-1].strip if (value.start_with?('"') && value.end_with?('"')) || (value.start_with?("'") && value.end_with?("'")) value = value[1..-2] end return value end end rescue StandardError # Silently ignore - file might not be readable end nil end |
.to_api_value(environment) ⇒ String
Map environment to API value (for backend compatibility) The API expects “sandbox”, “simulation”, or “prod”
175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/complyance_sdk/models/environment.rb', line 175 def self.to_api_value(environment) case environment when LOCAL, DEV, TEST, STAGE, SANDBOX 'sandbox' when SIMULATION 'simulation' when PRODUCTION 'prod' else 'sandbox' # Default to sandbox for safety end end |
.to_string(environment) ⇒ String
Convert environment to string format
148 149 150 |
# File 'lib/complyance_sdk/models/environment.rb', line 148 def self.to_string(environment) environment.to_s.upcase end |
.valid?(environment) ⇒ Boolean
Check if environment is valid
123 124 125 |
# File 'lib/complyance_sdk/models/environment.rb', line 123 def self.valid?(environment) URL_MAPPING.key?(environment) end |