Module: CloudCrowd::Helpers::Resources
- Included in:
- CloudCrowd::Helpers
- Defined in:
- lib/cloud_crowd/helpers/resources.rb
Instance Method Summary collapse
-
#current_job ⇒ Object
Lazy-fetch the job specified by
job_id
. -
#current_work_unit ⇒ Object
Lazy-fetch the WorkUnit specified by
work_unit_id
. -
#json(obj) ⇒ Object
Convenience method for responding with JSON.
Instance Method Details
#current_job ⇒ Object
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
|
#current_work_unit ⇒ Object
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
|
#json(obj) ⇒ Object
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
|