Class: Paquito::CoderChain

Inherits:
Object
  • Object
show all
Defined in:
lib/paquito/coder_chain.rb

Instance Method Summary collapse

Constructor Details

#initialize(*coders) ⇒ CoderChain

Returns a new instance of CoderChain.



5
6
7
8
# File 'lib/paquito/coder_chain.rb', line 5

def initialize(*coders)
  @coders = coders.flatten.map { |c| Paquito.cast(c) }
  @reverse_coders = @coders.reverse
end

Instance Method Details

#dump(object) ⇒ Object



10
11
12
13
14
# File 'lib/paquito/coder_chain.rb', line 10

def dump(object)
  payload = object
  @coders.each { |c| payload = c.dump(payload) }
  payload
end

#load(payload) ⇒ Object



16
17
18
19
20
# File 'lib/paquito/coder_chain.rb', line 16

def load(payload)
  object = payload
  @reverse_coders.each { |c| object = c.load(object) }
  object
end