Sha256: 9416d05784e888db986321294077c1318fa72b0ebda29e3d3461b515ee7e94b6

Contents?: true

Size: 793 Bytes

Versions: 2

Compression:

Stored size: 793 Bytes

Contents

module DocSmoosher
  class Resource < ApiObject
    attr_accessor :requests, :parameters

    def initialize(params = {}, &block)
      super(params)
    end

    def requests
      @requests ||= []
    end

    def parameters
      @parameters ||= []
    end

    def request( params = {}, &block )
      r = Request.new( params, &block )
      requests << r unless requests.include?(r)
      r
    end


    def as_json(options={})
      json = super
      if self.requests.length > 0
        json.merge(
          {
            :requests => self.requests.map(&:as_json)
          }
        )
      end
      if self.parameters.length > 0
        json.merge(
          {
            :parameters => self.parameters.map(&:as_json)
          }
        )
      end
      json
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
doc_smoosher-0.1.0 lib/doc_smoosher/resource.rb
doc_smoosher-0.0.2 lib/doc_smoosher/resource.rb