Skip to content

Commit

Permalink
Refactor attributes to use each_with_object
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva committed Jun 25, 2012
1 parent f75faba commit f3410eb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/mail_form/delivery.rb
Expand Up @@ -36,10 +36,10 @@ module ClassMethods
# * :validate - A hook to validates_*_of. When true is given, validates the
# presence of the attribute. When a regexp, validates format. When array,
# validates the inclusion of the attribute in the array.
#
#
# Whenever :validate is given, the presence is automatically checked. Give
# :allow_blank => true to override.
#
#
# Finally, when :validate is a symbol, the method given as symbol will be
# called. Then you can add validations as you do in ActiveRecord (errors.add).
#
Expand Down Expand Up @@ -148,4 +148,4 @@ def deliver!
MailForm::Notifier.contact(self).deliver
end
end
end
end
5 changes: 2 additions & 3 deletions lib/mail_form/shim.rb
Expand Up @@ -32,9 +32,8 @@ def initialize(params={})
# Returns a hash of attributes, according to the attributes existent in
# self.class.mail_attributes.
def attributes
self.class.mail_attributes.inject({}) do |hash, attr|
self.class.mail_attributes.each_with_object({}) do |attr, hash|
hash[attr.to_s] = send(attr)
hash
end
end

Expand Down Expand Up @@ -62,4 +61,4 @@ def deliver
end
alias :save :deliver
end
end
end

0 comments on commit f3410eb

Please sign in to comment.