Class: Nyauth::Registration

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/services/nyauth/registration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_params = {}) ⇒ Registration

Returns a new instance of Registration.



6
7
8
9
10
# File 'app/services/nyauth/registration.rb', line 6

def initialize(service_params = {})
  @email = service_params[:email]
  @password = service_params[:password]
  @password_confirmation = service_params[:password_confirmation]
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'app/services/nyauth/registration.rb', line 4

def client
  @client
end

#emailObject (readonly)

Returns the value of attribute email.



4
5
6
# File 'app/services/nyauth/registration.rb', line 4

def email
  @email
end

#passwordObject (readonly)

Returns the value of attribute password.



4
5
6
# File 'app/services/nyauth/registration.rb', line 4

def password
  @password
end

#password_confirmationObject (readonly)

Returns the value of attribute password_confirmation.



4
5
6
# File 'app/services/nyauth/registration.rb', line 4

def password_confirmation
  @password_confirmation
end

Instance Method Details

#save(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'app/services/nyauth/registration.rb', line 12

def save(options = {})
  options.reverse_merge!(as: :user)
  klass = options[:as].to_s.classify.constantize
  @client = klass.create(email: @email,
                         password: @password,
                         password_confirmation: @password_confirmation)
  @errors = @client.errors
  @client.valid?
end