Skip to content

Commit

Permalink
Replaces Vindicia::Util with ActiveSupport
Browse files Browse the repository at this point in the history
Uses camelize and underscore methods
  • Loading branch information
cadwallion committed Sep 12, 2012
1 parent 0e0efa5 commit e29395d
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 29 deletions.
1 change: 1 addition & 0 deletions lib/vindicia-api.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
require 'active_support/core_ext/string/conversions'
require 'vindicia/config'
require 'vindicia/model'
5 changes: 2 additions & 3 deletions lib/vindicia/config.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'singleton'
require 'vindicia/util'

module Vindicia

Expand Down Expand Up @@ -193,7 +192,7 @@ def self.initialize!
return false unless API_CLASSES[config.api_version]

API_CLASSES[config.api_version].each_key do |vindicia_klass|
const_set(Vindicia::Util.camelize(vindicia_klass.to_s),
const_set(vindicia_klass.to_s.camelize,
Class.new do
include Vindicia::Model

Expand All @@ -214,4 +213,4 @@ def self.initialize!
)
end
end
end
end
7 changes: 3 additions & 4 deletions lib/vindicia/model.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "savon"
require "savon/core_ext/string"

module Vindicia

Expand Down Expand Up @@ -46,7 +45,7 @@ def actions(*actions)

def define_class_action(action)
class_action_module.module_eval <<-CODE
def #{action.to_s.snakecase}(body = {}, &block)
def #{action.to_s.underscore}(body = {}, &block)
client.request :tns, #{action.inspect} do
soap.namespaces["xmlns:tns"] = vindicia_target_namespace
http.headers["SOAPAction"] = vindicia_soap_action('#{action}')
Expand All @@ -56,7 +55,7 @@ def #{action.to_s.snakecase}(body = {}, &block)
block.call(soap, wsdl, http, wsse) if block
end
rescue Exception => e
rescue_exception(:#{action.to_s.snakecase}, e)
rescue_exception(:#{action.to_s.underscore}, e)
end
CODE
end
Expand Down Expand Up @@ -90,7 +89,7 @@ def underscoreize_periods(target)
end

def vindicia_soap_action(action)
%{"#{vindicia_target_namespace}##{action.to_s.lower_camelcase}"}
%{"#{vindicia_target_namespace}##{action.to_s.camelize(:lower)}"}
end

def rescue_exception(action, error)
Expand Down
8 changes: 0 additions & 8 deletions lib/vindicia/util.rb

This file was deleted.

5 changes: 2 additions & 3 deletions test/vindicia/config_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'helper'
require 'vindicia/util'

class Vindicia::ConfigTest < Test::Unit::TestCase

Expand All @@ -8,7 +7,7 @@ def setup
def self.clear_config
if Vindicia.config.is_configured?
Vindicia::API_CLASSES[Vindicia.config.api_version].each_key do |vindicia_klass|
Vindicia.send(:remove_const, Vindicia::Util.camelize(vindicia_klass.to_s).to_sym)
Vindicia.send(:remove_const, vindicia_klass.to_s.camelize.to_sym)
end
end
end
Expand Down Expand Up @@ -88,7 +87,7 @@ def test_should_define_vindicia_classes_for_respective_api_version
assert Vindicia.config.is_configured?

Vindicia::API_CLASSES[good_api_version].each_key do |vindicia_klass|
assert Vindicia.const_get(Vindicia::Util.camelize(vindicia_klass.to_s))
assert Vindicia.const_get(vindicia_klass.to_s.camelize)
end
end

Expand Down
5 changes: 2 additions & 3 deletions test/vindicia/model_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'helper'
require 'vindicia/util'
require 'net/http'

class Vindicia::ModelTest < Test::Unit::TestCase
Expand All @@ -9,7 +8,7 @@ def setup
def self.clear_config
if Vindicia.config.is_configured?
Vindicia::API_CLASSES[Vindicia.config.api_version].each_key do |vindicia_klass|
Vindicia.send(:remove_const, Vindicia::Util.camelize(vindicia_klass.to_s).to_sym)
Vindicia.send(:remove_const, vindicia_klass.to_s.camelize.to_sym)
end
end
end
Expand Down Expand Up @@ -39,7 +38,7 @@ def teardown
def test_should_define_api_methods_of_respective_vindicia_class_for_respective_api_version
Vindicia::API_CLASSES[@good_api_version].each_key do |vindicia_klass_name|

vindicia_klass = Vindicia.const_get(Vindicia::Util.camelize(vindicia_klass_name.to_s))
vindicia_klass = Vindicia.const_get(vindicia_klass_name.to_s.camelize)

Vindicia::API_CLASSES[@good_api_version][vindicia_klass_name].each do |api_method|
assert vindicia_klass.respond_to?(api_method)
Expand Down
8 changes: 0 additions & 8 deletions test/vindicia/util_test.rb

This file was deleted.

1 change: 1 addition & 0 deletions vindicia-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]

gem.add_dependency('savon')
gem.add_dependency('active_support')

gem.add_development_dependency('rake')
gem.add_development_dependency('mocha')
Expand Down

0 comments on commit e29395d

Please sign in to comment.