Class: Tap::Controllers::Data

Inherits:
Tap::Controller show all
Includes:
RestRoutes, Utils
Defined in:
lib/tap/controllers/data.rb

Overview

::controller

Direct Known Subclasses

Schema

Constant Summary

Constants inherited from Tap::Controller

Tap::Controller::ServerError

Instance Attribute Summary

Attributes inherited from Tap::Controller

#controller_path, #request, #response, #server

Instance Method Summary collapse

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=



39
40
41
42
43
44
45
46
# File 'lib/tap/controllers/data.rb', line 39

def create(id)
  if id == "new"
    id = data.next_id(type).to_s
  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



59
60
61
62
# File 'lib/tap/controllers/data.rb', line 59

def destroy(id)
  data.destroy(type, id)
  redirect uri
end

#duplicate(id) ⇒ Object



80
81
82
# File 'lib/tap/controllers/data.rb', line 80

def duplicate(id)
  redirect data.copy(type, id, request['new_id'] || "#{id}_copy")
end

#indexObject

GET /projects



13
14
15
# File 'lib/tap/controllers/data.rb', line 13

def index
  render 'index.erb', :layout => true
end

#rename(id) ⇒ Object

Renames id to request in the schema data.



76
77
78
# File 'lib/tap/controllers/data.rb', line 76

def rename(id)
  redirect data.move(type, id, request['new_id'])
end

#select(ids = []) ⇒ Object



70
71
72
73
# File 'lib/tap/controllers/data.rb', line 70

def select(ids=[])
  data.cache[type] = ids
  redirect uri
end

#show(id) ⇒ Object

GET /projects/id GET /projects?id=id&as=



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tap/controllers/data.rb', line 19

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



51
52
53
54
# File 'lib/tap/controllers/data.rb', line 51

def update(id)
  data.update(type, id) {|io| io << parse_entry }
  redirect uri(id)
end

#upload(id = nil) ⇒ Object



64
65
66
67
68
# File 'lib/tap/controllers/data.rb', line 64

def upload(id=nil)
  check_id(id)
  data.import(type, request[type], id)
  redirect uri
end