module Representable::JSON
Public Class Methods
included(base)
click to toggle source
# File lib/representable/json.rb, line 16 def self.included(base) base.class_eval do include Representable # either in Hero or HeroRepresentation. extend ClassMethods # DISCUSS: do that only for classes? register_feature Representable::JSON end end
Public Instance Methods
from_json(data, *args)
click to toggle source
Parses the body as JSON and delegates to from_hash.
# File lib/representable/json.rb, line 33 def from_json(data, *args) data = MultiJson.load(data) from_hash(data, *args) end
to_json(*args)
click to toggle source
Returns a JSON string representing this object.
# File lib/representable/json.rb, line 39 def to_json(*args) MultiJson.dump to_hash(*args) end