Class: Offshore::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/offshore/server/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Controller

Returns a new instance of Controller.



4
5
6
# File 'lib/offshore/server/controller.rb', line 4

def initialize(hash)
  @params = hash
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/offshore/server/controller.rb', line 3

def params
  @params
end

Instance Method Details

#factory_createObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/offshore/server/controller.rb', line 31

def factory_create      
  name = params["name"]
  raise "Need a factory name" unless name
  attributes = params["attributes"] || {}
  
  clazz = factory_girl
  require "factory_girl" unless clazz
  clazz = factory_girl
  
  begin
    val = clazz.create(name, attributes)
    out = {:class_name => val.class.name, :id => val.id, :attributes => val.attributes}
    status = 200
  rescue ActiveRecord::RecordInvalid => invalid
    out = {:error => invalid.record.errors.full_messages.join(",") }
    status = 422
  end
  [status, out]
end

#suite_startObject



8
9
10
11
# File 'lib/offshore/server/controller.rb', line 8

def suite_start
  suite_key_set(params)
  [200, {"todo" => "log that the suite is running"}]
end

#suite_stopObject



13
14
15
16
# File 'lib/offshore/server/controller.rb', line 13

def suite_stop
  suite_key_clear
  [200, {"action" => "cleared"}]
end

#test_startObject



18
19
20
21
22
23
# File 'lib/offshore/server/controller.rb', line 18

def test_start
  Logger.info("  Start: #{params["name"]}")
  Offshore::Database.lock
  Offshore::Database.rollback if suite_key_options["snapshot"] != "none"
  [200, {"action" => "reset / lock"}]
end

#test_stopObject



25
26
27
28
29
# File 'lib/offshore/server/controller.rb', line 25

def test_stop
  Logger.info("   Stop: #{params["name"]}")
  Offshore::Database.unlock
  [200, {"action" => "unlocked"}]
end