Class: Tap::Controllers::Data

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

Overview

::controller

Constant Summary

Constants inherited from Tap::Controller

Tap::Controller::ServerError

Instance Attribute Summary

Attributes inherited from Tap::Controller

#request, #response, #server

Instance Method Summary collapse

Methods inherited from Tap::Controller

#action?, call, #call, #error, get, inherited, #initialize, #module_render, nest, #not_found, #redirect, #render, #render_erb, #render_layout, #route, set, set_variables, #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

#deselect(ids = []) ⇒ Object



81
82
83
84
85
86
# File 'lib/tap/controllers/data.rb', line 81

def deselect(ids=[])
  if current = data.cache[type]
    data.cache[type] = current - ids
  end
  redirect uri
end

#destroy(id) ⇒ Object

DELETE /projects/id POST /projects/id?_method=delete POST /projects?_method=put&id=id



62
63
64
65
66
# File 'lib/tap/controllers/data.rb', line 62

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

#destroy_all(ids = []) ⇒ Object



88
89
90
91
92
# File 'lib/tap/controllers/data.rb', line 88

def destroy_all(ids=[])
  ids.each {|id| data.destroy(type, id) }
  deselect(ids)
  redirect uri
end

#duplicate(id) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/tap/controllers/data.rb', line 105

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

#indexObject

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.



95
96
97
98
99
100
101
102
103
# File 'lib/tap/controllers/data.rb', line 95

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



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

def select(ids=[])
  current = data.cache[type] ||= []
  data.cache[type] = current | 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



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

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