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.



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

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.



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

def attributes
  @attributes
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#protocolObject (readonly)

Returns the value of attribute protocol.



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

def protocol
  @protocol
end

#userObject (readonly)

Returns the value of attribute user.



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

def user
  @user
end

Class Method Details

.call(attrs, user:, host:, protocol: "http") ⇒ Object



17
18
19
# File 'app/services/pages_core/invite_service.rb', line 17

def call(attrs, user:, host:, protocol: "http")
  new(attrs, user:, host:, protocol:).call
end

Instance Method Details

#callObject



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

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