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.


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

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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes


3
4
5
# File 'app/services/pages_core/create_user_service.rb', line 3

def attributes
  @attributes
end

#inviteObject (readonly)

Returns the value of attribute invite


3
4
5
# File 'app/services/pages_core/create_user_service.rb', line 3

def invite
  @invite
end

Class Method Details

.call(*attrs) ⇒ Object


11
12
13
# File 'app/services/pages_core/create_user_service.rb', line 11

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

Instance Method Details

#callObject


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

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