Class: ShedsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/sheds_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



6
7
8
# File 'app/controllers/sheds_controller.rb', line 6

def index
  render json: { tasks: @tasks }
end

#rakeObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/sheds_controller.rb', line 10

def rake
  errors = nil
  task_name = params[:id].humanize
  task = @tasks.find{|t| t[:name] == task_name }
  if task
    begin
      rake_task = Rake.application.tasks.find{|t| t.name ==  task[:command]}
      rake_task.execute
    rescue Exception => e
      errors = e.to_s
    end
  else
    errors = "Task #{task_name} could not be found"
  end

  if errors
    render json: { errors: errors }
  else
    render json: :ok
  end
end