Sha256: 600897fc3fc828befdcf840127c652f3a778d087e25831ccb8947137ec95a8f4

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

class Jeweler
  # This stuff is blatently ripped out of active_support's inflector
  module ActiveSupport
    if Module.method(:const_get).arity == 1
      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
    else
      def constantize(camel_cased_word) #:nodoc:
        names = camel_cased_word.split('::')
        names.shift if names.empty? || names.first.empty?

        constant = Object
        names.each do |name|
          constant = constant.const_get(name, false) || constant.const_missing(name)
        end
        constant
      end
    end

    def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
      if first_letter_in_uppercase
        lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
      else
        lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1]
      end
    end
  end
  
  include ActiveSupport
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
technicalpickles-jeweler-0.0.4 lib/jeweler/active_support.rb
technicalpickles-jeweler-0.0.5 lib/jeweler/active_support.rb
technicalpickles-jeweler-0.0.6 lib/jeweler/active_support.rb
technicalpickles-jeweler-0.0.7 lib/jeweler/active_support.rb
technicalpickles-jeweler-0.1.1 lib/jeweler/active_support.rb
technicalpickles-jeweler-0.2.0 lib/jeweler/active_support.rb