Class: PagesCore::CreateUserService

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes, invite: nil) ⇒ CreateUserService

Returns a new instance of CreateUserService.



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

def initialize(attributes, invite: nil)
  @attributes = attributes
  @invite = invite
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#inviteObject (readonly)

Returns the value of attribute invite.



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

def invite
  @invite
end

Class Method Details

.call(attrs, invite: nil) ⇒ Object



13
14
15
# File 'app/services/pages_core/create_user_service.rb', line 13

def call(attrs, invite: nil)
  new(attrs, invite:).call
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
# File 'app/services/pages_core/create_user_service.rb', line 18

def call
  User.transaction do
    user = User.create(attributes.merge(invite_attributes))
    if user.valid?
      PagesCore::PubSub.publish(:create_user, user:, invite:)
      invite&.destroy
    end
    user
  end
end