Module: HasTokenable::Concern

Defined in:
lib/has_tokenable/concern.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Constant Summary collapse

METHODS =
%w(urlsafe_base64 hex alphanumeric random_number uuid).freeze

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/has_tokenable/concern.rb', line 6

def self.included(base)
  base.send(:extend,  ClassMethods)
  base.send(:include, InstanceMethods)
  base.class_eval do
    validates :token, presence: true, uniqueness: true
    before_validation :generate_token, on: :create, if: proc{|record| record.token.nil? }
  end
end