Sha256: e90bd4f16abb226dec7573efcc81aef555f250eb4d0c7467a556231fdedcf6b2

Contents?: true

Size: 1.29 KB

Versions: 18

Compression:

Stored size: 1.29 KB

Contents

# Some methods in this file are taken from ActiveSupport
# and are copyright (c) 2005-2010 David Heinemeier Hansson.
# They are loaded only if ActiveSupport is not present.

module CSL
  module Extensions

    # ActiveSupport Fallback
    module SymbolizeKeys
      def symbolize_keys
        inject({}) do |options, (key, value)|
          options[(key.to_sym rescue key) || key] = value
          options
        end
      end

      def symbolize_keys!
        replace(symbolize_keys)
      end

    end

    # ActiveSupport Fallback
    module StringifyKeys
      def stringify_keys
        inject({}) do |options, (key, value)|
          options[(key.to_s rescue key) || key] = value
          options
        end
      end

      def stringify_keys!
        replace(symbolize_keys)
      end
    end

    module Nesting
      def nesting
        name.split(/::/).inject([]) { |ns, n| ns << (ns[-1] || Object).const_get(n) }
      end
    end

    module Blank
      def blank?
        nil? || respond_to?(:empty?) && empty?
      end
    end
  end
end

class Hash
  include CSL::Extensions::SymbolizeKeys unless method_defined?(:symbolize_keys)
  include CSL::Extensions::StringifyKeys unless method_defined?(:stringify_keys)
end

class Object
  include CSL::Extensions::Blank unless method_defined?(:blank?)
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
csl-2.0.0 lib/csl/extensions.rb
csl-1.6.0 lib/csl/extensions.rb
csl-1.5.2 lib/csl/extensions.rb
csl-1.5.1 lib/csl/extensions.rb
csl-1.5.0 lib/csl/extensions.rb
csl-1.4.5 lib/csl/extensions.rb
csl-1.4.4 lib/csl/extensions.rb
csl-1.4.3 lib/csl/extensions.rb
csl-1.4.2 lib/csl/extensions.rb
csl-1.4.1 lib/csl/extensions.rb
csl-1.4.0 lib/csl/extensions.rb
csl-1.3.2 lib/csl/extensions.rb
csl-1.3.1 lib/csl/extensions.rb
csl-1.3.0 lib/csl/extensions.rb
csl-1.2.3 lib/csl/extensions.rb
csl-1.2.2 lib/csl/extensions.rb
csl-1.2.1 lib/csl/extensions.rb
csl-1.2.0 lib/csl/extensions.rb