Module: CloudCrowd::Helpers::Resources

Included in:
CloudCrowd::Helpers
Defined in:
lib/cloud_crowd/helpers/resources.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) current_job

Lazy-fetch the job specified by job_id.



14
15
16
# File 'lib/cloud_crowd/helpers/resources.rb', line 14

def current_job
  @job ||= Job.find_by_id(params[:job_id]) or raise Sinatra::NotFound
end

- (Object) current_work_unit

Lazy-fetch the WorkUnit specified by work_unit_id.



19
20
21
# File 'lib/cloud_crowd/helpers/resources.rb', line 19

def current_work_unit
  @work_unit ||= WorkUnit.find_by_id(params[:work_unit_id]) or raise Sinatra::NotFound
end

- (Object) json(obj)

Convenience method for responding with JSON. Sets the content-type, serializes, and allows empty responses.



7
8
9
10
11
# File 'lib/cloud_crowd/helpers/resources.rb', line 7

def json(obj)
  content_type :json
  return status(204) && '' if obj.nil?
  (obj.respond_to?(:as_json) ? obj.as_json : obj).to_json
end