Sha256: f13b696c96fae029dfe9b09982afb7132bd504960e6ef9917352b2e6076a7eb3

Contents?: true

Size: 584 Bytes

Versions: 2

Compression:

Stored size: 584 Bytes

Contents

require 'ostruct'
class ApiResource < OpenStruct
  def to_h
    hashfied_resource = self.marshal_dump

    hashfied_resource.keys.each do |attr|
      if self.public_send(attr).kind_of?(ApiResource)
        hashfied_resource[attr] = hashfied_resource[attr].to_h
      end
    end

    hashfied_resource
  end

  def to_json(*args)
    jsonfied_resource = to_h

    jsonfied_resource.keys.each do |attr|
      if self.public_send(attr).kind_of?(ApiResource)
        jsonfied_resource[attr] = jsonfied_resource[attr].to_h
      end
    end

    jsonfied_resource.to_json(args)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
enceladus-0.0.8 spec/support/api_resource.rb
enceladus-0.0.7 spec/support/api_resource.rb