Permalink
Browse files

@ update transformer; + underscore_method option

  • Loading branch information...
1 parent c0d1f4f commit 879bbdb27dcdeba2d1c27bb5715693efc98c57fc Andrew Zinenko committed Sep 24, 2012
Showing with 26 additions and 3 deletions.
  1. +2 −2 Gemfile.lock
  2. +11 −0 lib/vk-ruby/core.rb
  3. +4 −0 lib/vk-ruby/secure.rb
  4. +4 −0 lib/vk-ruby/serverside.rb
  5. +4 −0 lib/vk-ruby/standalone.rb
  6. +1 −1 vk-ruby.gemspec
View
@@ -6,7 +6,7 @@ PATH
faraday (~> 0.8.4)
faraday_middleware (~> 0.8.8)
multi_json (~> 1.3.6)
- transformer (~> 0.2.2)
+ transformer (~> 0.3.0)
unicode_utils (~> 1.3.0)
GEM
@@ -42,7 +42,7 @@ GEM
oj (1.0.6)
patron (0.4.18)
rake (0.9.2.2)
- transformer (0.2.2)
+ transformer (0.3.0)
typhoeus (0.4.2)
ffi (~> 1.0)
mime-types (~> 1.18)
View
@@ -8,6 +8,8 @@ module Core
# A customized stack of Faraday middleware that will be used to make each request.
attr_accessor :faraday_middleware
+ attr_configurable :underscore_methods, default: false
+
# Application ID that will be used to make each request.
# @method app_id
attr_configurable :app_id
@@ -215,5 +217,14 @@ def http_params(verb, options)
end
end
+ # @private
+ def underscore(str)
+ str.gsub(/::/, '/').
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
+ tr("-", "_").
+ downcase
+ end
+
end
end
View
@@ -15,6 +15,10 @@ class VK::Secure
def initialize(params = {})
params.each{|k,v| instance_variable_set(:"@#{k}", v)}
+ if (params[:underscore_methods] || self.underscore_methods)
+ self.method_name = proc{|name| underscore(name)}
+ end
+
transform secure_api, self.method(:vk_call)
end
@@ -26,6 +26,10 @@ class VK::Serverside
def initialize(params = {})
params.each{|k,v| instance_variable_set(:"@#{k}", v) }
+ if (params[:underscore_methods] || self.underscore_methods)
+ self.method_name = proc{|name| underscore(name)}
+ end
+
transform base_api, self.method(:vk_call)
end
@@ -20,6 +20,10 @@ class VK::Standalone
def initialize(params={})
params.each{|k,v| instance_variable_set(:"@#{k}", v) }
+ if (params[:underscore_methods] || self.underscore_methods)
+ self.method_name = proc{|name| underscore(name)}
+ end
+
transform base_api, self.method(:vk_call)
transform ext_api, self.method(:vk_call)
end
View
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
gem.extra_rdoc_files = ["LICENSE.txt", "README.md" ]
- gem.add_runtime_dependency 'transformer', '~> 0.2.2'
+ gem.add_runtime_dependency 'transformer', '~> 0.3.0'
gem.add_runtime_dependency 'attr_configurable', '~> 0.1.0'
gem.add_runtime_dependency 'multi_json', '~> 1.3.6'
gem.add_runtime_dependency 'faraday', '~> 0.8.4'

0 comments on commit 879bbdb

Please sign in to comment.