Class: TestFile
- Inherits:
-
Object
- Object
- TestFile
- Extended by:
- ActiveModel::Naming
- Defined in:
- lib/citrulu/test_file.rb
Instance Attribute Summary collapse
-
#compiled_test_file_text ⇒ Object
readonly
The tests which will be run.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#domains ⇒ Object
readonly
The list of domains in compiled_test_file_text.
-
#errors ⇒ Object
readonly
A rails style error object (using ActiveModel::Errors) - use errors.full_messages to access an array of error messages.
-
#frequency ⇒ Object
readonly
How often the test file is run, in seconds (e.g. 3600 = once every hour).
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#run_tests ⇒ Object
Boolean - if set to true, the tests will be run.
-
#test_file_text ⇒ Object
Returns the value of attribute test_file_text.
-
#tutorial_id ⇒ Object
readonly
Returns the value of attribute tutorial_id.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Class Method Summary collapse
- .all ⇒ Object
-
.compile(id) ⇒ Object
POST “app.citrulu.com/api/v1/test_files/compile/?auth_token=abcdefg” status: 201 = successful compilation.
- .create(options = {}) ⇒ Object
-
.delete(id) ⇒ Object
DELETE “app.citrulu.com/api/v1/test_files/2?auth_token=abcdefg” Status 204 = successful deletion.
- .find(id) ⇒ Object
- .update(id, options = {}) ⇒ Object
Instance Method Summary collapse
-
#compile ⇒ Object
Attempts to compile the test file.
-
#destroy ⇒ Object
Deletes the current test file on Citrulu.
-
#initialize(args = {}) ⇒ TestFile
constructor
A new instance of TestFile.
-
#save ⇒ Object
Create or update the current test file on Citrulu.
Constructor Details
#initialize(args = {}) ⇒ TestFile
Returns a new instance of TestFile.
67 68 69 70 71 |
# File 'lib/citrulu/test_file.rb', line 67 def initialize(args={}) args.each do |attr, value| self.public_send("#{attr}=", value) end if args end |
Instance Attribute Details
#compiled_test_file_text ⇒ Object (readonly)
The tests which will be run. May differ from test_file_text if the
8 9 10 |
# File 'lib/citrulu/test_file.rb', line 8 def compiled_test_file_text @compiled_test_file_text end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
18 19 20 |
# File 'lib/citrulu/test_file.rb', line 18 def created_at @created_at end |
#domains ⇒ Object (readonly)
The list of domains in compiled_test_file_text
12 13 14 |
# File 'lib/citrulu/test_file.rb', line 12 def domains @domains end |
#errors ⇒ Object (readonly)
A rails style error object (using ActiveModel::Errors) - use errors.full_messages to access an array of error messages
21 22 23 |
# File 'lib/citrulu/test_file.rb', line 21 def errors @errors end |
#frequency ⇒ Object (readonly)
How often the test file is run, in seconds (e.g. 3600 = once every hour)
14 15 16 |
# File 'lib/citrulu/test_file.rb', line 14 def frequency @frequency end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
15 16 17 |
# File 'lib/citrulu/test_file.rb', line 15 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/citrulu/test_file.rb', line 5 def name @name end |
#run_tests ⇒ Object
Boolean - if set to true, the tests will be run
10 11 12 |
# File 'lib/citrulu/test_file.rb', line 10 def run_tests @run_tests end |
#test_file_text ⇒ Object
Returns the value of attribute test_file_text.
6 7 8 |
# File 'lib/citrulu/test_file.rb', line 6 def test_file_text @test_file_text end |
#tutorial_id ⇒ Object (readonly)
Returns the value of attribute tutorial_id.
16 17 18 |
# File 'lib/citrulu/test_file.rb', line 16 def tutorial_id @tutorial_id end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
17 18 19 |
# File 'lib/citrulu/test_file.rb', line 17 def updated_at @updated_at end |
Class Method Details
.all ⇒ Object
79 80 81 82 83 |
# File 'lib/citrulu/test_file.rb', line 79 def self.all response = Citrulu.connection.get "test_files" attr_array = JSON.parse(response.body) attr_array.map{ |attrs| build(attrs)} end |
.compile(id) ⇒ Object
POST “app.citrulu.com/api/v1/test_files/compile/?auth_token=abcdefg” status: 201 = successful compilation
132 133 134 135 |
# File 'lib/citrulu/test_file.rb', line 132 def self.compile(id) response = Citrulu.connection.post "test_files/compile/#{id}" parse_response(response.body) end |
.create(options = {}) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/citrulu/test_file.rb', line 97 def self.create(={}) response = Citrulu.connection.post "test_files", body = JSON.parse(response.body) if response.status == 200 build(body) else # 422 - validation errors test_file = build() add_all_errors(test_file, body["errors"]) return test_file end end |
.delete(id) ⇒ Object
DELETE “app.citrulu.com/api/v1/test_files/2?auth_token=abcdefg” Status 204 = successful deletion
126 127 128 |
# File 'lib/citrulu/test_file.rb', line 126 def self.delete(id) Citrulu.connection.delete "test_files/#{id}" end |
.find(id) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/citrulu/test_file.rb', line 86 def self.find(id) response = Citrulu.connection.get "test_files/#{id}" # parse_response(response.body) # TEMPORARY: there's a bug in the api which means that it returns an array instead of a single hash, # so we'll be hacky for now: attrs = JSON.parse(response.body) build(attrs.first) end |
.update(id, options = {}) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/citrulu/test_file.rb', line 111 def self.update(id, ={}) response = Citrulu.connection.put "test_files/#{id}", body = JSON.parse(response.body) if response.status == 200 build(body) else # 422 - validation errors test_file = find(id) add_all_errors(test_file, body["errors"]) return test_file end end |
Instance Method Details
#compile ⇒ Object
Attempts to compile the test file. Returns any compilation errors as an errors object. Use errors.full_messages to access the array of error messages.
161 162 163 |
# File 'lib/citrulu/test_file.rb', line 161 def compile self.class.compile(id) end |
#destroy ⇒ Object
Deletes the current test file on Citrulu
156 157 158 |
# File 'lib/citrulu/test_file.rb', line 156 def destroy self.class.delete(id) end |
#save ⇒ Object
Create or update the current test file on Citrulu
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/citrulu/test_file.rb', line 143 def save = { name: name, test_file_text: test_file_text, run_tests: run_tests, } if id self.class.update(id, ) else self.class.create() end end |