Skip to content
Snippets Groups Projects
Commit 90e13b57 authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

refactoring application model

parent 2fe73c47
No related branches found
No related tags found
No related merge requests found
......@@ -3,12 +3,4 @@ class Application < ActiveRecord::Base
validates :domain, presence: true, uniqueness: true
validates :application_id, presence: true, uniqueness: true
before_create :generate_application_id
private
def generate_application_id
@application_id = SecureRandom.uuid.to_s
generate_application_id if self.class.find_by_application_id(@application_id)
end
end
class ApplicationCreationService
def initialize(app_id_generate_service)
@app_id_generate_service = app_id_generate_service
end
def create(params={})
Application.create! params.merge(application_id: generate_random_app_id)
end
private
def generate_random_app_id
app_id = @app_id_generate_service.generate_random
return generate_random_app_id unless Application.find_by_application_id(app_id).blank?
return app_id
end
end
require 'securerandom'
module Applications
class AppIdGenerateService
def self.generate_random
SecureRandom.uuid
end
end
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment