Sha256: 2565ba11b7840df45643f99d94389fe6a4e48250b31a95bb9db64fd1cd63a6a3

Contents?: true

Size: 1.33 KB

Versions: 21

Compression:

Stored size: 1.33 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 Module
	include CSL::Extensions::Nesting
end

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

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
csl-1.0.0.pre21 lib/csl/extensions.rb
csl-1.0.0.pre20 lib/csl/extensions.rb
csl-1.0.0.pre19 lib/csl/extensions.rb
csl-1.0.0.pre18 lib/csl/extensions.rb
csl-1.0.0.pre17 lib/csl/extensions.rb
csl-1.0.0.pre16 lib/csl/extensions.rb
csl-1.0.0.pre15 lib/csl/extensions.rb
csl-1.0.0.pre14 lib/csl/extensions.rb
csl-1.0.0.pre13 lib/csl/extensions.rb
csl-1.0.0.pre12 lib/csl/extensions.rb
csl-1.0.0.pre11 lib/csl/extensions.rb
csl-1.0.0.pre10 lib/csl/extensions.rb
csl-1.0.0.pre9 lib/csl/extensions.rb
csl-1.0.0.pre8 lib/csl/extensions.rb
csl-1.0.0.pre7 lib/csl/extensions.rb
csl-1.0.0.pre6 lib/csl/extensions.rb
csl-1.0.0.pre5 lib/csl/extensions.rb
csl-1.0.0.pre4 lib/csl/extensions.rb
csl-1.0.0.pre3 lib/csl/extensions.rb
csl-1.0.0.pre2 lib/csl/extensions.rb