Module: Calligraphy::Utils
- Included in:
- FileResource
- Defined in:
- lib/calligraphy/utils.rb
Overview
Miscellaneous general convenience methods.
Constant Summary collapse
- TRUE_VALUES =
[true, 1, '1', 't', 'T', 'true', 'TRUE'].freeze
- FALSE_VALUES =
[false, 0, '0', 'f', 'F', 'false', 'FALSE'].freeze
Instance Method Summary collapse
-
#extract_lock_token(if_header) ⇒ Object
Extracts a lock token from an If headers.
-
#false?(val) ⇒ Boolean
Determines if a value is falsy.
-
#join_paths(*paths) ⇒ Object
Joins paths.
-
#lockentry_hash(scope, type) ⇒ Object
Hash used in describing a supportedlock.
-
#map_array_of_hashes(arr_hashes) ⇒ Object
Given an array of hashes, returns an array of hash values.
-
#obj_exists_and_is_not_type?(obj:, type:) ⇒ Boolean
Determines if object exists and if existing object is of a given type.
-
#split_and_pop(path:, separator: '/') ⇒ Object
Given a path and separator, splits the path string using the separator and pops off the last element of the split array.
-
#true?(val) ⇒ Boolean
Determines if a value is truthy.
Instance Method Details
#extract_lock_token(if_header) ⇒ Object
Extracts a lock token from an If headers.
45 46 47 48 |
# File 'lib/calligraphy/utils.rb', line 45 def extract_lock_token(if_header) token = if_header.scan(Calligraphy::LOCK_TOKEN_REGEX) token.flatten.first if token.is_a? Array end |
#false?(val) ⇒ Boolean
Determines if a value is falsy.
15 16 17 |
# File 'lib/calligraphy/utils.rb', line 15 def false?(val) FALSE_VALUES.include? val end |
#join_paths(*paths) ⇒ Object
Joins paths.
20 21 22 |
# File 'lib/calligraphy/utils.rb', line 20 def join_paths(*paths) paths.join '/' end |
#lockentry_hash(scope, type) ⇒ Object
Hash used in describing a supportedlock.
51 52 53 |
# File 'lib/calligraphy/utils.rb', line 51 def lockentry_hash(scope, type) { lockentry: { lockscope: scope, locktype: type } } end |
#map_array_of_hashes(arr_hashes) ⇒ Object
Given an array of hashes, returns an array of hash values.
36 37 38 39 40 41 42 |
# File 'lib/calligraphy/utils.rb', line 36 def map_array_of_hashes(arr_hashes) [].tap do |output_array| arr_hashes.each do |hash| output_array.push hash.values end end end |
#obj_exists_and_is_not_type?(obj:, type:) ⇒ Boolean
Determines if object exists and if existing object is of a given type.
31 32 33 |
# File 'lib/calligraphy/utils.rb', line 31 def obj_exists_and_is_not_type?(obj:, type:) obj.nil? ? false : obj != type end |
#split_and_pop(path:, separator: '/') ⇒ Object
Given a path and separator, splits the path string using the separator and pops off the last element of the split array.
26 27 28 |
# File 'lib/calligraphy/utils.rb', line 26 def split_and_pop(path:, separator: '/') path.split(separator)[0..-2] end |
#true?(val) ⇒ Boolean
Determines if a value is truthy.
10 11 12 |
# File 'lib/calligraphy/utils.rb', line 10 def true?(val) TRUE_VALUES.include? val end |