Sha256: 1c7d53e63dee051d5ec9017af9e74ceaac854d7381e783648a380bf03752d6fa
Contents?: true
Size: 545 Bytes
Versions: 11
Compression:
Stored size: 545 Bytes
Contents
module AttributeJsonizer require 'multi_json' def add_jsonizable_attribute(json_name, jsonizeable_object) self.class.module_eval { attr_accessor json_name.to_sym} self.send("#{json_name.to_s}=", jsonizeable_object) end def to_json(options) json_hash = {} self.instance_variables.each do |iv| key = iv value = self.instance_variable_get(iv) json_hash[key.to_s.gsub("@","")] = value unless value.kind_of?(Array) && value.length == 0 #Bail on empty arrays end MultiJson.dump(json_hash) end end
Version data entries
11 entries across 11 versions & 1 rubygems