Class: Prefab::Options
- Inherits:
-
Object
- Object
- Prefab::Options
- Defined in:
- lib/prefab/options.rb
Defined Under Namespace
Modules: DATASOURCES, ON_INITIALIZATION_FAILURE, ON_NO_DEFAULT
Constant Summary collapse
- DEFAULT_LOG_FORMATTER =
proc { |severity, datetime, progname, msg| "#{severity.ljust(5)} #{datetime}: #{progname} #{msg}\n" }
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#initialization_timeout_sec ⇒ Object
readonly
Returns the value of attribute initialization_timeout_sec.
-
#log_formatter ⇒ Object
readonly
Returns the value of attribute log_formatter.
-
#logdev ⇒ Object
readonly
Returns the value of attribute logdev.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#on_init_failure ⇒ Object
readonly
Returns the value of attribute on_init_failure.
-
#on_no_default ⇒ Object
readonly
Returns the value of attribute on_no_default.
-
#prefab_api_url ⇒ Object
readonly
Returns the value of attribute prefab_api_url.
-
#prefab_config_classpath_dir ⇒ Object
readonly
Returns the value of attribute prefab_config_classpath_dir.
-
#prefab_config_override_dir ⇒ Object
readonly
Returns the value of attribute prefab_config_override_dir.
-
#prefab_envs ⇒ Object
readonly
Returns the value of attribute prefab_envs.
-
#prefab_grpc_url ⇒ Object
readonly
Returns the value of attribute prefab_grpc_url.
-
#shared_cache ⇒ Object
readonly
Returns the value of attribute shared_cache.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Instance Method Summary collapse
-
#initialize(api_key: ENV['PREFAB_API_KEY'], logdev: $stdout, stats: NoopStats.new, shared_cache: NoopCache.new, namespace: "", log_formatter: DEFAULT_LOG_FORMATTER, prefab_api_url: ENV["PREFAB_API_URL"] || 'https://api.prefab.cloud', prefab_grpc_url: ENV["PREFAB_GRPC_URL"] || 'grpc.prefab.cloud:443', on_no_default: ON_NO_DEFAULT::RAISE, initialization_timeout_sec: 10, on_init_failure: ON_INITIALIZATION_FAILURE::RAISE, prefab_datasources: ENV['PREFAB_DATASOURCES'] == "LOCAL_ONLY" ? DATASOURCES::LOCAL_ONLY : DATASOURCES::ALL, prefab_config_override_dir: Dir.home, prefab_config_classpath_dir: ".", prefab_envs: ENV['PREFAB_ENVS'].nil? ? [] : ENV['PREFAB_ENVS'].split(",")) ⇒ Options
constructor
A new instance of Options.
- #local_only? ⇒ Boolean
- #url_for_api_cdn ⇒ Object
Constructor Details
#initialize(api_key: ENV['PREFAB_API_KEY'], logdev: $stdout, stats: NoopStats.new, shared_cache: NoopCache.new, namespace: "", log_formatter: DEFAULT_LOG_FORMATTER, prefab_api_url: ENV["PREFAB_API_URL"] || 'https://api.prefab.cloud', prefab_grpc_url: ENV["PREFAB_GRPC_URL"] || 'grpc.prefab.cloud:443', on_no_default: ON_NO_DEFAULT::RAISE, initialization_timeout_sec: 10, on_init_failure: ON_INITIALIZATION_FAILURE::RAISE, prefab_datasources: ENV['PREFAB_DATASOURCES'] == "LOCAL_ONLY" ? DATASOURCES::LOCAL_ONLY : DATASOURCES::ALL, prefab_config_override_dir: Dir.home, prefab_config_classpath_dir: ".", prefab_envs: ENV['PREFAB_ENVS'].nil? ? [] : ENV['PREFAB_ENVS'].split(",")) ⇒ Options
Returns a new instance of Options.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/prefab/options.rb', line 36 def initialize( api_key: ENV['PREFAB_API_KEY'], logdev: $stdout, stats: NoopStats.new, # receives increment("prefab.limitcheck", {:tags=>["policy_group:page_view", "pass:true"]}) shared_cache: NoopCache.new, # Something that quacks like Rails.cache ideally memcached namespace: "", log_formatter: DEFAULT_LOG_FORMATTER, prefab_api_url: ENV["PREFAB_API_URL"] || 'https://api.prefab.cloud', prefab_grpc_url: ENV["PREFAB_GRPC_URL"] || 'grpc.prefab.cloud:443', on_no_default: ON_NO_DEFAULT::RAISE, # options :raise, :warn_and_return_nil, initialization_timeout_sec: 10, # how long to wait before on_init_failure on_init_failure: ON_INITIALIZATION_FAILURE::RAISE, #options :unlock_and_continue, :lock_and_keep_trying, :raise # new_config_callback: nil, #callback method # live_override_url: nil, prefab_datasources: ENV['PREFAB_DATASOURCES'] == "LOCAL_ONLY" ? DATASOURCES::LOCAL_ONLY : DATASOURCES::ALL, prefab_config_override_dir: Dir.home, prefab_config_classpath_dir: ".", prefab_envs: ENV['PREFAB_ENVS'].nil? ? [] : ENV['PREFAB_ENVS'].split(",") ) # debugger @api_key = api_key @logdev = logdev @stats = stats @shared_cache = shared_cache @namespace = namespace @log_formatter = log_formatter @prefab_api_url = prefab_api_url @prefab_grpc_url = prefab_grpc_url @on_no_default = on_no_default @initialization_timeout_sec = initialization_timeout_sec @on_init_failure = on_init_failure @prefab_datasources = prefab_datasources @prefab_config_classpath_dir = prefab_config_classpath_dir @prefab_config_override_dir = prefab_config_override_dir @prefab_envs = Array(prefab_envs) end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
4 5 6 |
# File 'lib/prefab/options.rb', line 4 def api_key @api_key end |
#initialization_timeout_sec ⇒ Object (readonly)
Returns the value of attribute initialization_timeout_sec.
13 14 15 |
# File 'lib/prefab/options.rb', line 13 def initialization_timeout_sec @initialization_timeout_sec end |
#log_formatter ⇒ Object (readonly)
Returns the value of attribute log_formatter.
6 7 8 |
# File 'lib/prefab/options.rb', line 6 def log_formatter @log_formatter end |
#logdev ⇒ Object (readonly)
Returns the value of attribute logdev.
5 6 7 |
# File 'lib/prefab/options.rb', line 5 def logdev @logdev end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
9 10 11 |
# File 'lib/prefab/options.rb', line 9 def namespace @namespace end |
#on_init_failure ⇒ Object (readonly)
Returns the value of attribute on_init_failure.
14 15 16 |
# File 'lib/prefab/options.rb', line 14 def on_init_failure @on_init_failure end |
#on_no_default ⇒ Object (readonly)
Returns the value of attribute on_no_default.
12 13 14 |
# File 'lib/prefab/options.rb', line 12 def on_no_default @on_no_default end |
#prefab_api_url ⇒ Object (readonly)
Returns the value of attribute prefab_api_url.
10 11 12 |
# File 'lib/prefab/options.rb', line 10 def prefab_api_url @prefab_api_url end |
#prefab_config_classpath_dir ⇒ Object (readonly)
Returns the value of attribute prefab_config_classpath_dir.
16 17 18 |
# File 'lib/prefab/options.rb', line 16 def prefab_config_classpath_dir @prefab_config_classpath_dir end |
#prefab_config_override_dir ⇒ Object (readonly)
Returns the value of attribute prefab_config_override_dir.
15 16 17 |
# File 'lib/prefab/options.rb', line 15 def prefab_config_override_dir @prefab_config_override_dir end |
#prefab_envs ⇒ Object (readonly)
Returns the value of attribute prefab_envs.
17 18 19 |
# File 'lib/prefab/options.rb', line 17 def prefab_envs @prefab_envs end |
#prefab_grpc_url ⇒ Object (readonly)
Returns the value of attribute prefab_grpc_url.
11 12 13 |
# File 'lib/prefab/options.rb', line 11 def prefab_grpc_url @prefab_grpc_url end |
#shared_cache ⇒ Object (readonly)
Returns the value of attribute shared_cache.
8 9 10 |
# File 'lib/prefab/options.rb', line 8 def shared_cache @shared_cache end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
7 8 9 |
# File 'lib/prefab/options.rb', line 7 def stats @stats end |
Instance Method Details
#local_only? ⇒ Boolean
73 74 75 |
# File 'lib/prefab/options.rb', line 73 def local_only? @prefab_datasources == DATASOURCES::LOCAL_ONLY end |
#url_for_api_cdn ⇒ Object
78 79 80 |
# File 'lib/prefab/options.rb', line 78 def url_for_api_cdn ENV['PREFAB_CDN_URL'] || "#{@prefab_api_url.gsub(/\./, "-")}.global.ssl.fastly.net" end |