Class: Picobox::DockerCompose::Config
- Inherits:
-
Object
- Object
- Picobox::DockerCompose::Config
- Defined in:
- lib/picobox/docker_compose/config.rb
Instance Method Summary collapse
- #add_service(service, links) ⇒ Object
- #check!(type) ⇒ Object
-
#initialize(filename) ⇒ Config
constructor
A new instance of Config.
- #remove_service(service) ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(filename) ⇒ Config
Returns a new instance of Config.
4 5 6 7 8 9 |
# File 'lib/picobox/docker_compose/config.rb', line 4 def initialize(filename) @config = YAML.load_file(filename) @filename = filename rescue SystemCallError raise Picobox::Errors::FileNotFoundError, "could not open #{filename}" end |
Instance Method Details
#add_service(service, links) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/picobox/docker_compose/config.rb', line 19 def add_service(service, links) service_name = service.keys.first services = config['services'].merge! service links.each do |link| existing_service = services[link] if existing_service existing_service['links'] = (existing_service['links'] || Array.new).push service_name existing_service['links'].uniq! end end end |
#check!(type) ⇒ Object
12 13 14 15 16 |
# File 'lib/picobox/docker_compose/config.rb', line 12 def check!(type) unless config['services'].keys.include? type raise Picobox::Errors::ServiceNotInstalled end end |
#remove_service(service) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/picobox/docker_compose/config.rb', line 34 def remove_service(service) service_name = service.keys.first services = config['services'] services.delete(service_name) services.each_value do |service| if service['links'] service['links'].delete(service_name) service.delete('links') if service['links'].empty? end end end |
#save ⇒ Object
49 50 51 52 53 |
# File 'lib/picobox/docker_compose/config.rb', line 49 def save File.open(filename,'w') do |h| h.write config.to_yaml end end |