Sha256: eabfda1b04653961ee1566b313be3e0c717ffabbda108ecaa7155fa363c8b94a

Contents?: true

Size: 756 Bytes

Versions: 11

Compression:

Stored size: 756 Bytes

Contents

module CloudCrowd
  module Helpers
    module Resources
      
      # Convenience method for responding with JSON. Sets the content-type, 
      # serializes, and allows empty responses.
      def json(obj)
        content_type :json
        return status(204) && '' if obj.nil?
        (obj.respond_to?(:as_json) ? obj.as_json : obj).to_json
      end
      
      # Lazy-fetch the job specified by <tt>job_id</tt>.
      def current_job
        @job ||= Job.find_by_id(params[:job_id]) or raise Sinatra::NotFound
      end
      
      # Lazy-fetch the WorkUnit specified by <tt>work_unit_id</tt>.
      def current_work_unit
        @work_unit ||= WorkUnit.find_by_id(params[:work_unit_id]) or raise Sinatra::NotFound
      end
      
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
cloud-crowd-0.7.6 lib/cloud_crowd/helpers/resources.rb
cloud-crowd-0.7.5 lib/cloud_crowd/helpers/resources.rb
cloud-crowd-0.7.3 lib/cloud_crowd/helpers/resources.rb
cloud-crowd-0.7.2 lib/cloud_crowd/helpers/resources.rb
cloud-crowd-0.7.2.beta lib/cloud_crowd/helpers/resources.rb
cloud-crowd-0.7.2.pre3 lib/cloud_crowd/helpers/resources.rb
cloud-crowd-0.7.2.pre2 lib/cloud_crowd/helpers/resources.rb
cloud-crowd-0.7.2.pre lib/cloud_crowd/helpers/resources.rb
cloud-crowd-0.7.1 lib/cloud_crowd/helpers/resources.rb
cloud-crowd-0.7.0 lib/cloud_crowd/helpers/resources.rb
cloud-crowd-0.7.0.pre lib/cloud_crowd/helpers/resources.rb