Skip to content

Commit

Permalink
Remove dependency on activesupport for camelize
Browse files Browse the repository at this point in the history
Progress toward sferik#264.
  • Loading branch information
sferik committed Jun 1, 2012
1 parent 6052252 commit 538cd2f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/twitter/action_factory.rb
@@ -1,13 +1,14 @@
require 'active_support/core_ext/string/inflections'
require 'twitter/favorite'
require 'twitter/follow'
require 'twitter/inflector'
require 'twitter/list_member_added'
require 'twitter/mention'
require 'twitter/reply'
require 'twitter/retweet'

module Twitter
class ActionFactory
extend Twitter::Inflector

# Instantiates a new action object
#
Expand All @@ -17,7 +18,7 @@ class ActionFactory
def self.new(action={})
type = action.delete('action')
if type
Twitter.const_get(type.camelize.to_sym).new(action)
Twitter.const_get(camelize(type).to_sym).new(action)
else
raise ArgumentError, "argument must have an 'action' key"
end
Expand Down
13 changes: 13 additions & 0 deletions lib/twitter/inflector.rb
@@ -0,0 +1,13 @@
module Twitter
module Inflector

# Converts a snake_case string to CamelCase
#
# @params string [String]
# @return [String]
def camelize(string)
string.split('_').map(&:capitalize).join
end

end
end

0 comments on commit 538cd2f

Please sign in to comment.