Class: JSSWebHooks::Configuration
- Inherits:
-
Object
- Object
- JSSWebHooks::Configuration
- Includes:
- Singleton
- Defined in:
- lib/jss/webhooks/configuration.rb
Overview
The configuration object
Constant Summary collapse
- DEFAULT_CONF_FILE =
The location of the default config file
Pathname.new '/etc/jsswebhooks.conf'
- CONF_KEYS =
The attribute keys we maintain, and the type they should be stored as
{ server_port: :to_i, server_engine: :to_sym, handler_dir: :to_s, handler_computer_added: :to_s, handler_computer_check_in: :to_s, handler_computer_inventory_completed: :to_s, handler_computer_policy_finished: :to_s, handler_computer_push_capability_changed: :to_s, handler_jss_shutdown: :to_s, handler_jss_startup: :to_s, handler_mobile_device_check_in: :to_s, handler_mobile_device_command_complete: :to_s, handler_mobile_device_enrolled: :to_s, handler_mobile_device_push_sent: :to_s, handler_mobile_device_unenrolled: :to_s, handler_patch_software_title_updated: :to_s, handler_push_sent: :to_s, handler_rest_api_operation: :to_s, handler_scep_challenge: :to_s, handler_smart_group_computer_membership_change: :to_s, handler_smart_group_mobile_device_membership_change: :to_s }.freeze
Instance Method Summary collapse
-
#clear_all ⇒ void
Clear all values.
-
#initialize ⇒ Configuration
constructor
Initialize!.
-
#print ⇒ void
Print out the current settings to stdout.
-
#read_global ⇒ Boolean
(Re)read the global prefs, if it exists.
-
#reload(file = DEFAULT_CONF_FILE) ⇒ Boolean
Clear the settings and reload the prefs file, or another file if provided.
-
#save(file) ⇒ void
Save the prefs into a file.
Constructor Details
#initialize ⇒ Configuration
Initialize!
82 83 84 |
# File 'lib/jss/webhooks/configuration.rb', line 82 def initialize read_global end |
Instance Method Details
#clear_all ⇒ void
This method returns an undefined value.
Clear all values
95 96 97 |
# File 'lib/jss/webhooks/configuration.rb', line 95 def clear_all CONF_KEYS.keys.each { |k| send "#{k}=".to_sym, nil } end |
#print ⇒ void
This method returns an undefined value.
Print out the current settings to stdout
168 169 170 |
# File 'lib/jss/webhooks/configuration.rb', line 168 def print CONF_KEYS.keys.sort.each { |k| puts "#{k}: #{send k}" } end |
#read_global ⇒ Boolean
(Re)read the global prefs, if it exists.
104 105 106 107 |
# File 'lib/jss/webhooks/configuration.rb', line 104 def read_global return false unless DEFAULT_CONF_FILE.file? && DEFAULT_CONF_FILE.readable? read DEFAULT_CONF_FILE end |
#reload(file = DEFAULT_CONF_FILE) ⇒ Boolean
Clear the settings and reload the prefs file, or another file if provided
116 117 118 119 120 121 |
# File 'lib/jss/webhooks/configuration.rb', line 116 def reload(file = DEFAULT_CONF_FILE) file = Pathname.new file return false unless file.file? and file.readable? clear_all read file end |
#save(file) ⇒ void
This method returns an undefined value.
Save the prefs into a file
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/jss/webhooks/configuration.rb', line 130 def save(file) path = Pathname.new(file) # file already exists? read it in and update the values. # Don't overwrite it, since the user might have comments # in there. if path.readable? data = path.read # go thru the known attributes/keys CONF_KEYS.keys.sort.each do |k| # if the key exists, update it. if data =~ /^#{k}:/ data.sub!(/^#{k}:.*$/, "#{k}: #{send k}") # if not, add it to the end unless it's nil else data += "\n#{k}: #{send k}" unless send(k).nil? end # if data =~ /^#{k}:/ end # each do |k| else # not readable, make a new file data = '' CONF_KEYS.keys.sort.each do |k| data << "#{k}: #{send k}\n" unless send(k).nil? end end # if path readable # make sure we end with a newline, the save it. data << "\n" unless data.end_with?("\n") path.jss_save data end |