Class: Mutx::Support::Configuration
- Inherits:
-
Object
- Object
- Mutx::Support::Configuration
- Defined in:
- lib/mutx/support/configuration.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Class Method Summary collapse
- .attach_report? ⇒ Boolean
- .auto_execution_id ⇒ Object
- .company ⇒ Object
- .config_file_exists? ⇒ Boolean
- .configuration_values ⇒ Object
- .db_connection_data ⇒ Object
-
.db_host ⇒ Object
def self.db_type @@input[‘type’] || ‘mongodb’ end.
- .db_pass ⇒ Object
- .db_port ⇒ Object
- .db_username ⇒ Object
- .default_input ⇒ Object
- .email_configured? ⇒ Boolean
- .execution_check_time ⇒ Object
-
.execution_time_to_live ⇒ Object
After this period of time (in seconds) Mutx will kill process execution automatically.
- .formatted_datetime ⇒ Object
- .get ⇒ Object
- .headless? ⇒ Boolean
- .headless_configuration ⇒ Object
- .hostname ⇒ Object
-
.inactivity_timeout ⇒ Object
After this period of time (in seconds) Mutx will show a stop execution button on result report and results list.
- .is_a_number?(value) ⇒ Boolean
- .is_boolean?(object) ⇒ Boolean
- .is_email_correct? ⇒ Boolean
- .kill_after_time? ⇒ Boolean
- .mail_from ⇒ Object
- .max_execs ⇒ Object
- .maximum_execs_per_task ⇒ Object
- .notification? ⇒ Boolean
- .notification_password ⇒ Object
- .notification_username ⇒ Object
- .notifications_to ⇒ Object
- .path ⇒ Object
- .path_template ⇒ Object
-
.port ⇒ Fixnum
Returns the configured port.
- .pretty_configuration_values ⇒ Object
- .project_name ⇒ Object
- .project_name=(value) ⇒ Object
- .project_url ⇒ Object
- .proxys ⇒ Object
- .recipients ⇒ Object
- .refresh? ⇒ Boolean
- .refresh_time ⇒ Object
- .reset_execution_availability? ⇒ Boolean
-
.resolution ⇒ String
Returns value for screen resolution.
- .show_configuration_values ⇒ Object
-
.size ⇒ String
Returns value for screen size.
- .smtp_address ⇒ Object
- .smtp_address? ⇒ Boolean
- .smtp_autentication ⇒ Object
- .smtp_domain ⇒ Object
- .smtp_domain? ⇒ Boolean
- .smtp_enable_start_tls_auto ⇒ Object
- .smtp_password ⇒ Object
- .smtp_password? ⇒ Boolean
- .smtp_port ⇒ Object
- .smtp_port? ⇒ Boolean
- .smtp_user ⇒ Object
- .smtp_user? ⇒ Boolean
- .telegram_token ⇒ Object
- .use_git? ⇒ Boolean
- .validate_use_git_configuration_value ⇒ Object
- .value?(value) ⇒ Boolean
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
6 7 8 |
# File 'lib/mutx/support/configuration.rb', line 6 def input @input end |
Class Method Details
.attach_report? ⇒ Boolean
224 225 226 227 |
# File 'lib/mutx/support/configuration.rb', line 224 def self.attach_report? value = @@input['notification']['attach_report'] self.is_boolean? value ? value : false end |
.auto_execution_id ⇒ Object
280 281 282 283 284 285 286 287 288 |
# File 'lib/mutx/support/configuration.rb', line 280 def self.auto_execution_id if @@input.has_key? "execution_tag_placeholder" if @@input["execution_tag_placeholder"]["datetime"] Time.now.strftime(@@input["execution_tag_placeholder"]["format"]) else @@input["execution_tag_placeholder"]["default"] end end end |
.company ⇒ Object
254 255 256 257 258 259 260 |
# File 'lib/mutx/support/configuration.rb', line 254 def self.company if @@input['footer_text'].is_a? String @@input['footer_text'] else "" end end |
.config_file_exists? ⇒ Boolean
68 69 70 |
# File 'lib/mutx/support/configuration.rb', line 68 def self.config_file_exists? File.exist? self.path end |
.configuration_values ⇒ Object
316 317 318 319 320 321 322 323 |
# File 'lib/mutx/support/configuration.rb', line 316 def self.configuration_values output = Marshal.load(Marshal.dump(@@input)) output["database"]["username"] = "******" output["database"]["password"] = "******" output["notification"]["username"] = "******" output["notification"]["password"] = "******" output end |
.db_connection_data ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/mutx/support/configuration.rb', line 101 def self.db_connection_data { :host => self.db_host, :port => self.db_port, :username => self.db_username, :pass => self.db_pass } end |
.db_host ⇒ Object
def self.db_type
@@input["database"]['type'] || 'mongodb'
end
85 86 87 |
# File 'lib/mutx/support/configuration.rb', line 85 def self.db_host @@input["database"]['host'] || 'localhost' end |
.db_pass ⇒ Object
97 98 99 |
# File 'lib/mutx/support/configuration.rb', line 97 def self.db_pass @@input["database"]["password"] || nil end |
.db_port ⇒ Object
89 90 91 |
# File 'lib/mutx/support/configuration.rb', line 89 def self.db_port @@input["database"]['port'] || 27017 end |
.db_username ⇒ Object
93 94 95 |
# File 'lib/mutx/support/configuration.rb', line 93 def self.db_username @@input["database"]["username"] || nil end |
.default_input ⇒ Object
24 25 26 27 |
# File 'lib/mutx/support/configuration.rb', line 24 def self.default_input Mutx::Support::Log.debug "#{self.class}Setting default input (from template)" if Mutx::Support::Log JSON.parse(IO.read(self.path_template)) end |
.email_configured? ⇒ Boolean
110 111 112 113 114 115 116 117 |
# File 'lib/mutx/support/configuration.rb', line 110 def self.email_configured? return true if self.smtp_address? and self.smtp_port? and self.smtp_domain? and self.smtp_user? and self.smtp_password.nil? true end |
.execution_check_time ⇒ Object
195 196 197 |
# File 'lib/mutx/support/configuration.rb', line 195 def self.execution_check_time self.is_a_number?(@@input["execution_check_time"]) ? @@input["execution_check_time"] : 5 end |
.execution_time_to_live ⇒ Object
After this period of time (in seconds) Mutx will kill process execution automatically
268 269 270 |
# File 'lib/mutx/support/configuration.rb', line 268 def self.execution_time_to_live self.is_a_number?(@@input["kill_inactive_executions_after"]) ? @@input["kill_inactive_executions_after"] : 180 end |
.formatted_datetime ⇒ Object
250 251 252 |
# File 'lib/mutx/support/configuration.rb', line 250 def self.formatted_datetime @@input['datetime_format'] || "%d/%m/%Y %H:%M:%S" end |
.get ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/mutx/support/configuration.rb', line 8 def self.get Mutx::Support::Log.start Mutx::Support::Log.debug "Creating configuration object" if Mutx::Support::Log if self.config_file_exists? @@input = Mutx::Support::Update.mutx_conf elsif !Dir.pwd.to_s.include? "garba-automation"#not show put if you are in other dir else @@input = self.default_input puts "Error loading mutx configuration file. Using default values".colorize(:red) end end |
.headless? ⇒ Boolean
290 291 292 |
# File 'lib/mutx/support/configuration.rb', line 290 def self.headless? self.is_boolean? @@input["headless"]["active"] end |
.headless_configuration ⇒ Object
294 295 296 |
# File 'lib/mutx/support/configuration.rb', line 294 def self.headless_configuration "xvfb-run --auto-servernum --server-args='-screen 0, #{self.resolution}x#{self.size}' " end |
.hostname ⇒ Object
50 51 52 |
# File 'lib/mutx/support/configuration.rb', line 50 def self.hostname @@input['app_name'] || 'localhost' end |
.inactivity_timeout ⇒ Object
After this period of time (in seconds) Mutx will show a stop execution button on result report and results list
263 264 265 |
# File 'lib/mutx/support/configuration.rb', line 263 def self.inactivity_timeout self.is_a_number?(@@input["inactivity_timeout"]) ? @@input["inactivity_timeout"] : 60 end |
.is_a_number?(value) ⇒ Boolean
229 230 231 |
# File 'lib/mutx/support/configuration.rb', line 229 def self.is_a_number? value !"#{value}".scan(/\d+/).empty? end |
.is_boolean?(object) ⇒ Boolean
233 234 235 236 237 238 239 |
# File 'lib/mutx/support/configuration.rb', line 233 def self.is_boolean? object if [TrueClass, FalseClass].include? object.class object.class else false end end |
.is_email_correct? ⇒ Boolean
216 217 218 219 220 221 222 |
# File 'lib/mutx/support/configuration.rb', line 216 def self.is_email_correct? begin !@@input['notification']['recipients'].scan(/\w+@[a-zA-Z]+?\.[a-zA-Z]{2,6}/).empty? rescue false end end |
.kill_after_time? ⇒ Boolean
272 273 274 |
# File 'lib/mutx/support/configuration.rb', line 272 def self.kill_after_time? self.execution_time_to_live > 0 end |
.mail_from ⇒ Object
58 59 60 |
# File 'lib/mutx/support/configuration.rb', line 58 def self.mail_from @@input['mail_from'] || "Mutx <[email protected]>" end |
.max_execs ⇒ Object
203 204 205 |
# File 'lib/mutx/support/configuration.rb', line 203 def self.max_execs self.maximum_execs_per_task end |
.maximum_execs_per_task ⇒ Object
199 200 201 |
# File 'lib/mutx/support/configuration.rb', line 199 def self.maximum_execs_per_task self.is_a_number?(@@input["max_execs_per_task"]) ? @@input["max_execs_per_task"] : 3 end |
.notification? ⇒ Boolean
175 176 177 |
# File 'lib/mutx/support/configuration.rb', line 175 def self.notification? self.notification_username and self.notification_password and self.use_gmail? end |
.notification_password ⇒ Object
191 192 193 |
# File 'lib/mutx/support/configuration.rb', line 191 def self.notification_password @@input['notification']['password'] end |
.notification_username ⇒ Object
187 188 189 |
# File 'lib/mutx/support/configuration.rb', line 187 def self.notification_username @@input['notification']['username'] end |
.notifications_to ⇒ Object
179 180 181 |
# File 'lib/mutx/support/configuration.rb', line 179 def self.notifications_to self.recipients end |
.path ⇒ Object
29 30 31 |
# File 'lib/mutx/support/configuration.rb', line 29 def self.path "#{Dir.pwd}/mutx/conf/mutx.conf" end |
.path_template ⇒ Object
33 34 35 |
# File 'lib/mutx/support/configuration.rb', line 33 def self.path_template File.("../../../", __FILE__) + "/generators/templates/mutx.conf.tt" end |
.port ⇒ Fixnum
Returns the configured port. If it isn’t a number, port 8080 will be returned by defualt
64 65 66 |
# File 'lib/mutx/support/configuration.rb', line 64 def self.port self.is_a_number?(@@input["app_port"]) ? @@input["app_port"] : 8080 end |
.pretty_configuration_values ⇒ Object
311 312 313 314 |
# File 'lib/mutx/support/configuration.rb', line 311 def self.pretty_configuration_values output = self.configuration_values JSON.pretty_generate(output).gsub("\"******\"", "******") end |
.project_name ⇒ Object
37 38 39 40 |
# File 'lib/mutx/support/configuration.rb', line 37 def self.project_name Mutx::Support::Log.debug "Project name: #{Dir.pwd.split("/").last}" "#{Dir.pwd.split("/").last}" end |
.project_name=(value) ⇒ Object
42 43 44 |
# File 'lib/mutx/support/configuration.rb', line 42 def self.project_name= value @@project_name = value end |
.project_url ⇒ Object
76 77 78 79 |
# File 'lib/mutx/support/configuration.rb', line 76 def self.project_url url = @@input['project_url'] == "http://your.project.url" ? "" : @@input['project_url'] url.empty? ? Mutx::Support::Git.remote_url : url end |
.proxys ⇒ Object
54 55 56 |
# File 'lib/mutx/support/configuration.rb', line 54 def self.proxys @@input['proxys'] end |
.recipients ⇒ Object
183 184 185 |
# File 'lib/mutx/support/configuration.rb', line 183 def self.recipients self.is_email_correct? ? @@input['notification']['recipients'] : '' end |
.refresh? ⇒ Boolean
212 213 214 |
# File 'lib/mutx/support/configuration.rb', line 212 def self.refresh? !self.refresh_time.zero? end |
.refresh_time ⇒ Object
208 209 210 |
# File 'lib/mutx/support/configuration.rb', line 208 def self.refresh_time self.is_a_number?(@@input['refresh_time']) ? @@input['refresh_time'] : 0 end |
.reset_execution_availability? ⇒ Boolean
276 277 278 |
# File 'lib/mutx/support/configuration.rb', line 276 def self.reset_execution_availability? inactivity_timeout > 0 end |
.resolution ⇒ String
Returns value for screen resolution
300 301 302 |
# File 'lib/mutx/support/configuration.rb', line 300 def self.resolution @@input["headless"]["resolution"] end |
.show_configuration_values ⇒ Object
325 326 327 328 329 330 331 |
# File 'lib/mutx/support/configuration.rb', line 325 def self.show_configuration_values puts " * Configuration values loaded at starting Mutx: #{self.pretty_configuration_values}" end |
.size ⇒ String
Returns value for screen size. This is used by xvfb configuration
307 308 309 |
# File 'lib/mutx/support/configuration.rb', line 307 def self.size @@input["headless"]["size"] end |
.smtp_address ⇒ Object
119 120 121 |
# File 'lib/mutx/support/configuration.rb', line 119 def self.smtp_address @@input['notification']['smtp_address'] end |
.smtp_address? ⇒ Boolean
123 124 125 |
# File 'lib/mutx/support/configuration.rb', line 123 def self.smtp_address? self.value?(self.smtp_address) end |
.smtp_autentication ⇒ Object
163 164 165 |
# File 'lib/mutx/support/configuration.rb', line 163 def self.smtp_autentication @@input['notification']['smtp_autentication'] end |
.smtp_domain ⇒ Object
135 136 137 |
# File 'lib/mutx/support/configuration.rb', line 135 def self.smtp_domain @@input['notification']['smtp_domain'] end |
.smtp_domain? ⇒ Boolean
139 140 141 |
# File 'lib/mutx/support/configuration.rb', line 139 def self.smtp_domain? self.value?(self.smtp_domain) end |
.smtp_enable_start_tls_auto ⇒ Object
167 168 169 |
# File 'lib/mutx/support/configuration.rb', line 167 def self.smtp_enable_start_tls_auto @@input['notification']['smtp_enable_start_tls_auto'] end |
.smtp_password ⇒ Object
151 152 153 |
# File 'lib/mutx/support/configuration.rb', line 151 def self.smtp_password @@input['notification']['smtp_password'] end |
.smtp_password? ⇒ Boolean
155 156 157 |
# File 'lib/mutx/support/configuration.rb', line 155 def self.smtp_password? self.value?(self.smtp_password) end |
.smtp_port ⇒ Object
127 128 129 |
# File 'lib/mutx/support/configuration.rb', line 127 def self.smtp_port @@input['notification']['smtp_port'] end |
.smtp_port? ⇒ Boolean
131 132 133 |
# File 'lib/mutx/support/configuration.rb', line 131 def self.smtp_port? self.value?(self.smtp_port) end |
.smtp_user ⇒ Object
143 144 145 |
# File 'lib/mutx/support/configuration.rb', line 143 def self.smtp_user @@input['notification']['smtp_user'] end |
.smtp_user? ⇒ Boolean
147 148 149 |
# File 'lib/mutx/support/configuration.rb', line 147 def self.smtp_user? self.value?(self.smtp_user) end |
.telegram_token ⇒ Object
171 172 173 |
# File 'lib/mutx/support/configuration.rb', line 171 def self.telegram_token @@input['notification']['telegram_token'] end |
.use_git? ⇒ Boolean
241 242 243 244 |
# File 'lib/mutx/support/configuration.rb', line 241 def self.use_git? self.validate_use_git_configuration_value @@input['use_git'] end |
.validate_use_git_configuration_value ⇒ Object
246 247 248 |
# File 'lib/mutx/support/configuration.rb', line 246 def self.validate_use_git_configuration_value raise "You have to set use_git config with true or false. Has #{@@input['use_git']}" unless self.is_boolean? @@input['use_git'] end |
.value?(value) ⇒ Boolean
159 160 161 |
# File 'lib/mutx/support/configuration.rb', line 159 def self.value? value ![nil,""].include? value end |