Sha256: 5babbea85d300a0f5b1b1796a3b11edd7611a1f1590263a6e1b28673948bdc7c
Contents?: true
Size: 879 Bytes
Versions: 13
Compression:
Stored size: 879 Bytes
Contents
require 'multi_json' require 'representable/hash' require 'representable/json/collection' module Representable # Brings #to_json and #from_json to your object. module JSON extend Hash::ClassMethods include Hash 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 module ClassMethods def collection_representer_class JSON::Collection end end # Parses the body as JSON and delegates to #from_hash. def from_json(data, *args) data = MultiJson.load(data) from_hash(data, *args) end # Returns a JSON string representing this object. def to_json(*args) MultiJson.dump to_hash(*args) end end end
Version data entries
13 entries across 13 versions & 1 rubygems