Class: TwitterFriendly::Serializer::Coder

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_friendly/serializer.rb

Direct Known Subclasses

JsonCoder, OjCoder

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(coder) ⇒ Coder

Returns a new instance of Coder.



46
47
48
# File 'lib/twitter_friendly/serializer.rb', line 46

def initialize(coder)
  @coder = coder
end

Class Method Details

.instance(coder = nil) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/twitter_friendly/serializer.rb', line 54

def self.instance(coder = nil)
  if coder.nil? && defined?(Oj)
    OjCoder.new(Oj)
  else
    JsonCoder.new(coder)
  end
end

Instance Method Details

#encode(obj) ⇒ Object



50
51
52
# File 'lib/twitter_friendly/serializer.rb', line 50

def encode(obj)
  @coder.dump(obj)
end