Class: Rosetta::Deserializers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rosetta/deserializers/base.rb

Direct Known Subclasses

JSON

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Base

Returns a new instance of Base.



30
31
32
# File 'lib/rosetta/deserializers/base.rb', line 30

def initialize(input)
  @input = input.dup.freeze
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



9
10
11
# File 'lib/rosetta/deserializers/base.rb', line 9

def input
  @input
end

Class Method Details

.call(input) ⇒ Object



18
19
20
21
22
# File 'lib/rosetta/deserializers/base.rb', line 18

def call(input)
  new(input).call
rescue StandardError
  raise DeserializationError
end

.deserializeObject



23
24
25
26
27
# File 'lib/rosetta/deserializers/base.rb', line 23

def call(input)
  new(input).call
rescue StandardError
  raise DeserializationError
end

.inherited(new_serializer) ⇒ Object



12
13
14
15
16
# File 'lib/rosetta/deserializers/base.rb', line 12

def inherited(new_serializer)
  key = new_serializer.name.match(/^(.*?)(Deserializer)?$/)[1]
  key = key.split("::").last
  Deserializers.register(key.underscore.to_sym, new_serializer)
end

.to_procObject



25
26
27
# File 'lib/rosetta/deserializers/base.rb', line 25

def to_proc
  proc { |*args, &block| self.call(*args, &block) }
end

Instance Method Details

#callObject Also known as: deserialize

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/rosetta/deserializers/base.rb', line 34

def call
  raise NotImplementedError
end

#to_procObject



39
40
41
# File 'lib/rosetta/deserializers/base.rb', line 39

def to_proc
  proc { |*args, &block| self.call(*args, &block) }
end