Sha256: e82403f499b94da1a0771d82ae006542c9fd146739723eecdb59e5a679df5e04

Contents?: true

Size: 1.37 KB

Versions: 7

Compression:

Stored size: 1.37 KB

Contents

begin
  require 'active_support/core_ext/hash/keys'
  require 'active_support/core_ext/hash/deep_merge'
rescue LoadError
  class Hash
    def slice(*keys)
      keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
      keys.each_with_object(self.class.new) { |k, hash| hash[k] = self[k] if key?(k) }
    end unless {}.respond_to?(:slice)

    def slice!(*keys)
      keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
      omit = slice(*self.keys - keys)
      hash = slice(*keys)
      hash.default      = default
      hash.default_proc = default_proc if default_proc
      replace(hash)
      omit
    end unless {}.respond_to?(:slice!)
  end
end

class Array
  def extract_options!
    if last.is_a?(Hash) && last.instance_of?(Hash)
      pop
    else
      {}
    end
  end unless [].respond_to?(:extract_options!)
end

class String
  def classify
    camelize(sub(/.*\./, ''))
  end unless ''.respond_to?(:classify)

  def camelize(uppercase_first_letter = true)
    string = self
    if uppercase_first_letter
      string = string.sub(/^[a-z\d]*/) { $&.capitalize }
    else
      string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
    end
    string.gsub!(%r{(?:_|(\/))([a-z\d]*)}i) do
      "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}"
    end
    string.gsub!(%r{/}, '::')
    string
  end unless ''.respond_to?(:camelize)
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-4.0.13 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-4.0.12 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-4.0.11 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-4.0.10 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-4.0.9 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-4.0.8 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-4.0.7 lib/sidekiq_unique_jobs/core_ext.rb