Class: FigRake::Configuration
- Inherits:
-
Object
- Object
- FigRake::Configuration
- Defined in:
- lib/fig_rake/configuration.rb
Constant Summary collapse
- COMPOSE_FILE =
"docker-compose.yml"- FIG_FILE =
"fig.yml"
Instance Attribute Summary collapse
-
#container_name ⇒ Object
Returns the value of attribute container_name.
-
#docker_command ⇒ Object
Returns the value of attribute docker_command.
-
#rake_args ⇒ Object
Returns the value of attribute rake_args.
Instance Method Summary collapse
- #command_from_defaults ⇒ Object
- #command_from_environment ⇒ Object
- #command_from_file ⇒ Object
- #compose_file_exists? ⇒ Boolean
- #fig_file_exists? ⇒ Boolean
-
#initialize(name: nil, command: nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #name_from_defaults ⇒ Object
- #name_from_environment ⇒ Object
- #name_from_file ⇒ Object
Constructor Details
#initialize(name: nil, command: nil) ⇒ Configuration
Returns a new instance of Configuration.
10 11 12 13 |
# File 'lib/fig_rake/configuration.rb', line 10 def initialize(name: nil, command: nil) @container_name = name || name_from_defaults @docker_command = command || command_from_defaults end |
Instance Attribute Details
#container_name ⇒ Object
Returns the value of attribute container_name.
5 6 7 |
# File 'lib/fig_rake/configuration.rb', line 5 def container_name @container_name end |
#docker_command ⇒ Object
Returns the value of attribute docker_command.
5 6 7 |
# File 'lib/fig_rake/configuration.rb', line 5 def docker_command @docker_command end |
#rake_args ⇒ Object
Returns the value of attribute rake_args.
5 6 7 |
# File 'lib/fig_rake/configuration.rb', line 5 def rake_args @rake_args end |
Instance Method Details
#command_from_defaults ⇒ Object
19 20 21 |
# File 'lib/fig_rake/configuration.rb', line 19 def command_from_defaults command_from_environment || command_from_file end |
#command_from_environment ⇒ Object
27 28 29 |
# File 'lib/fig_rake/configuration.rb', line 27 def command_from_environment ENV['FIG_RAKE_COMMAND'] end |
#command_from_file ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fig_rake/configuration.rb', line 39 def command_from_file case when compose_file_exists? "docker-compose" when fig_file_exists? "fig" else raise "No configuration file found are you in the right Directory?" end end |
#compose_file_exists? ⇒ Boolean
31 32 33 |
# File 'lib/fig_rake/configuration.rb', line 31 def compose_file_exists? File.exists? COMPOSE_FILE end |
#fig_file_exists? ⇒ Boolean
35 36 37 |
# File 'lib/fig_rake/configuration.rb', line 35 def fig_file_exists? File.exists? FIG_FILE end |
#name_from_defaults ⇒ Object
15 16 17 |
# File 'lib/fig_rake/configuration.rb', line 15 def name_from_defaults name_from_environment || name_from_file end |
#name_from_environment ⇒ Object
23 24 25 |
# File 'lib/fig_rake/configuration.rb', line 23 def name_from_environment ENV['FIG_RAKE_CONTAINER'] end |
#name_from_file ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fig_rake/configuration.rb', line 50 def name_from_file file_name = case when compose_file_exists? COMPOSE_FILE when fig_file_exists? FIG_FILE else raise "No configuration file found are you in the right Directory?" end container_config = YAML.load(File.read(file_name)).to_a.select do |(_, opts)| opts.has_key?("build") end container_config.first.first end |