Module: MailForm::Delivery
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #check_not_spam ⇒ Object
-
#deliver! ⇒ Object
Deliver the resource without running any validation.
-
#mail_form_attributes ⇒ Object
Returns a hash of attributes, according to the attributes existent in self.class.mail_attributes.
- #not_spam? ⇒ Boolean
-
#spam? ⇒ Boolean
In development, raises an error if the captcha field is not blank.
Instance Method Details
#check_not_spam ⇒ Object
154 155 156 |
# File 'lib/mail_form/delivery.rb', line 154 def check_not_spam throw(:abort) if spam? end |
#deliver! ⇒ Object
Deliver the resource without running any validation.
159 160 161 162 163 164 165 166 |
# File 'lib/mail_form/delivery.rb', line 159 def deliver! mailer = MailForm::Notifier.contact(self) if mailer.respond_to?(:deliver_now) mailer.deliver_now else mailer.deliver end end |
#mail_form_attributes ⇒ Object
Returns a hash of attributes, according to the attributes existent in self.class.mail_attributes.
170 171 172 173 174 |
# File 'lib/mail_form/delivery.rb', line 170 def mail_form_attributes self.class.mail_attributes.each_with_object({}) do |attr, hash| hash[attr.to_s] = send(attr) end end |
#not_spam? ⇒ Boolean
150 151 152 |
# File 'lib/mail_form/delivery.rb', line 150 def not_spam? !spam? end |
#spam? ⇒ Boolean
In development, raises an error if the captcha field is not blank. This is is good to remember that the field should be hidden with CSS and shown only to robots.
In test and in production, it returns true if all captcha fields are blank, returns false otherwise.
136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/mail_form/delivery.rb', line 136 def spam? self.class.mail_captcha.each do |field| next if send(field).blank? if defined?(Rails) && Rails.env.development? raise ScriptError, "The captcha field #{field} was supposed to be blank" else return true end end false end |