Class: Invitation::InvitesController::InviteForm

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/controllers/invitation/invites_controller.rb

Overview

A form object pretends to be ‘invite’, but accepts both ‘email’ and ‘emails’. It knows how to build all of the invite instances.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ InviteForm

Returns a new instance of InviteForm.



66
67
68
69
# File 'app/controllers/invitation/invites_controller.rb', line 66

def initialize(attributes = {})
  @emails ||= []
  super
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



59
60
61
# File 'app/controllers/invitation/invites_controller.rb', line 59

def email
  @email
end

#emailsObject

Returns the value of attribute emails.



59
60
61
# File 'app/controllers/invitation/invites_controller.rb', line 59

def emails
  @emails
end

#invitableObject (readonly)

Returns the value of attribute invitable.



60
61
62
# File 'app/controllers/invitation/invites_controller.rb', line 60

def invitable
  @invitable
end

#invitable_idObject

Returns the value of attribute invitable_id.



59
60
61
# File 'app/controllers/invitation/invites_controller.rb', line 59

def invitable_id
  @invitable_id
end

#invitable_typeObject

Returns the value of attribute invitable_type.



59
60
61
# File 'app/controllers/invitation/invites_controller.rb', line 59

def invitable_type
  @invitable_type
end

Class Method Details

.model_nameObject

form masquerades as ‘invite’



62
63
64
# File 'app/controllers/invitation/invites_controller.rb', line 62

def self.model_name # form masquerades as 'invite'
  ActiveModel::Name.new(self, nil, 'Invite')
end

Instance Method Details

#build_invites(current_user) ⇒ Object



75
76
77
78
79
# File 'app/controllers/invitation/invites_controller.rb', line 75

def build_invites(current_user)
  all_emails.reject(&:blank?).collect do |e|
    Invite.new(invitable_id: @invitable_id, invitable_type: @invitable_type, sender_id: current_user.id, email: e)
  end
end