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

Version Path
blitline-2.9.0 lib/blitline/attribute_jsonizer.rb
blitline-2.8.0 lib/blitline/attribute_jsonizer.rb
blitline-2.7.0 lib/blitline/attribute_jsonizer.rb
blitline-2.6.0 lib/blitline/attribute_jsonizer.rb
blitline-2.5.1 lib/blitline/attribute_jsonizer.rb
blitline-2.5.0 lib/blitline/attribute_jsonizer.rb
blitline-2.4.0 lib/blitline/attribute_jsonizer.rb
blitline-2.3.0 lib/blitline/attribute_jsonizer.rb
blitline-2.2.0 lib/blitline/attribute_jsonizer.rb
blitline-2.1.0 lib/blitline/attribute_jsonizer.rb
blitline-2.0.1 lib/blitline/attribute_jsonizer.rb