Module: ActsAsTokened

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/acts_as_tokened.rb

Overview

ActsAsTokened

Implements rails 5 has_secure_token Extends the find() method to work with tokens instead of ids. Prevents enumeration of this resource.

Defined Under Namespace

Modules: Base, ClassMethods, FinderMethods

Instance Method Summary collapse

Instance Method Details

#reload(options = nil) ⇒ Object



52
53
54
55
56
57
# File 'app/models/concerns/acts_as_tokened.rb', line 52

def reload(options = nil)
  self.class.instance_variable_set(:@_effective_reloading, true)
  retval = super
  self.class.instance_variable_set(:@_effective_reloading, nil)
  retval
end

#to_global_id(**params) ⇒ Object



47
48
49
50
# File 'app/models/concerns/acts_as_tokened.rb', line 47

def to_global_id(**params)
  params[:tenant] = Tenant.current if defined?(Tenant)
  GlobalID.new(URI::GID.build(app: Rails.application.config.global_id.app, model_name: model_name, model_id: to_param, params: params))
end

#to_paramObject

Instance Methods



43
44
45
# File 'app/models/concerns/acts_as_tokened.rb', line 43

def to_param
  token if persisted?
end