module Arbor::Utils

Constants

INFLECTIONS

Public Instance Methods

attempt(enum) { || ... } click to toggle source
# File lib/arbor/utils.rb, line 32
def attempt(enum)
  exception = nil
  enum.each do
    begin
      return yield
    rescue => e
      exception = e
      next
    end
  end
  raise exception
end
get_resource_name(type) click to toggle source
# File lib/arbor/utils.rb, line 11
def get_resource_name(type)
  case type
  when Class
    # do reverse serialiser lookup instead
    pluralize(type.name).underscore
  else
    pluralize(type.to_s)
  end
end
left_pad(array, num) click to toggle source
# File lib/arbor/utils.rb, line 28
def left_pad(array, num)
  num.times { array.unshift(nil) }
end
parse_resource_name(type) click to toggle source
# File lib/arbor/utils.rb, line 7
def parse_resource_name(type)
  validate(get_resource_name(type), Arbor::RESOURCES)
end
validate(choice, options) click to toggle source
# File lib/arbor/utils.rb, line 21
def validate(choice, options)
  unless options.include?(choice.to_sym)
    raise ArgumentError, "#{choice} is not a valid option: #{options}"
  end
  choice
end

Private Instance Methods

pluralize(string) click to toggle source
# File lib/arbor/utils.rb, line 46
def pluralize(string)
  INFLECTIONS[string] || string.pluralize
end