Class: Prototok::Encoders::Base
- Inherits:
-
Object
- Object
- Prototok::Encoders::Base
- Defined in:
- lib/prototok/encoders.rb
Class Method Summary collapse
Instance Method Summary collapse
- #decode(str) ⇒ Object
- #deserialize(data) ⇒ Object
- #encode(payload, **header) ⇒ Object
-
#initialize(**encoder_options) ⇒ Base
constructor
A new instance of Base.
- #options ⇒ Object
- #serialize(payload = nil, **header) ⇒ Object
Constructor Details
#initialize(**encoder_options) ⇒ Base
Returns a new instance of Base.
17 18 19 |
# File 'lib/prototok/encoders.rb', line 17 def initialize(**) .merge!() end |
Class Method Details
.options ⇒ Object
13 14 15 |
# File 'lib/prototok/encoders.rb', line 13 def self. @options ||= Prototok.config[:encoder_options].dup end |
Instance Method Details
#decode(str) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/prototok/encoders.rb', line 30 def decode str case [:encoding_mode].to_s when 'token' decode_token str when 'payload' decode_payload str end end |
#deserialize(data) ⇒ Object
48 49 50 |
# File 'lib/prototok/encoders.rb', line 48 def deserialize data Token.new(Serializers.find(:token).decode (data)) end |
#encode(payload, **header) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/prototok/encoders.rb', line 21 def encode payload, **header case [:encoding_mode].to_s when 'token' encode_token payload, **header when 'payload' encode_payload payload end end |
#options ⇒ Object
9 10 11 |
# File 'lib/prototok/encoders.rb', line 9 def @options ||= self.class..dup end |
#serialize(payload = nil, **header) ⇒ Object
39 40 41 42 43 44 45 46 |
# 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 |