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
- .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
- .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
- .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
- .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.
- .use_git? ⇒ Boolean
- .use_gmail? ⇒ Boolean
- .validate_use_git_configuration_value ⇒ Object
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
153 154 155 156 |
# File 'lib/mutx/support/configuration.rb', line 153 def self.attach_report? value = @@input['notification']['attach_report'] self.is_boolean? value ? value : false end |
.auto_execution_id ⇒ Object
207 208 209 210 211 212 213 214 215 |
# File 'lib/mutx/support/configuration.rb', line 207 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
181 182 183 184 185 186 187 |
# File 'lib/mutx/support/configuration.rb', line 181 def self.company if @@input['footer_text'].is_a? String @@input['footer_text'] else "" end end |
.config_file_exists? ⇒ Boolean
59 60 61 |
# File 'lib/mutx/support/configuration.rb', line 59 def self.config_file_exists? File.exist? self.path end |
.configuration_values ⇒ Object
247 248 249 250 251 252 253 254 |
# File 'lib/mutx/support/configuration.rb', line 247 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
92 93 94 95 96 97 98 99 |
# File 'lib/mutx/support/configuration.rb', line 92 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
76 77 78 |
# File 'lib/mutx/support/configuration.rb', line 76 def self.db_host @@input["database"]['host'] || 'localhost' end |
.db_pass ⇒ Object
88 89 90 |
# File 'lib/mutx/support/configuration.rb', line 88 def self.db_pass @@input["database"]["password"] || nil end |
.db_port ⇒ Object
80 81 82 |
# File 'lib/mutx/support/configuration.rb', line 80 def self.db_port @@input["database"]['port'] || 27017 end |
.db_username ⇒ Object
84 85 86 |
# File 'lib/mutx/support/configuration.rb', line 84 def self.db_username @@input["database"]["username"] || nil end |
.default_input ⇒ Object
23 24 25 26 |
# File 'lib/mutx/support/configuration.rb', line 23 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 |
.execution_check_time ⇒ Object
101 102 103 |
# File 'lib/mutx/support/configuration.rb', line 101 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
195 196 197 |
# File 'lib/mutx/support/configuration.rb', line 195 def self.execution_time_to_live self.is_a_number?(@@input["kill_inactive_executions_after"]) ? @@input["kill_inactive_executions_after"] : 900 end |
.formatted_datetime ⇒ Object
177 178 179 |
# File 'lib/mutx/support/configuration.rb', line 177 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 |
# 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 else @@input = self.default_input puts "Error loading mutx configuration file. Using default values".colorize(:red) end end |
.headless? ⇒ Boolean
217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/mutx/support/configuration.rb', line 217 def self.headless? if self.is_boolean? @@input["headless"]["active"] "xvfb-run --auto-servernum --server-args='-screen 0, #{self.resolution}x#{self.size}' " if @@input["headless"]["active"] end # begin # @@input["headless"]["active"] if self.is_boolean? @@input["headless"]["active"] # rescue # false # end end |
.hostname ⇒ Object
49 50 51 |
# File 'lib/mutx/support/configuration.rb', line 49 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
190 191 192 |
# File 'lib/mutx/support/configuration.rb', line 190 def self.inactivity_timeout self.is_a_number?(@@input["inactivity_timeout"]) ? @@input["inactivity_timeout"] : 60 end |
.is_a_number?(value) ⇒ Boolean
160 161 162 |
# File 'lib/mutx/support/configuration.rb', line 160 def self.is_a_number? value !"#{value}".scan(/\d+/).empty? end |
.is_boolean?(object) ⇒ Boolean
164 165 166 |
# File 'lib/mutx/support/configuration.rb', line 164 def self.is_boolean? object [TrueClass, FalseClass].include? object.class end |
.is_email_correct? ⇒ Boolean
145 146 147 148 149 150 151 |
# File 'lib/mutx/support/configuration.rb', line 145 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
199 200 201 |
# File 'lib/mutx/support/configuration.rb', line 199 def self.kill_after_time? self.execution_time_to_live > 0 end |
.max_execs ⇒ Object
109 110 111 |
# File 'lib/mutx/support/configuration.rb', line 109 def self.max_execs self.maximum_execs_per_task end |
.maximum_execs_per_task ⇒ Object
105 106 107 |
# File 'lib/mutx/support/configuration.rb', line 105 def self.maximum_execs_per_task self.is_a_number?(@@input["max_execs_per_task"]) ? @@input["max_execs_per_task"] : 3 end |
.notification? ⇒ Boolean
113 114 115 |
# File 'lib/mutx/support/configuration.rb', line 113 def self.notification? self.notification_username and self.notification_password and self.use_gmail? end |
.notification_password ⇒ Object
129 130 131 |
# File 'lib/mutx/support/configuration.rb', line 129 def self.notification_password @@input['notification']['password'] end |
.notification_username ⇒ Object
125 126 127 |
# File 'lib/mutx/support/configuration.rb', line 125 def self.notification_username @@input['notification']['username'] end |
.notifications_to ⇒ Object
117 118 119 |
# File 'lib/mutx/support/configuration.rb', line 117 def self.notifications_to self.recipients end |
.path ⇒ Object
28 29 30 |
# File 'lib/mutx/support/configuration.rb', line 28 def self.path "#{Dir.pwd}/mutx/conf/mutx.conf" end |
.path_template ⇒ Object
32 33 34 |
# File 'lib/mutx/support/configuration.rb', line 32 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
55 56 57 |
# File 'lib/mutx/support/configuration.rb', line 55 def self.port self.is_a_number?(@@input["app_port"]) ? @@input["app_port"] : 8080 end |
.pretty_configuration_values ⇒ Object
242 243 244 245 |
# File 'lib/mutx/support/configuration.rb', line 242 def self.pretty_configuration_values output = self.configuration_values JSON.pretty_generate(output).gsub("\"******\"", "******") end |
.project_name ⇒ Object
36 37 38 39 |
# File 'lib/mutx/support/configuration.rb', line 36 def self.project_name Mutx::Support::Log.debug "Project name: #{Dir.pwd.split("/").last}" "#{Dir.pwd.split("/").last}" end |
.project_name=(value) ⇒ Object
41 42 43 |
# File 'lib/mutx/support/configuration.rb', line 41 def self.project_name= value @@project_name = value end |
.project_url ⇒ Object
67 68 69 70 |
# File 'lib/mutx/support/configuration.rb', line 67 def self.project_url url = @@input['project_url'] == "http://your.project.url" ? "" : @@input['project_url'] url.empty? ? Mutx::Support::Git.remote_url : url end |
.recipients ⇒ Object
121 122 123 |
# File 'lib/mutx/support/configuration.rb', line 121 def self.recipients self.is_email_correct? ? @@input['notification']['recipients'] : '' end |
.refresh? ⇒ Boolean
137 138 139 |
# File 'lib/mutx/support/configuration.rb', line 137 def self.refresh? !self.refresh_time.zero? end |
.refresh_time ⇒ Object
133 134 135 |
# File 'lib/mutx/support/configuration.rb', line 133 def self.refresh_time self.is_a_number?(@@input['refresh_time']) ? @@input['refresh_time'] : 0 end |
.reset_execution_availability? ⇒ Boolean
203 204 205 |
# File 'lib/mutx/support/configuration.rb', line 203 def self.reset_execution_availability? inactivity_timeout > 0 end |
.resolution ⇒ String
Returns value for screen resolution
231 232 233 |
# File 'lib/mutx/support/configuration.rb', line 231 def self.resolution @@input["headless"]["resolution"] end |
.show_configuration_values ⇒ Object
256 257 258 259 260 261 262 |
# File 'lib/mutx/support/configuration.rb', line 256 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
238 239 240 |
# File 'lib/mutx/support/configuration.rb', line 238 def self.size @@input["headless"]["size"] end |
.use_git? ⇒ Boolean
168 169 170 171 |
# File 'lib/mutx/support/configuration.rb', line 168 def self.use_git? self.validate_use_git_configuration_value @@input['use_git'] end |
.use_gmail? ⇒ Boolean
141 142 143 |
# File 'lib/mutx/support/configuration.rb', line 141 def self.use_gmail? self.is_boolean? @@input['use_gmail'] ? @@input['use_gmail'] : false end |
.validate_use_git_configuration_value ⇒ Object
173 174 175 |
# File 'lib/mutx/support/configuration.rb', line 173 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 |