Class: Tap::Controllers::Data
- Inherits:
-
Tap::Controller
- Object
- Tap::Controller
- Tap::Controllers::Data
- Includes:
- RestRoutes, Utils
- Defined in:
- lib/tap/controllers/data.rb
Overview
::controller
Direct Known Subclasses
Constant Summary
Constants inherited from Tap::Controller
Instance Attribute Summary
Attributes inherited from Tap::Controller
#controller_path, #request, #response, #server
Instance Method Summary collapse
-
#create(id) ⇒ Object
POST /projects/id POST /projects?id=id POST /projects?type=.
-
#destroy(id) ⇒ Object
DELETE /projects/id POST /projects/id?_method=delete POST /projects?_method=put&id=id.
- #duplicate(id) ⇒ Object
-
#index ⇒ Object
GET /projects.
-
#rename(id) ⇒ Object
Renames id to request in the schema data.
- #select(ids = []) ⇒ Object
-
#show(id) ⇒ Object
GET /projects/id GET /projects?id=id&as=.
-
#update(id) ⇒ Object
PUT /projects/id POST /projects/id?_method=put POST /projects?_method=put&_action=select&id=id.
- #upload(id = nil) ⇒ Object
Methods inherited from Tap::Controller
#action?, call, #call, get, inherited, #initialize, #module_path, #module_render, nest, #redirect, #render, #render_erb, #render_layout, #route, set, set_variables, #template_path, #uri
Constructor Details
This class inherits a constructor from Tap::Controller
Instance Method Details
#create(id) ⇒ Object
POST /projects/id POST /projects?id=id POST /projects?type=
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tap/controllers/data.rb', line 40 def create(id) if id == "new" id = data.next_id(type).to_s else check_id(id) end data.create(type, id) {|io| io << parse_entry } redirect uri(id) end |
#destroy(id) ⇒ Object
DELETE /projects/id POST /projects/id?_method=delete POST /projects?_method=put&id=id
62 63 64 65 |
# File 'lib/tap/controllers/data.rb', line 62 def destroy(id) data.destroy(type, id) redirect uri end |
#duplicate(id) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/tap/controllers/data.rb', line 90 def duplicate(id) if new_id = request['new_id'] check_id(new_id) end redirect data.copy(type, id, new_id || "#{id}_copy") end |
#index ⇒ Object
GET /projects
14 15 16 |
# File 'lib/tap/controllers/data.rb', line 14 def index render 'index.erb', :layout => true end |
#rename(id) ⇒ Object
Renames id to request in the schema data.
80 81 82 83 84 85 86 87 88 |
# File 'lib/tap/controllers/data.rb', line 80 def rename(id) if new_id = request['new_id'] check_id(new_id) else raise "no new id specified" end redirect data.move(type, id, new_id) end |
#select(ids = []) ⇒ Object
74 75 76 77 |
# File 'lib/tap/controllers/data.rb', line 74 def select(ids=[]) data.cache[type] = ids redirect uri end |
#show(id) ⇒ Object
GET /projects/id GET /projects?id=id&as=
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tap/controllers/data.rb', line 20 def show(id) case request['as'] when 'preview' response.headers['Content-Type'] = 'text/plain' data.read(type, id) when 'download' unless path = data.find(type, id) raise "unknown #{type}: #{id.inspect}" end download(path) else display(id) end end |
#update(id) ⇒ Object
PUT /projects/id POST /projects/id?_method=put POST /projects?_method=put&_action=select&id=id
54 55 56 57 |
# File 'lib/tap/controllers/data.rb', line 54 def update(id) data.update(type, id) {|io| io << parse_entry } redirect uri(id) end |
#upload(id = nil) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/tap/controllers/data.rb', line 67 def upload(id=nil) check_id(id) if id data.import(type, request[type], id) redirect uri end |