Class: Keys::CreateService

Inherits:
BaseService show all
Defined in:
app/services/keys/create_service.rb

Instance Attribute Summary collapse

Attributes inherited from BaseService

#params, #user

Instance Method Summary collapse

Methods inherited from BaseService

#notification_service

Constructor Details

#initialize(current_user, params = {}) ⇒ CreateService

Returns a new instance of CreateService.


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

def initialize(current_user, params = {})
  @current_user = current_user
  @params = params
  @ip_address = @params.delete(:ip_address)
  @user = params.delete(:user) || current_user
end

Instance Attribute Details

#current_userObject

Returns the value of attribute current_user.


5
6
7
# File 'app/services/keys/create_service.rb', line 5

def current_user
  @current_user
end

Instance Method Details

#executeObject


14
15
16
17
18
# File 'app/services/keys/create_service.rb', line 14

def execute
  key = user.keys.create(params)
  notification_service.new_key(key) if key.persisted?
  key
end