Class: Kaya::Support::Configuration
- Inherits:
-
Object
- Object
- Kaya::Support::Configuration
- Defined in:
- lib/kaya/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
- .db_pass ⇒ Object
- .db_port ⇒ Object
- .db_type ⇒ Object
- .db_username ⇒ Object
- .default_input ⇒ Object
-
.execution_time_to_live ⇒ Object
After this period of time (in seconds) Kaya will kill process execution automatically.
- .formatted_datetime ⇒ Object
- .get ⇒ Object
- .headless? ⇒ Boolean
- .hostname ⇒ Object
-
.inactivity_timeout ⇒ Object
After this period of time (in seconds) Kaya 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
- .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.
5 6 7 |
# File 'lib/kaya/support/configuration.rb', line 5 def input @input end |
Class Method Details
.attach_report? ⇒ Boolean
141 142 143 144 |
# File 'lib/kaya/support/configuration.rb', line 141 def self.attach_report? value = @@input['NOTIFICATION']['ATTACH_REPORT'] self.is_boolean? value ? value : false end |
.auto_execution_id ⇒ Object
195 196 197 198 199 200 201 202 203 |
# File 'lib/kaya/support/configuration.rb', line 195 def self.auto_execution_id if @@input.has_key? "AUTO_EXECUTION_ID" if @@input["AUTO_EXECUTION_ID"]["datetime"] Time.now.strftime(@@input["AUTO_EXECUTION_ID"]["format"]) else @@input["AUTO_EXECUTION_ID"]["default"] end end end |
.company ⇒ Object
169 170 171 172 173 174 175 |
# File 'lib/kaya/support/configuration.rb', line 169 def self.company if @@input['FOOTER'].is_a? String @@input['FOOTER'] else "" end end |
.config_file_exists? ⇒ Boolean
59 60 61 |
# File 'lib/kaya/support/configuration.rb', line 59 def self.config_file_exists? File.exist? self.path end |
.configuration_values ⇒ Object
235 236 237 238 239 240 241 242 |
# File 'lib/kaya/support/configuration.rb', line 235 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/kaya/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
76 77 78 |
# File 'lib/kaya/support/configuration.rb', line 76 def self.db_host @@input["DATABASE"]['HOST'] || 'localhost' end |
.db_pass ⇒ Object
88 89 90 |
# File 'lib/kaya/support/configuration.rb', line 88 def self.db_pass @@input["DATABASE"]["PASSWORD"] || nil end |
.db_port ⇒ Object
80 81 82 |
# File 'lib/kaya/support/configuration.rb', line 80 def self.db_port @@input["DATABASE"]['PORT'] || 27017 end |
.db_type ⇒ Object
72 73 74 |
# File 'lib/kaya/support/configuration.rb', line 72 def self.db_type @@input["DATABASE"]['TYPE'] || 'mongodb' end |
.db_username ⇒ Object
84 85 86 |
# File 'lib/kaya/support/configuration.rb', line 84 def self.db_username @@input["DATABASE"]["USERNAME"] || nil end |
.default_input ⇒ Object
23 24 25 26 |
# File 'lib/kaya/support/configuration.rb', line 23 def self.default_input $K_LOG.debug "#{self.class}Setting default input (from template)" if $K_LOG JSON.parse(IO.read(self.path_template)) end |
.execution_time_to_live ⇒ Object
After this period of time (in seconds) Kaya will kill process execution automatically
183 184 185 |
# File 'lib/kaya/support/configuration.rb', line 183 def self.execution_time_to_live self.is_a_number?(@@input["KILL_INACTIVE_EXECUTIONS_AFTER"]) ? @@input["KILL_INACTIVE_EXECUTIONS_AFTER"] : 3600 end |
.formatted_datetime ⇒ Object
165 166 167 |
# File 'lib/kaya/support/configuration.rb', line 165 def self.formatted_datetime @@input['FORMAT_DATETIME'] || "%d/%m/%Y %H:%M:%S" end |
.get ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/kaya/support/configuration.rb', line 7 def self.get $K_LOG.debug "Creating configuration object" if $K_LOG if File.exist?("#{Dir.pwd}/kaya_conf") puts "Moving kaya_conf from #{Dir.pwd}/kaya_conf to #{self.path}".colorize(:green) FileUtils.mv("#{Dir.pwd}/kaya_conf", self.path) puts "Done.".colorize(:green) end if self.config_file_exists? @@input = Kaya::Support::Update.kaya_conf else @@input = self.default_input puts "Error loading kaya_conf. Using default values".colorize(:red) end end |
.headless? ⇒ Boolean
205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/kaya/support/configuration.rb', line 205 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/kaya/support/configuration.rb', line 49 def self.hostname @@input['HOSTNAME'] || 'localhost' end |
.inactivity_timeout ⇒ Object
After this period of time (in seconds) Kaya will show a stop execution button on result report and results list
178 179 180 |
# File 'lib/kaya/support/configuration.rb', line 178 def self.inactivity_timeout self.is_a_number?(@@input["INACTIVITY_TIMEOUT"]) ? @@input["INACTIVITY_TIMEOUT"] : 60 end |
.is_a_number?(value) ⇒ Boolean
148 149 150 |
# File 'lib/kaya/support/configuration.rb', line 148 def self.is_a_number? value !"#{value}".scan(/\d+/).empty? end |
.is_boolean?(object) ⇒ Boolean
152 153 154 |
# File 'lib/kaya/support/configuration.rb', line 152 def self.is_boolean? object [TrueClass, FalseClass].include? object.class end |
.is_email_correct? ⇒ Boolean
133 134 135 136 137 138 139 |
# File 'lib/kaya/support/configuration.rb', line 133 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
187 188 189 |
# File 'lib/kaya/support/configuration.rb', line 187 def self.kill_after_time? self.execution_time_to_live > 0 end |
.notification? ⇒ Boolean
101 102 103 |
# File 'lib/kaya/support/configuration.rb', line 101 def self.notification? self.notification_username and self.notification_password and self.use_gmail? end |
.notification_password ⇒ Object
117 118 119 |
# File 'lib/kaya/support/configuration.rb', line 117 def self.notification_password @@input['NOTIFICATION']['PASSWORD'] end |
.notification_username ⇒ Object
113 114 115 |
# File 'lib/kaya/support/configuration.rb', line 113 def self.notification_username @@input['NOTIFICATION']['USERNAME'] end |
.notifications_to ⇒ Object
105 106 107 |
# File 'lib/kaya/support/configuration.rb', line 105 def self.notifications_to self.recipients end |
.path ⇒ Object
28 29 30 |
# File 'lib/kaya/support/configuration.rb', line 28 def self.path "#{Dir.pwd}/kaya/kaya_conf" end |
.path_template ⇒ Object
32 33 34 |
# File 'lib/kaya/support/configuration.rb', line 32 def self.path_template File.("../../", __FILE__) + "/generators/templates/kaya_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/kaya/support/configuration.rb', line 55 def self.port self.is_a_number?(@@input["APP_PORT"]) ? @@input["APP_PORT"] : 8080 end |
.pretty_configuration_values ⇒ Object
230 231 232 233 |
# File 'lib/kaya/support/configuration.rb', line 230 def self.pretty_configuration_values output = self.configuration_values JSON.pretty_generate(output).gsub("\"******\"", "******") end |
.project_name ⇒ Object
36 37 38 39 |
# File 'lib/kaya/support/configuration.rb', line 36 def self.project_name $K_LOG.debug "Project name: #{Dir.pwd.split("/").last}" "#{Dir.pwd.split("/").last}" end |
.project_name=(value) ⇒ Object
41 42 43 |
# File 'lib/kaya/support/configuration.rb', line 41 def self.project_name= value @@project_name = value end |
.project_url ⇒ Object
67 68 69 70 |
# File 'lib/kaya/support/configuration.rb', line 67 def self.project_url url = @@input['PROJECT_URL'] == "http://your.project.url" ? "" : @@input['PROJECT_URL'] url.empty? ? Kaya::Support::Git.remote_url : url end |
.recipients ⇒ Object
109 110 111 |
# File 'lib/kaya/support/configuration.rb', line 109 def self.recipients self.is_email_correct? ? @@input['NOTIFICATION']['RECIPIENTS'] : '' end |
.refresh? ⇒ Boolean
125 126 127 |
# File 'lib/kaya/support/configuration.rb', line 125 def self.refresh? !self.refresh_time.zero? end |
.refresh_time ⇒ Object
121 122 123 |
# File 'lib/kaya/support/configuration.rb', line 121 def self.refresh_time self.is_a_number?(@@input['REFRESH_TIME']) ? @@input['REFRESH_TIME'] : 0 end |
.reset_execution_availability? ⇒ Boolean
191 192 193 |
# File 'lib/kaya/support/configuration.rb', line 191 def self.reset_execution_availability? inactivity_timeout > 0 end |
.resolution ⇒ String
Returns value for screen resolution
219 220 221 |
# File 'lib/kaya/support/configuration.rb', line 219 def self.resolution @@input["HEADLESS"]["resolution"] end |
.show_configuration_values ⇒ Object
244 245 246 247 248 249 250 |
# File 'lib/kaya/support/configuration.rb', line 244 def self.show_configuration_values puts " * Configuration values loaded at starting Kaya: #{self.pretty_configuration_values}" end |
.size ⇒ String
Returns value for screen size. This is used by xvfb configuration
226 227 228 |
# File 'lib/kaya/support/configuration.rb', line 226 def self.size @@input["HEADLESS"]["size"] end |
.use_git? ⇒ Boolean
156 157 158 159 |
# File 'lib/kaya/support/configuration.rb', line 156 def self.use_git? self.validate_use_git_configuration_value @@input['USE_GIT'] end |
.use_gmail? ⇒ Boolean
129 130 131 |
# File 'lib/kaya/support/configuration.rb', line 129 def self.use_gmail? self.is_boolean? @@input['USE_GMAIL'] ? @@input['USE_GMAIL'] : false end |
.validate_use_git_configuration_value ⇒ Object
161 162 163 |
# File 'lib/kaya/support/configuration.rb', line 161 def self.validate_use_git_configuration_value raise "You have to set USE_GIT config with true or false. Has #{@@input['USE_GIT']}" unless is_boolean? @@input['USE_GIT'] end |