Sha256: 23a7ee59c86e18ba9be125f25117bab01b7d61c71fea8d39f74e855b3a0a30f3

Contents?: true

Size: 310 Bytes

Versions: 36

Compression:

Stored size: 310 Bytes

Contents

module WithGeneratedCode
  extend ActiveSupport::Concern

  included do
    validates_uniqueness_of :code

    defaults do
      self.code ||= self.class.generate_code
    end

    required :code_size
  end

  class_methods do
    def generate_code
      SecureRandom.urlsafe_base64 code_size
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
mumuki-domain-9.23.0 app/models/concerns/with_generated_code.rb
mumuki-domain-9.22.1 app/models/concerns/with_generated_code.rb
mumuki-domain-9.22.0 app/models/concerns/with_generated_code.rb
mumuki-domain-9.21.0 app/models/concerns/with_generated_code.rb
mumuki-domain-9.20.0 app/models/concerns/with_generated_code.rb
mumuki-domain-9.19.0 app/models/concerns/with_generated_code.rb
mumuki-domain-9.18.0 app/models/concerns/with_generated_code.rb
mumuki-domain-9.17.0 app/models/concerns/with_generated_code.rb
mumuki-domain-9.16.0 app/models/concerns/with_generated_code.rb
mumuki-domain-9.15.0 app/models/concerns/with_generated_code.rb
mumuki-domain-9.14.1 app/models/concerns/with_generated_code.rb
mumuki-domain-9.14.0 app/models/concerns/with_generated_code.rb
mumuki-domain-9.13.1 app/models/concerns/with_generated_code.rb
mumuki-domain-9.13.0 app/models/concerns/with_generated_code.rb
mumuki-domain-9.12.0 app/models/concerns/with_generated_code.rb
mumuki-domain-9.11.0 app/models/concerns/with_generated_code.rb
mumuki-domain-9.10.0 app/models/concerns/with_generated_code.rb
mumuki-domain-9.9.0 app/models/concerns/with_generated_code.rb
mumuki-domain-9.8.1 app/models/concerns/with_generated_code.rb
mumuki-domain-9.8.0 app/models/concerns/with_generated_code.rb