Sha256: 0c161e60e0b310fc737a87f216aa76b0fc792a511150a2fcb3b8c53c898ab0b4

Contents?: true

Size: 957 Bytes

Versions: 18

Compression:

Stored size: 957 Bytes

Contents

# encoding: utf-8

# Collection of utility methods
# @author Gernot Kogler
module XapianDb
  module Utilities

    extend self

    # Convert a string to camel case
    # @param [String] The string to camelize
    # @return [String] The camelized string
    def camelize(string)
      string.split(/[^a-z0-9]/i).map{|w| w.capitalize}.join
    end

    # Taken from Rails
    def constantize(camel_cased_word)
      names = camel_cased_word.split('::')
      names.shift if names.empty? || names.first.empty?

      constant = Object
      names.each do |name|
        constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
      end
      constant
    end

    # Taken from Rails
    def assert_valid_keys(hash, *valid_keys)
      unknown_keys = hash.keys - [valid_keys].flatten
      raise(ArgumentError, "Unsupported option(s) detected: #{unknown_keys.join(", ")}") unless unknown_keys.empty?
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
xapian_db-1.3.5 lib/xapian_db/utilities.rb
xapian_db-1.3.4 lib/xapian_db/utilities.rb
xapian_db-1.3.3.1 lib/xapian_db/utilities.rb
xapian_db-1.3.3 lib/xapian_db/utilities.rb
xapian_db-1.3.2 lib/xapian_db/utilities.rb
xapian_db-1.3.1 lib/xapian_db/utilities.rb
xapian_db-1.3 lib/xapian_db/utilities.rb
xapian_db-1.2.5.1 lib/xapian_db/utilities.rb
xapian_db-1.2.5 lib/xapian_db/utilities.rb
xapian_db-1.2.4.7 lib/xapian_db/utilities.rb
xapian_db-1.2.4.6 lib/xapian_db/utilities.rb
xapian_db-1.2.4.5 lib/xapian_db/utilities.rb
xapian_db-1.2.4.4 lib/xapian_db/utilities.rb
xapian_db-1.2.4.3 lib/xapian_db/utilities.rb
xapian_db-1.2.4.2 lib/xapian_db/utilities.rb
xapian_db-1.2.4.1 lib/xapian_db/utilities.rb
xapian_db-1.2.4 lib/xapian_db/utilities.rb
xapian_db-1.2.3 lib/xapian_db/utilities.rb