Permalink
Browse files

Merge pull request #93 from jamescook/remove_AS_dependency

Remove AS dependency
  • Loading branch information...
2 parents 0862a46 + d94a2fe commit 9b6fb84873e13df0e93da404154591ed986b272f james cook committed Jul 21, 2011
Showing with 55 additions and 14 deletions.
  1. +0 −1 Gemfile
  2. +0 −2 Gemfile.lock
  3. +0 −7 lib/garb.rb
  4. +1 −1 lib/garb/filter_parameters.rb
  5. +5 −1 lib/support.rb
  6. +49 −0 lib/support/string.rb
  7. +0 −2 test/test_helper.rb
View
@@ -4,7 +4,6 @@ source "http://gems.github.com"
gem 'rake', '~> 0.8.7'
gem 'i18n'
-gem 'activesupport'
group :test do
gem 'shoulda'
View
@@ -2,7 +2,6 @@ GEM
remote: http://rubygems.org/
remote: http://gems.github.com/
specs:
- activesupport (3.0.3)
i18n (0.4.2)
jferris-mocha (0.9.8.20100526112143)
rake
@@ -19,7 +18,6 @@ PLATFORMS
ruby
DEPENDENCIES
- activesupport
i18n
jferris-mocha
minitest
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 9b6fb84

Please sign in to comment.