Class: Eye::Config
- Inherits:
-
Object
- Object
- Eye::Config
- Defined in:
- lib/eye/config.rb
Instance Attribute Summary collapse
-
#applications ⇒ Object
readonly
Returns the value of attribute applications.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
- #application_names ⇒ Object
- #delete_app(name) ⇒ Object
- #delete_group(name) ⇒ Object
- #delete_process(name) ⇒ Object
-
#initialize(settings = {}, applications = {}) ⇒ Config
constructor
A new instance of Config.
- #merge(other_config) ⇒ Object
- #merge!(other_config) ⇒ Object
- #processes ⇒ Object
- #to_h ⇒ Object
-
#validate! ⇒ Object
raise an error if config wrong.
Constructor Details
#initialize(settings = {}, applications = {}) ⇒ Config
Returns a new instance of Config.
5 6 7 8 |
# File 'lib/eye/config.rb', line 5 def initialize(settings = {}, applications = {}) @settings = settings @applications = applications end |
Instance Attribute Details
#applications ⇒ Object (readonly)
Returns the value of attribute applications.
3 4 5 |
# File 'lib/eye/config.rb', line 3 def applications @applications end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
3 4 5 |
# File 'lib/eye/config.rb', line 3 def settings @settings end |
Instance Method Details
#application_names ⇒ Object
66 67 68 |
# File 'lib/eye/config.rb', line 66 def application_names applications.keys end |
#delete_app(name) ⇒ Object
70 71 72 |
# File 'lib/eye/config.rb', line 70 def delete_app(name) applications.delete(name) end |
#delete_group(name) ⇒ Object
74 75 76 77 78 |
# File 'lib/eye/config.rb', line 74 def delete_group(name) applications.each do |app_name, app_cfg| app_cfg[:groups].delete(name) end end |
#delete_process(name) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/eye/config.rb', line 80 def delete_process(name) applications.each do |app_name, app_cfg| app_cfg[:groups].each do |gr_name, gr_cfg| gr_cfg[:processes].delete(name) end end end |
#merge(other_config) ⇒ Object
10 11 12 |
# File 'lib/eye/config.rb', line 10 def merge(other_config) Eye::Config.new(@settings.merge(other_config.settings), @applications.merge(other_config.applications)) end |
#merge!(other_config) ⇒ Object
14 15 16 17 |
# File 'lib/eye/config.rb', line 14 def merge!(other_config) @settings.merge!(other_config.settings) @applications.merge!(other_config.applications) end |
#processes ⇒ Object
62 63 64 |
# File 'lib/eye/config.rb', line 62 def processes applications.values.map{|e| (e[:groups] || {}).values.map{|c| (c[:processes] || {}).values} }.flatten end |
#to_h ⇒ Object
19 20 21 |
# File 'lib/eye/config.rb', line 19 def to_h {:settings => @settings, :applications => @applications} end |
#validate! ⇒ Object
raise an error if config wrong
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/eye/config.rb', line 24 def validate! all_processes = processes # Check blank pid_files no_pid_file = all_processes.select{|c| c[:pid_file].blank? } if no_pid_file.present? raise Eye::Dsl::Error, "blank pid_file for: #{no_pid_file.map{|c| c[:name]} * ', '}" end # Check dublicates of the full pid_file dubl_pids = all_processes.each_with_object(Hash.new(0)) do |o, h| ex_pid_file = Eye::System.normalized_file(o[:pid_file], o[:working_dir]) h[ex_pid_file] += 1 end dubl_pids = dubl_pids.select{|k,v| v>1} if dubl_pids.present? raise Eye::Dsl::Error, "dublicate pid_files: #{dubl_pids.inspect}" end # Check dublicates of the full_name dubl_names = all_processes.each_with_object(Hash.new(0)) do |o, h| full_name = "#{o[:application]}:#{o[:group]}:#{o[:name]}" h[full_name] += 1 end dubl_names = dubl_names.select{|k,v| v>1} if dubl_names.present? raise Eye::Dsl::Error, "dublicate names: #{dubl_names.inspect}" end # validate processes with their own validate all_processes.each do |process_cfg| Eye::Process.validate process_cfg end end |