Skip to content

Commit

Permalink
added autocomplete_bank_name method, added gemspec
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmartin committed Apr 18, 2011
1 parent cd10ecf commit 51533d5
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Jeweler::Tasks.new do |gem|
gem.name = "kontoapi-rails"
gem.homepage = "http://github.com/GeneralScripting/kontoapi-rails"
gem.license = "MIT"
gem.summary = %Q{TODO: one-line summary of your gem}
gem.description = %Q{TODO: longer description of your gem}
gem.summary = %Q{A wrapper for the Konto API (https://www.kontoapi.de/) providing model validation.}
gem.description = %Q{This library is a wrapper for the Konto API (https://www.kontoapi.de/). It provides a validation method for models that checks if a given account number and bank code represent a valid combination.}
gem.email = "[email protected]"
gem.authors = ["Jan Schwenzien"]
# Include your dependencies below. Runtime dependencies are required when using your gem,
Expand Down
75 changes: 75 additions & 0 deletions kontoapi-rails.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{kontoapi-rails}
s.version = "0.0.1"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Jan Schwenzien"]
s.date = %q{2011-04-18}
s.description = %q{This library is a wrapper for the Konto API (https://www.kontoapi.de/). It provides a validation method for models that checks if a given account number and bank code represent a valid combination.}
s.email = %q{[email protected]}
s.extra_rdoc_files = [
"LICENSE",
"README.markdown"
]
s.files = [
".document",
".rspec",
"Gemfile",
"Gemfile.lock",
"LICENSE",
"README.markdown",
"Rakefile",
"VERSION",
"init.rb",
"lib/kontoapi-rails.rb",
"lib/kontoapi-rails/config.rb",
"lib/kontoapi-rails/orm/active_record_extension.rb",
"lib/kontoapi-rails/orm/mongoid_extension.rb",
"lib/kontoapi-rails/railtie.rb",
"lib/kontoapi-rails/validators/bank_account_validator.rb",
"spec/kontoapi-rails_spec.rb",
"spec/spec_helper.rb"
]
s.homepage = %q{http://github.com/GeneralScripting/kontoapi-rails}
s.licenses = ["MIT"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.7.2}
s.summary = %q{A wrapper for the Konto API (https://www.kontoapi.de/) providing model validation.}
s.test_files = [
"spec/kontoapi-rails_spec.rb",
"spec/spec_helper.rb"
]

if s.respond_to? :specification_version then
s.specification_version = 3

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rails>, ["~> 3.0.0"])
s.add_runtime_dependency(%q<kontoapi-ruby>, [">= 0"])
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
s.add_development_dependency(%q<rcov>, [">= 0"])
else
s.add_dependency(%q<rails>, ["~> 3.0.0"])
s.add_dependency(%q<kontoapi-ruby>, [">= 0"])
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
s.add_dependency(%q<rcov>, [">= 0"])
end
else
s.add_dependency(%q<rails>, ["~> 3.0.0"])
s.add_dependency(%q<kontoapi-ruby>, [">= 0"])
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
s.add_dependency(%q<rcov>, [">= 0"])
end
end

1 change: 1 addition & 0 deletions lib/kontoapi-rails.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
require 'kontoapi-ruby'
require 'kontoapi-rails/config'
require 'kontoapi-rails/railtie'
18 changes: 15 additions & 3 deletions lib/kontoapi-rails/orm/active_record_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@ def self.included(base)
module ClassMethods
def validates_bank_account(options={})
options.symbolize_keys!
class_eval do
validates_with KontoAPI::BankAccountValidator, options
validates_with KontoAPI::BankAccountValidator, options
end

def autocomplete_bank_name(options={})
options.symbolize_keys!
options.reverse_merge!(
:bank_code_field => :bank_code,
:bank_name_field => :bank_name
)
#write_inheritable_attribute(:autocomplete_bank_name_options, options)
define_method :autocomplete_bank_name do
current_value = send(:"#{options[:bank_name_field]}")
blz = send(:"#{options[:bank_code_field]}")
self.send(:"#{options[:bank_name_field]}=", KontoAPI::bank_name(blz)) if current_value.blank? && blz.present?
end
nil
before_save :autocomplete_bank_name
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/kontoapi-rails/validators/bank_account_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BankAccountValidator < ActiveModel::Validator
def validate(record)
record_options = options.reverse_merge(DEFAULTS)
account_number = record.send(:"#{record_options[:account_number_field]}")
bank_code = record.send(:"#{record_options[:bank_code_field]}"))
bank_code = record.send(:"#{record_options[:bank_code_field]}")
record.errors[:"#{record_options[:account_number_field]}"] << :invalid unless KontoAPI::valid?(account_number, bank_code)
rescue Timeout::Error => ex
case record_options[:on_timeout]
Expand Down
6 changes: 3 additions & 3 deletions spec/kontoapi-rails_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "KontoapiRails" do
it "fails" do
fail "hey buddy, you should probably rename this file and start specing for real"
describe "KontoAPI Rails" do
it "should be tested" do
fail "TEST ME!"
end
end

0 comments on commit 51533d5

Please sign in to comment.