class Prototok::Encoders::Base

Public Class Methods

new(**encoder_options) click to toggle source
# File lib/prototok/encoders.rb, line 17
def initialize(**encoder_options)
  options.merge!(encoder_options)
end
options() click to toggle source
# File lib/prototok/encoders.rb, line 13
def self.options
  @options ||= Prototok.config[:encoder_options].dup
end

Public Instance Methods

decode(str) click to toggle source
# File lib/prototok/encoders.rb, line 30
def decode str
  case options[:encoding_mode].to_s
  when 'token'
    decode_token str
  when 'payload'
    decode_payload str
  end
end
deserialize(data) click to toggle source
# File lib/prototok/encoders.rb, line 48
def deserialize data
  Token.new(Serializers.find(:token).decode (data))
end
encode(payload, **header) click to toggle source
# File lib/prototok/encoders.rb, line 21
def encode payload, **header
  case options[:encoding_mode].to_s
  when 'token'
    encode_token payload, **header
  when 'payload'
    encode_payload payload
  end
end
options() click to toggle source
# File lib/prototok/encoders.rb, line 9
def options
  @options ||= self.class.options.dup
end
serialize(payload=nil, **header) click to toggle source
# File lib/prototok/encoders.rb, line 39
def serialize payload=nil, **header
  if payload.is_a? Token
    token = payload.dup.update!(header)
  else
    token = Token.new.update!(header.merge(:payload => payload))
  end
   Serializers.find(:token).new(token).encode
end