Class: Savvy::Configuration
- Inherits:
-
Object
- Object
- Savvy::Configuration
- Defined in:
- lib/savvy/configuration.rb
Overview
Shared configuration object for a Savvy-enabled application
Constant Summary collapse
- APP_ENV_VARS =
%w[ RAILS_ENV RACK_ENV ].freeze
- DEFAULT_REDIS_ENV_VARS =
%w[ REDISTOGO_URL REDISCLOUD_URL BOXEN_REDIS_URL REDIS_URL ].freeze
- DEFAULT_REDIS_URL =
'redis://localhost:6379'
Instance Attribute Summary collapse
-
#app_env ⇒ Object
Returns the value of attribute app_env.
- #app_name ⇒ Object
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#include_app_env ⇒ Boolean
(also: #include_app_env?)
Whether the Rails/Rack env should be included when building namespaces.
- #redis_default_url ⇒ String
- #redis_env_vars ⇒ Object
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#build_namespace(*parts, prefix: nil, separator: ?.) ⇒ String
Build a namespace that takes environmental and application factors into account.
- #configure {|to_dsl| ... } ⇒ Object
-
#initialize(root:, env: Savvy.env) ⇒ Configuration
constructor
A new instance of Configuration.
- #read_from_env(*vars, **options) ⇒ String
- #setup! ⇒ Object
Constructor Details
#initialize(root:, env: Savvy.env) ⇒ Configuration
Returns a new instance of Configuration.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/savvy/configuration.rb', line 28 def initialize(root:, env: Savvy.env) @root = root @env = env @config_file = find_config_file @app_name = root.basename.to_s @include_app_env = false @redis_env_vars = DEFAULT_REDIS_ENV_VARS.dup @redis_default_url = DEFAULT_REDIS_URL end |
Instance Attribute Details
#app_env ⇒ Object
Returns the value of attribute app_env.
73 74 75 |
# File 'lib/savvy/configuration.rb', line 73 def app_env @app_env end |
#app_name ⇒ String #app_name=(new_app_name) ⇒ Object
81 82 83 |
# File 'lib/savvy/configuration.rb', line 81 def app_name @app_name end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
25 26 27 |
# File 'lib/savvy/configuration.rb', line 25 def env @env end |
#include_app_env ⇒ Boolean Also known as: include_app_env?
Whether the Rails/Rack env should be included when building namespaces.
94 95 96 |
# File 'lib/savvy/configuration.rb', line 94 def include_app_env @include_app_env end |
#redis_default_url ⇒ String
104 105 106 |
# File 'lib/savvy/configuration.rb', line 104 def redis_default_url @redis_default_url end |
#redis_env_vars ⇒ <String> #redis_env_vars=(new_env_keys) ⇒ Object
118 119 120 |
# File 'lib/savvy/configuration.rb', line 118 def redis_env_vars @redis_env_vars end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
26 27 28 |
# File 'lib/savvy/configuration.rb', line 26 def root @root end |
Instance Method Details
#build_namespace(*parts, prefix: nil, separator: ?.) ⇒ String
Build a namespace that takes environmental and application factors into account.
52 53 54 55 56 57 58 59 |
# File 'lib/savvy/configuration.rb', line 52 def build_namespace(*parts, prefix: nil, separator: ?.) [ prefix, app_name, ( app_env if include_app_env? ), *parts ].compact.join(separator) end |
#configure {|to_dsl| ... } ⇒ Object
61 62 63 64 65 |
# File 'lib/savvy/configuration.rb', line 61 def configure yield to_dsl if block_given? return self end |
#read_from_env(*vars, **options) ⇒ String
69 70 71 |
# File 'lib/savvy/configuration.rb', line 69 def read_from_env(*vars, **) @env[*vars, **] end |
#setup! ⇒ Object
40 41 42 43 44 |
# File 'lib/savvy/configuration.rb', line 40 def setup! @app_env = @env[*APP_ENV_VARS] load_from_file! end |