Sha256: 806e6b09e569f089fb35772c050d82514d842a9d966a536e9962113d4dc19e8a

Contents?: true

Size: 675 Bytes

Versions: 5

Compression:

Stored size: 675 Bytes

Contents

module DeviseTokenAuth::Concerns::TokensSerialization
  extend self
  # Serialization hash to json
  def dump(object)
    JSON.generate(object && object.transform_values do |token|
      serialize_updated_at(token).compact
    end.compact)
  end

  # Deserialization json to hash
  def load(json)
    case json
    when String
      JSON.parse(json)
    when NilClass
      {}
    else
      json
    end
  end

  private

  def serialize_updated_at(token)
    updated_at_key = ['updated_at', :updated_at].find(&token.method(:[]))

    return token unless token[updated_at_key].respond_to?(:iso8601)

    token.merge updated_at_key => token[updated_at_key].iso8601
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
devise_token_auth-1.2.4 app/models/devise_token_auth/concerns/tokens_serialization.rb
devise_token_auth-1.2.2 app/models/devise_token_auth/concerns/tokens_serialization.rb
devise_token_auth-1.2.1 app/models/devise_token_auth/concerns/tokens_serialization.rb
devise_token_auth-1.2.0 app/models/devise_token_auth/concerns/tokens_serialization.rb
devise_token_auth-1.1.5 app/models/devise_token_auth/concerns/tokens_serialization.rb