Module: Containers::Configurable

Extended by:
ActiveSupport::Concern
Included in:
CLI, Generator::CLI
Defined in:
lib/containers/concerns/configurable.rb

Constant Summary collapse

DEFAULT_CONFIGURATION =
{
  "organization" => {
    "name" => gitname
  },
  "app" => {
    "name" => File.basename(Dir.pwd).parameterize,
    "directory" => "."
  },
  "docker" => {
    "directory" => ".",
    "default_service" => nil,
    "compose_files" => ["docker-compose.yml"]
  }
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.gitnameObject



6
7
8
9
10
11
12
13
# File 'lib/containers/concerns/configurable.rb', line 6

def self.gitname
  email = begin
    `git config --get user.email`.strip
  rescue
    nil
  end
  email&.split("@")&.first || "example"
end

Instance Method Details

#app_directoryObject



38
39
40
# File 'lib/containers/concerns/configurable.rb', line 38

def app_directory
  configuration["app"]["directory"]
end

#app_nameObject



34
35
36
# File 'lib/containers/concerns/configurable.rb', line 34

def app_name
  configuration["app"]["name"]
end

#configurationObject



54
55
56
57
58
59
60
61
# File 'lib/containers/concerns/configurable.rb', line 54

def configuration
  @configuration ||=
    if File.exist?(".containers.yml")
      YAML.load_file(".containers.yml")
    else
      DEFAULT_CONFIGURATION
    end
end

#docker_compose_filesObject



50
51
52
# File 'lib/containers/concerns/configurable.rb', line 50

def docker_compose_files
  configuration["docker"]["compose_files"]
end

#docker_default_serviceObject



46
47
48
# File 'lib/containers/concerns/configurable.rb', line 46

def docker_default_service
  configuration["docker"]["default_service"]
end

#docker_directoryObject



42
43
44
# File 'lib/containers/concerns/configurable.rb', line 42

def docker_directory
  configuration["docker"]["directory"]
end

#organization_nameObject



30
31
32
# File 'lib/containers/concerns/configurable.rb', line 30

def organization_name
  configuration["organization"]["name"]
end