Module: MailForm::Shim

Included in:
Base
Defined in:
lib/mail_form/shim.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mail_form/shim.rb', line 6

def self.included(base)
  base.class_eval do
    extend ActiveModel::Naming
    extend ActiveModel::Translation
    extend ActiveModel::Callbacks
    include ActiveModel::Validations
    include ActiveModel::Conversion

    extend MailForm::Shim::ClassMethods
    define_model_callbacks :deliver
  end
end

Instance Method Details

#deliverObject Also known as: save

Create just check validity, and if so, trigger callbacks.



47
48
49
50
51
52
53
# File 'lib/mail_form/shim.rb', line 47

def deliver
  if valid?
    run_callbacks :deliver
  else
    false
  end
end

#idObject

Always return nil so when using form_for, the default method will be post.



42
43
44
# File 'lib/mail_form/shim.rb', line 42

def id
  nil
end

#initialize(params = {}) ⇒ Object

Initialize assigning the parameters given as hash.



26
27
28
29
30
# File 'lib/mail_form/shim.rb', line 26

def initialize(params = {})
  params.each_pair do |attr, value|
    send("#{attr}=", value) if respond_to?("#{attr}=", true)
  end unless params.blank?
end

#new_record?Boolean

Always return true so when using form_for, the default method will be post.

Returns:

  • (Boolean)


33
34
35
# File 'lib/mail_form/shim.rb', line 33

def new_record?
  true
end

#persisted?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/mail_form/shim.rb', line 37

def persisted?
  false
end