Module: Orchestration::Services::ConfigurationBase
- Included in:
- App::Configuration, Database::Configuration, Listener::Configuration, Mongo::Configuration, RabbitMQ::Configuration, Redis::Configuration
- Defined in:
- lib/orchestration/services/mixins/configuration_base.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#service_name ⇒ Object
readonly
Returns the value of attribute service_name.
Class Method Summary collapse
Instance Method Summary collapse
- #configured? ⇒ Boolean
- #host ⇒ Object
- #image ⇒ Object
- #initialize(env, service_name = nil, options = {}) ⇒ Object
- #parse_port(service) ⇒ Object
- #port ⇒ Object
- #service ⇒ Object
- #yaml(content) ⇒ Object
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/orchestration/services/mixins/configuration_base.rb', line 6 def env @env end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/orchestration/services/mixins/configuration_base.rb', line 6 def error @error end |
#service_name ⇒ Object (readonly)
Returns the value of attribute service_name.
6 7 8 |
# File 'lib/orchestration/services/mixins/configuration_base.rb', line 6 def service_name @service_name end |
Class Method Details
.included(base) ⇒ Object
8 9 10 |
# File 'lib/orchestration/services/mixins/configuration_base.rb', line 8 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#configured? ⇒ Boolean
38 39 40 41 42 43 44 |
# File 'lib/orchestration/services/mixins/configuration_base.rb', line 38 def configured? port true rescue KeyError => e @error = e false end |
#host ⇒ Object
31 32 33 34 35 36 |
# File 'lib/orchestration/services/mixins/configuration_base.rb', line 31 def host return @service_name if @env.environment == 'test' && @options[:sidecar] return '127.0.0.1' if %w[test development].include?(@env.environment) @service_name end |
#image ⇒ Object
46 47 48 |
# File 'lib/orchestration/services/mixins/configuration_base.rb', line 46 def image service['image'] end |
#initialize(env, service_name = nil, options = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/orchestration/services/mixins/configuration_base.rb', line 25 def initialize(env, service_name = nil, = {}) @env = env @options = @service_name = service_name || self.class.service_name end |
#parse_port(service) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/orchestration/services/mixins/configuration_base.rb', line 65 def parse_port(service) # Remove our sidecar variable for easier parsing # '{sidecar-27018:}27017' => '27018:27017' local, _, remote = service.fetch('ports') .first .sub(/\${sidecar-(\d+):}/, '\1:') .partition(':') [local, remote] end |
#port ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/orchestration/services/mixins/configuration_base.rb', line 50 def port return @env.app_port if @service_name == 'app' local, remote = parse_port(service).map(&:to_i) return remote if @env.environment == 'test' && @options[:sidecar] (@env.environment == 'deployment' ? remote : local) end |
#service ⇒ Object
59 60 61 62 63 |
# File 'lib/orchestration/services/mixins/configuration_base.rb', line 59 def service @service ||= @env.docker_compose_config .fetch('services') .fetch(@service_name) end |
#yaml(content) ⇒ Object
75 76 77 78 |
# File 'lib/orchestration/services/mixins/configuration_base.rb', line 75 def yaml(content) # Whitelist `Symbol` and permit aliases: YAML.safe_load(content, permitted_classes: [Symbol], aliases: true) end |