Created
February 11, 2014 22:18
-
-
Save tinogomes/8945392 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BANK_RULES ||= YAML::load(ERB.new(File.read(Rails.root.join('bank_rules.yml'))).result) | |
BANK_RULES.default = BANK_RULES['default'] | |
def BANK_RULES.[](key, attribute = nil) | |
attributes = super(key) | |
return attributes if attribute.nil? | |
attributes[attribute] | |
end | |
class Bank | |
include ActiveModel::Validations | |
attr_accessor :bank_code, :agency_number, :agency_digit, :account_number, :account_digit | |
validates_presence_of :bank_code, :agency_number, :agency_digit, :account_number, :account_digit | |
validates_each BANK_RULES.keys, allow_blank: true do |record, attr, value| | |
bank_rule = BANK_RULE[record.bank_code, attr] | |
record.errors.add(attr, :too_long, count: bank_rule) if value.to_s.length > bank_rule | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default: &DEFAULT | |
agency_number: 10 | |
agency_digit: 2 | |
account_number: 10 | |
account_digit: 2 | |
'001': | |
<<: *DEFAULT | |
agency_number: 4 | |
account_number: 8 | |
'341': | |
<<: *DEFAULT | |
agency_number: 4 | |
account_number: 5 | |
account_digit: 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment