Class: Algebrick::Serializers::Chain

Inherits:
Abstract show all
Defined in:
lib/algebrick/serializers/chain.rb,
lib/algebrick/serializers2/chain.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from TypeCheck

#Child!, #Child?, #Match!, #Match?, #Type!, #Type?, error

Constructor Details

- (Chain) initialize(serializer, chain_to)

Returns a new instance of Chain



24
25
26
27
# File 'lib/algebrick/serializers/chain.rb', line 24

def initialize(serializer, chain_to)
  @serializer = Type! serializer, Abstract
  @chain_to   = Type! chain_to, Abstract
end

Instance Attribute Details

- (Object) chain_to (readonly)

Returns the value of attribute chain_to



22
23
24
# File 'lib/algebrick/serializers/chain.rb', line 22

def chain_to
  @chain_to
end

- (Object) serializer (readonly)

Returns the value of attribute serializer



22
23
24
# File 'lib/algebrick/serializers/chain.rb', line 22

def serializer
  @serializer
end

Class Method Details

+ (Object) build(*serializers)



18
19
20
# File 'lib/algebrick/serializers/chain.rb', line 18

def self.build(*serializers)
  serializers.reverse_each.reduce { |ch, s| new(s, ch) }
end

Instance Method Details

- (Object) dump(object, options = {})



33
34
35
# File 'lib/algebrick/serializers/chain.rb', line 33

def dump(object, options = {})
  chain_to.dump serializer.dump(object, options), options
end

- (Object) load(data, options = {})



29
30
31
# File 'lib/algebrick/serializers/chain.rb', line 29

def load(data, options = {})
  serializer.load chain_to.load(data, options), options
end