Module: ErrorMerger
- Defined in:
- lib/error_merger/version.rb,
lib/error_merger/error_merger.rb
Constant Summary collapse
- VERSION =
'0.2.0'
Instance Method Summary collapse
- #full_sentence(attribute, message) ⇒ Object
- #full_sentences ⇒ Object
-
#merge(association, prefix = nil) ⇒ Object
merges an association’s Errors set into the current set eg: @user.errors.merge @account @user.errors.merge @account, “Account ##@[email protected]: ”.
Instance Method Details
#full_sentence(attribute, message) ⇒ Object
23 24 25 26 |
# File 'lib/error_merger/error_merger.rb', line 23 def full_sentence(attribute, ) m = (attribute, ) m.ends_with?('.') ? m : "#{m}." end |
#full_sentences ⇒ Object
19 20 21 |
# File 'lib/error_merger/error_merger.rb', line 19 def full_sentences map{ |attr, m| full_sentence(attr, m) } end |
#merge(association, prefix = nil) ⇒ Object
merges an association’s Errors set into the current set eg: @user.errors.merge @account
@user.errors.merge @account, "Account ##{@account.id}: "
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/error_merger/error_merger.rb', line 6 def merge(association, prefix=nil) if association.errors.respond_to? : prefix ||= "#{association.class.model_name.human}: " association.errors.each do |attr, error| add :base, "#{prefix}#{association.errors.full_message(attr, error)}" end else association.errors.each do |error| add :base, error end end end |