Class: PagesCore::InviteService

Inherits:
Object
  • Object
show all
Defined in:
app/services/pages_core/invite_service.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes, user:, host:, protocol: "http") ⇒ InviteService

Returns a new instance of InviteService.


7
8
9
10
11
12
# File 'app/services/pages_core/invite_service.rb', line 7

def initialize(attributes, user:, host:, protocol: "http")
  @attributes = attributes
  @user = user
  @host = host
  @protocol = protocol
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes


5
6
7
# File 'app/services/pages_core/invite_service.rb', line 5

def attributes
  @attributes
end

#hostObject (readonly)

Returns the value of attribute host


5
6
7
# File 'app/services/pages_core/invite_service.rb', line 5

def host
  @host
end

#protocolObject (readonly)

Returns the value of attribute protocol


5
6
7
# File 'app/services/pages_core/invite_service.rb', line 5

def protocol
  @protocol
end

#userObject (readonly)

Returns the value of attribute user


5
6
7
# File 'app/services/pages_core/invite_service.rb', line 5

def user
  @user
end

Class Method Details

.call(*attrs) ⇒ Object


15
16
17
# File 'app/services/pages_core/invite_service.rb', line 15

def call(*attrs)
  new(*attrs).call
end

Instance Method Details

#callObject


20
21
22
23
24
25
26
27
28
29
# File 'app/services/pages_core/invite_service.rb', line 20

def call
  Invite.transaction do
    invite = user.invites.create(attributes)
    if invite.valid?
      deliver_invite(invite)
      invite.update(sent_at: Time.now.utc)
    end
    invite
  end
end