Sha256: 390d2b0da34c2e3532d42fdeaaefc7cfca87f5bc19cb8b682384305fe0e972ae

Contents?: true

Size: 437 Bytes

Versions: 11

Compression:

Stored size: 437 Bytes

Contents

require 'multi_json'

module Bixby
module Jsonify

  include Hashify

  def to_json(*opts)
    MultiJson.dump(self.to_hash)
  end

  module ClassMethods
    def from_json(json)
      json = MultiJson.load(json) if json.kind_of? String
      obj = self.allocate
      json.each{ |k,v| obj.send("#{k}=".to_sym, v) }
      obj
    end
  end

  def self.included(receiver)
    receiver.extend(ClassMethods)
  end

end # Jsonify
end # Bixby

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
bixby-common-0.7.1 lib/bixby-common/util/jsonify.rb
bixby-common-0.7.0 lib/bixby-common/util/jsonify.rb
bixby-common-0.6.6 lib/bixby-common/util/jsonify.rb
bixby-common-0.6.5 lib/bixby-common/util/jsonify.rb
bixby-common-0.6.4 lib/bixby-common/util/jsonify.rb
bixby-common-0.6.3 lib/bixby-common/util/jsonify.rb
bixby-common-0.6.2 lib/bixby-common/util/jsonify.rb
bixby-common-0.6.1 lib/bixby-common/util/jsonify.rb
bixby-common-0.6.0 lib/bixby-common/util/jsonify.rb
bixby-common-0.5.0 lib/bixby-common/util/jsonify.rb
bixby-common-0.4.13 lib/bixby-common/util/jsonify.rb