Class: Docker::Rails::Config

Inherits:
Dry::Config::Base
  • Object
show all
Defined in:
lib/docker/rails/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/docker/rails/config.rb', line 6

def initialize(options = {})
  raise 'build unspecified' if options[:build].nil?
  build = options[:build]

  raise 'target unspecified' if options[:target].nil?
  target = options[:target]

  # determine project_name
  dir_name = Dir.pwd.split('/').last
  project_name = "#{dir_name}_#{target}_#{build}"

  # FIXME: temporarily sanitize project_name until they loosen restrictions see https://github.com/docker/compose/issues/2119
  project_name = project_name.gsub(/[^a-z0-9]/, '')

  super({
            default_configuration: {
                build: build,
                target: target,
                project_name: project_name,
                verbose: false
            },
            prune: [:development, :test, :parallel_tests, :staging, :production]
        }.merge(options))
end

Instance Method Details

#load!(environment, *filenames) ⇒ Object



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/docker/rails/config.rb', line 42

def load!(environment, *filenames)

  # reject nil target environments
  raise 'Target environment unspecified.' if environment.nil?

  # default the filename if unspecified
  if filenames.empty?
    puts 'Using docker-rails.yml'
    filenames = ['docker-rails.yml']
  end

  # reject unknown target environments
  unpruned_config = load_unpruned(environment, *filenames)
  raise "Unknown target environment '#{environment.to_sym}'" if unpruned_config[environment.to_sym].nil?


  # -----------------------------------------------------
  # Generate defaults for GEMSET_VOLUME and SSH_AGENT
  generated_defaults = {compose: {}}
  compose = generated_defaults[:compose]

  # now add the generated to the seeded default configuration
  @default_configuration.merge!(generated_defaults)

  # reset the base @configuration by loading the new default configuration
  clear

  # finally, load the config as internal state
  super(environment, *filenames)
end

#to_yaml(config = @configuration) ⇒ Object



36
37
38
39
40
# File 'lib/docker/rails/config.rb', line 36

def to_yaml(config = @configuration)
  yaml = super(config)
  yaml = yaml.gsub(/command: .$/, 'command: >')
  yaml
end

#write_docker_compose_file(output_filename = 'docker-compose.yml') ⇒ Object



32
33
34
# File 'lib/docker/rails/config.rb', line 32

def write_docker_compose_file(output_filename = 'docker-compose.yml')
  write_yaml_file(output_filename, self[:'compose'])
end