Skip to content

Commit

Permalink
remove active support
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioMurga committed Apr 17, 2014
1 parent 7d11415 commit 57af4a3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
* Add payout and payee models with specs.
* Add webhook logs for events.
* Ameliorate convert_to_conekta_object logic.

=== 0.4.1 2014-04-16

* Remove active support and add custom methods in util file.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ gem 'sys-uname'
gem 'rspec'
gem 'faraday'
gem 'json'
gem 'active_support'
# Specify your gem's dependencies in conekta.gemspec
gemspec
45 changes: 39 additions & 6 deletions lib/conekta/util.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'active_support/inflector'
module Conekta
module Util
def self.types
Expand Down Expand Up @@ -27,12 +26,12 @@ def self.convert_to_conekta_object(name,resp)
instance.load_from(resp)
return instance
elsif name.instance_of? String
name = "event_data" if name.camelize == "Data"
name = "obj" if name.camelize == "Object"
if !Object.const_defined?(name.camelize)
instance = Object.const_set(name.camelize, Class.new(ConektaObject)).new
name = "event_data" if camelize(name) == "Data"
name = "obj" if camelize(name) == "Object"
if !Object.const_defined?(camelize(name))
instance = Object.const_set(camelize(name), Class.new(ConektaObject)).new
else
instance = name.camelize.constantize.new
instance = constantize(camelize(name)).new
end
instance.load_from(resp)
return instance
Expand All @@ -52,5 +51,39 @@ def self.convert_to_conekta_object(name,resp)
end
return instance
end
protected
def self.camelize(str)
str.split('_').map{|e| e.capitalize}.join
end
def self.constantize(camel_cased_word)
names = camel_cased_word.split('::')

# Trigger a builtin NameError exception including the ill-formed constant in the message.
Object.const_get(camel_cased_word) if names.empty?

# Remove the first blank element in case of '::ClassName' notation.
names.shift if names.size > 1 && names.first.empty?

names.inject(Object) do |constant, name|
if constant == Object
constant.const_get(name)
else
candidate = constant.const_get(name)
next candidate if constant.const_defined?(name, false)
next candidate unless Object.const_defined?(name)

# Go down the ancestors to check it it's owned
# directly before we reach Object or the end of ancestors.
constant = constant.ancestors.inject do |const, ancestor|
break const if ancestor == Object
break ancestor if ancestor.const_defined?(name, false)
const
end

# owner is in Object, so raise
constant.const_get(name, false)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/conekta/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Conekta
VERSION = '0.4.0'
VERSION = '0.4.1'
end

0 comments on commit 57af4a3

Please sign in to comment.