Permalink
Browse files

Remove AS dependency and vendor needed string utils.

  • Loading branch information...
1 parent 0862a46 commit 87b2ff67adfa3c766b89158d6ed454e6a2b9e439 James Cook committed Jul 21, 2011
Showing with 55 additions and 11 deletions.
  1. +0 −7 lib/garb.rb
  2. +1 −1 lib/garb/filter_parameters.rb
  3. +5 −1 lib/support.rb
  4. +49 −0 lib/support/string.rb
  5. +0 −2 test/test_helper.rb
View
@@ -10,13 +10,6 @@
require 'json'
end
-begin
- require 'active_support/inflector'
- require 'active_support/deprecation'
-rescue LoadError
- require 'active_support'
-end
-
module Garb
autoload :Destination, 'garb/destination'
autoload :FilterParameters, 'garb/filter_parameters'
@@ -16,7 +16,7 @@ class FilterParameters
attr_accessor :parameters
def initialize(parameters)
- self.parameters = (Array.wrap(parameters) || [])
+ self.parameters = ([parameters].flatten || []).compact
end
def to_params
View
@@ -1,3 +1,7 @@
+unless Object.const_defined?("ActiveSupport")
+ require File.expand_path("./lib/support/string.rb")
+end
+
class SymbolOperator
def initialize(field, operator)
@field, @operator = field, operator
@@ -34,7 +38,7 @@ class Symbol
:substring, :not_substring].each do |operator|
define_method(operator) do
- ActiveSupport::Deprecation.warn("The use of SymbolOperator(#{operator}, etc.) has been deprecated. Please use named filters.")
+ warn("The use of SymbolOperator(#{operator}, etc.) has been deprecated. Please use named filters.")
SymbolOperator.new(self, operator)
end unless method_defined?(operator)
end
View
@@ -0,0 +1,49 @@
+# Pull in some AS String utilities (not loaded if AS is available)
+unless Object.const_defined?("ActiveSupport")
+ class String
+ def camelize(first_letter = :upper)
+ case first_letter
+ when :upper then ActiveSupport::Inflector.camelize(self, true)
+ when :lower then ActiveSupport::Inflector.camelize(self, false)
+ end
+ end
+ alias_method :camelcase, :camelize
+
+ def underscore
+ ActiveSupport::Inflector.underscore(self)
+ end
+
+ def demodulize
+ ActiveSupport::Inflector.demodulize(self)
+ end
+ end
+
+
+ module ActiveSupport
+ module Inflector
+ extend self
+
+ 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.to_s[0].chr.downcase + camelize(lower_case_and_underscored_word)[1..-1]
+ end
+ end
+
+ def underscore(camel_cased_word)
+ word = camel_cased_word.to_s.dup
+ word.gsub!(/::/, '/')
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
+ word.tr!("-", "_")
+ word.downcase!
+ word
+ end
+
+ def demodulize(class_name_in_module)
+ class_name_in_module.to_s.gsub(/^.*::/, '')
+ end
+ end
+ end
+end
View
@@ -25,8 +25,6 @@
$:.unshift File.expand_path('../../lib', __FILE__)
require 'garb'
-ActiveSupport::Deprecation.silenced = true
-
class MiniTest::Unit::TestCase
include Shoulda::InstanceMethods
extend Shoulda::ClassMethods

0 comments on commit 87b2ff6

Please sign in to comment.