Class: Mutx::Support::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/mutx/support/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#inputObject (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

Returns:

  • (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_idObject



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

.companyObject



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

Returns:

  • (Boolean)


59
60
61
# File 'lib/mutx/support/configuration.rb', line 59

def self.config_file_exists?
  File.exist? self.path
end

.configuration_valuesObject



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_dataObject



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_hostObject

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_passObject



88
89
90
# File 'lib/mutx/support/configuration.rb', line 88

def self.db_pass
  @@input["database"]["password"] || nil
end

.db_portObject



80
81
82
# File 'lib/mutx/support/configuration.rb', line 80

def self.db_port
  @@input["database"]['port'] || 27017
end

.db_usernameObject



84
85
86
# File 'lib/mutx/support/configuration.rb', line 84

def self.db_username
  @@input["database"]["username"] || nil
end

.default_inputObject



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_timeObject



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_liveObject

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_datetimeObject



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

.getObject



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

Returns:

  • (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

.hostnameObject



49
50
51
# File 'lib/mutx/support/configuration.rb', line 49

def self.hostname
  @@input['app_name'] || 'localhost'
end

.inactivity_timeoutObject

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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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_execsObject



109
110
111
# File 'lib/mutx/support/configuration.rb', line 109

def self.max_execs
  self.maximum_execs_per_task
end

.maximum_execs_per_taskObject



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

Returns:

  • (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_passwordObject



129
130
131
# File 'lib/mutx/support/configuration.rb', line 129

def self.notification_password
  @@input['notification']['password']
end

.notification_usernameObject



125
126
127
# File 'lib/mutx/support/configuration.rb', line 125

def self.notification_username
  @@input['notification']['username']
end

.notifications_toObject



117
118
119
# File 'lib/mutx/support/configuration.rb', line 117

def self.notifications_to
  self.recipients
end

.pathObject



28
29
30
# File 'lib/mutx/support/configuration.rb', line 28

def self.path
  "#{Dir.pwd}/mutx/conf/mutx.conf"
end

.path_templateObject



32
33
34
# File 'lib/mutx/support/configuration.rb', line 32

def self.path_template
  File.expand_path("../../../", __FILE__) + "/generators/templates/mutx.conf.tt"
end

.portFixnum

Returns the configured port. If it isn’t a number, port 8080 will be returned by defualt

Returns:

  • (Fixnum)

    port number



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_valuesObject



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_nameObject



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_urlObject



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

.recipientsObject



121
122
123
# File 'lib/mutx/support/configuration.rb', line 121

def self.recipients
  self.is_email_correct? ? @@input['notification']['recipients'] : ''
end

.refresh?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/mutx/support/configuration.rb', line 137

def self.refresh?
  !self.refresh_time.zero?
end

.refresh_timeObject



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

Returns:

  • (Boolean)


203
204
205
# File 'lib/mutx/support/configuration.rb', line 203

def self.reset_execution_availability?
  inactivity_timeout > 0
end

.resolutionString

Returns value for screen resolution

Returns:

  • (String)

    resolution like 1024x768



231
232
233
# File 'lib/mutx/support/configuration.rb', line 231

def self.resolution
  @@input["headless"]["resolution"]
end

.show_configuration_valuesObject



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

.sizeString

Returns value for screen size. This is used by xvfb configuration

Returns:

  • (String)

    value in inches



238
239
240
# File 'lib/mutx/support/configuration.rb', line 238

def self.size
  @@input["headless"]["size"]
end

.use_git?Boolean

Returns:

  • (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

Returns:

  • (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_valueObject



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