Class: Tap::Controllers::Schema

Inherits:
Data show all
Defined in:
lib/tap/controllers/schema.rb

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 Data

#create, #destroy, #duplicate, #index, #rename, #select, #show, #update, #upload

Methods inherited from Tap::Controller

#action?, call, #call, #dispatch, 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

#add(id) ⇒ Object

Adds tasks or joins to the schema. Parameters:

tasks[]

An array of tasks to add to the schema.

inputs[]

An array of task indicies used as inputs to a join.

outputs[]

An array of task indicies used as outputs for a join.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tap/controllers/schema.rb', line 13

def add(id)
  if id == "new"
    id = data.next_id(type).to_s
  end
  
  tasks = request['tasks'] || []
  inputs = request['inputs'] || []
  outputs = request['outputs'] || []
  queue = request['queue'] || []
  
  update_schema(id) do |schema|
    current = schema.tasks
    tasks.each do |task|
      key = task
      while current.has_key?(key)
        i ||= 0
        key = "#{task}_#{i}"
        i += 1
      end
      
      current[key] = {'id' => task}
    end
    
    if !inputs.empty? && !outputs.empty?
      schema.joins << [inputs, outputs]
    end
    
    queue.each do |task|
      schema.queue << [task]
    end
  end
  
  redirect uri(id)
end

#configure(id) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/tap/controllers/schema.rb', line 79

def configure(id)
  if id == "new"
    id = data.next_id(type).to_s
  end
  
  schema = Tap::Schema.new(request['schema'] || {})
  schema.scrub! do |obj|
    scrub(obj['config'])
  end
  
  data.create_or_update(type, id) do |io| 
    io << schema.dump
  end
  
  redirect uri(id)
end

#remove(id) ⇒ Object

Removes tasks or joins from a schema. Parameters:

tasks[]

An array of task keys to remove.

joins[]

An array of join indicies to remove.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/tap/controllers/schema.rb', line 53

def remove(id)
  if id == "new"
    id = data.next_id(type).to_s
  end
  
  tasks = request['tasks'] || []
  joins = request['joins'] || []
  queue = request['queue'] || []
  
  update_schema(id) do |schema|
    tasks.each do |key|
      schema.tasks.delete(key)
    end
    
    joins.each {|index| schema.joins[index.to_i] = nil }
    schema.joins.compact!
    
    queue.each {|index| schema.queue[index.to_i] = nil }
    schema.queue.compact!
    
    schema.cleanup!
  end
    
  redirect uri(id)
end