Class: Checklister::ConfigurationFile

Inherits:
Object
  • Object
show all
Defined in:
lib/checklister/configuration_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ConfigurationFile

Returns a new instance of ConfigurationFile.



7
8
9
10
11
# File 'lib/checklister/configuration_file.rb', line 7

def initialize(path)
  @path = path
  @file = load_file
  @services = load_services
end

Instance Attribute Details

#servicesObject (readonly)

Returns the value of attribute services.



5
6
7
# File 'lib/checklister/configuration_file.rb', line 5

def services
  @services
end

Instance Method Details

#add_service(service) ⇒ Object



17
18
19
20
21
# File 'lib/checklister/configuration_file.rb', line 17

def add_service(service)
  symbolized_service = Checklister::Sanitizer.symbolize(service)
  remove_service symbolized_service[:endpoint]
  @services << symbolized_service
end

#exist?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/checklister/configuration_file.rb', line 13

def exist?
  File.exist?(@path)
end

#persistObject



27
28
29
30
31
32
33
# File 'lib/checklister/configuration_file.rb', line 27

def persist
  File.open(@path, "w") do |f|
    namespaced_services = { services: @services }
    f.write namespaced_services.to_yaml
  end
  reload!
end

#reload!Object



35
36
37
38
# File 'lib/checklister/configuration_file.rb', line 35

def reload!
  @file = load_file
  @services = load_services
end

#remove_service(endpoint) ⇒ Object



23
24
25
# File 'lib/checklister/configuration_file.rb', line 23

def remove_service(endpoint)
  @services.delete_if { |h| h[:endpoint].to_s == endpoint.to_s }
end