Sha256: 182b12ca25db274aad023027a1e08a5bc277cd11b461bacccf8a6a43161b490a

Contents?: true

Size: 651 Bytes

Versions: 59

Compression:

Stored size: 651 Bytes

Contents

module Spree
  module Core
    module TokenResource
      module ClassMethods
        def token_resource
          has_one :tokenized_permission, :as => :permissable
          delegate :token, :to => :tokenized_permission, :allow_nil => true
          after_create :create_token
        end
      end

      def create_token
        permission = build_tokenized_permission
        permission.token = token = ::SecureRandom::hex(8)
        permission.save!
        token
      end

      def self.included(receiver)
        receiver.extend ClassMethods
      end
    end
  end
end

ActiveRecord::Base.class_eval { include Spree::Core::TokenResource }

Version data entries

59 entries across 59 versions & 2 rubygems

Version Path
spree_core-2.2.14 lib/spree/core/token_resource.rb
spree_core-2.2.13 lib/spree/core/token_resource.rb
spree_core-2.2.12 lib/spree/core/token_resource.rb
spree_core-2.2.11 lib/spree/core/token_resource.rb
spree_core-2.2.10 lib/spree/core/token_resource.rb
spree_core-2.2.9 lib/spree/core/token_resource.rb
spree_core-2.1.12 lib/spree/core/token_resource.rb
spree_core-2.2.8 lib/spree/core/token_resource.rb
spree_core-2.1.11 lib/spree/core/token_resource.rb
spree_core-2.2.7 lib/spree/core/token_resource.rb
spree_core-2.1.10 lib/spree/core/token_resource.rb
spree_core-2.0.13 lib/spree/core/token_resource.rb
spree_core-2.1.9 lib/spree/core/token_resource.rb
spree_core-2.2.6 lib/spree/core/token_resource.rb
spree_core-2.2.5 lib/spree/core/token_resource.rb
spree_core-2.1.8 lib/spree/core/token_resource.rb
spree_core-2.0.12 lib/spree/core/token_resource.rb
spree_core-2.2.4 lib/spree/core/token_resource.rb
spree_core-2.2.3 lib/spree/core/token_resource.rb
spree_core-2.2.2 lib/spree/core/token_resource.rb