3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/brief/server/handlers/action.rb', line 3
def self.handle(path_args, briefcase, options={})
parts = path_args.split("/")
action = parts.shift
path = parts.join("/")
document = briefcase.document_at(path)
= {
"Content-Type" => "application/json"
}
if !document
return [404,,{error:"Could not find a document at this path"}]
end
model = document.to_model
if !model.class.defined_actions.include?(action.to_sym)
[400, , {error:"Invalid action: #{ action }"}]
else
model.send(action)
[200, , model.as_json]
end
end
|