Module: Maze::Helper
- Defined in:
- lib/maze/helper.rb
Overview
Miscellaneous helper functions.
Class Method Summary collapse
-
.error_exit(message) ⇒ Object
Logs the given message and exits the program with a failure status.
-
.expand_path(path) ⇒ String
Nil-safe version of File.expand_path.
-
.get_current_platform ⇒ Object
Returns the current platform all lower-case.
-
.parse_querystring(request) ⇒ Hash
Parses a request’s query string, because WEBrick doesn’t in POST requests.
-
.read_at_arg_file(argument) ⇒ Object
Helps interpret “@file” arguments.
-
.read_key_path(hash, key_path) ⇒ Any
Enables traversal of a hash using Mongo-style dot notation.
-
.to_friendly_filename(string) ⇒ Object
Returns the name of the scenario to.
-
.valid_bugsnag_integrity_header(request) ⇒ Boolean
Determines if the Bugsnag-Integrity header is valid.
Class Method Details
.error_exit(message) ⇒ Object
Logs the given message and exits the program with a failure status
110 111 112 113 114 |
# File 'lib/maze/helper.rb', line 110 def error_exit() $logger.error Bugsnag.notify() exit false end |
.expand_path(path) ⇒ String
Nil-safe version of File.expand_path
73 74 75 76 77 |
# File 'lib/maze/helper.rb', line 73 def (path) return nil unless path File. path end |
.get_current_platform ⇒ Object
Returns the current platform all lower-case.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/maze/helper.rb', line 91 def get_current_platform if Maze.mode == :browser os = 'browser' else os = case Maze.config.farm when :bs Maze.config.capabilities['platformName'] else Maze.config.os end os = os&.downcase end raise('Unable to determine the current platform') if os.nil? os end |
.parse_querystring(request) ⇒ Hash
Parses a request’s query string, because WEBrick doesn’t in POST requests
16 17 18 |
# File 'lib/maze/helper.rb', line 16 def parse_querystring(request) CGI.parse(request[:request].query_string) end |
.read_at_arg_file(argument) ⇒ Object
Helps interpret “@file” arguments. I.e. if the argument starts with an “@”, read the contents of the filename given.
81 82 83 84 85 86 87 |
# File 'lib/maze/helper.rb', line 81 def read_at_arg_file(argument) return nil if argument.nil? return argument unless argument.start_with? '@' file = argument[1..argument.size] (File.read file).strip end |
.read_key_path(hash, key_path) ⇒ Any
Enables traversal of a hash using Mongo-style dot notation.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/maze/helper.rb', line 28 def read_key_path(hash, key_path) value = hash key_path.split('.').each do |key| if key =~ /^(\d+)$/ key = key.to_i if value.length > key value = value[key] else return nil end else if value.key? key value = value[key] else return nil end end end value end |
.to_friendly_filename(string) ⇒ Object
Returns the name of the scenario to
118 119 120 |
# File 'lib/maze/helper.rb', line 118 def to_friendly_filename(string) string.gsub(/[:"& ]/, "_").gsub(/_+/, "_") end |
.valid_bugsnag_integrity_header(request) ⇒ Boolean
Determines if the Bugsnag-Integrity header is valid. Whether a missing header is deemed valid depends on @see Maze.config.enforce_bugsnag_integrity.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/maze/helper.rb', line 53 def valid_bugsnag_integrity_header(request) header = request[:request]['Bugsnag-Integrity'] return !Maze.config.enforce_bugsnag_integrity if header.nil? digests = request[:digests] if header.start_with?('sha1') computed_digest = "sha1 #{digests[:sha1]}" elsif header.start_with?('simple') computed_digest = "simple #{digests[:simple]}" else return false end header == computed_digest end |