From f3410eb2e1aa29e54678a06c5b46da3856549bc9 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Mon, 25 Jun 2012 15:45:35 -0300 Subject: [PATCH] Refactor attributes to use each_with_object --- lib/mail_form/delivery.rb | 6 +++--- lib/mail_form/shim.rb | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/mail_form/delivery.rb b/lib/mail_form/delivery.rb index 8808054..78d483d 100644 --- a/lib/mail_form/delivery.rb +++ b/lib/mail_form/delivery.rb @@ -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). # @@ -148,4 +148,4 @@ def deliver! MailForm::Notifier.contact(self).deliver end end -end \ No newline at end of file +end diff --git a/lib/mail_form/shim.rb b/lib/mail_form/shim.rb index 396de98..27b8bbc 100644 --- a/lib/mail_form/shim.rb +++ b/lib/mail_form/shim.rb @@ -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 @@ -62,4 +61,4 @@ def deliver end alias :save :deliver end -end \ No newline at end of file +end