module Calligraphy::Utils

Miscellaneous general convenience methods.

Constants

FALSE_VALUES
TRUE_VALUES

Public Instance Methods

extract_lock_token(if_header) click to toggle source

Extracts a lock token from an If headers.

# 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) click to toggle source

Determines if a value is falsy.

# File lib/calligraphy/utils.rb, line 15
def false?(val)
  FALSE_VALUES.include? val
end
join_paths(*paths) click to toggle source

Joins paths.

# File lib/calligraphy/utils.rb, line 20
def join_paths(*paths)
  paths.join '/'
end
lockentry_hash(scope, type) click to toggle source

Hash used in describing a supportedlock.

# File lib/calligraphy/utils.rb, line 51
def lockentry_hash(scope, type)
  { lockentry: { lockscope: scope, locktype: type } }
end
map_array_of_hashes(arr_hashes) click to toggle source

Given an array of hashes, returns an array of hash values.

# 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:) click to toggle source

Determines if object exists and if existing object is of a given type.

# 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: '/') click to toggle source

Given a path and separator, splits the path string using the separator and pops off the last element of the split array.

# File lib/calligraphy/utils.rb, line 26
def split_and_pop(path:, separator: '/')
  path.split(separator)[0..-2]
end
true?(val) click to toggle source

Determines if a value is truthy.

# File lib/calligraphy/utils.rb, line 10
def true?(val)
  TRUE_VALUES.include? val
end