Class: CoderDecorator::Coders::Base64
- Defined in:
- lib/coder_decorator/coders/base64.rb
Overview
:nodoc:
Constant Summary
Constants inherited from Coder
Instance Method Summary collapse
- #decode(str) ⇒ Object
- #encode(obj) ⇒ Object
-
#initialize(coder = nil, strict: true) ⇒ Base64
constructor
A new instance of Base64.
Methods inherited from Coder
Constructor Details
#initialize(coder = nil, strict: true) ⇒ Base64
Returns a new instance of Base64.
6 7 8 9 |
# File 'lib/coder_decorator/coders/base64.rb', line 6 def initialize(coder = nil, strict: true) super(coder) @template_str = strict ? 'm0' : 'm' end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class CoderDecorator::Coders::Coder
Instance Method Details
#decode(str) ⇒ Object
15 16 17 18 19 |
# File 'lib/coder_decorator/coders/base64.rb', line 15 def decode(str) coder.decode(str.unpack(@template_str).first) rescue ::ArgumentError raise InvalidEncoding end |
#encode(obj) ⇒ Object
11 12 13 |
# File 'lib/coder_decorator/coders/base64.rb', line 11 def encode(obj) [coder.encode(obj)].pack(@template_str) end |