Class: CiInACan::Web

Inherits:
Object
  • Object
show all
Defined in:
lib/ci_in_a_can/web.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.jobs_locationObject

Returns the value of attribute jobs_location.



10
11
12
# File 'lib/ci_in_a_can/web.rb', line 10

def jobs_location
  @jobs_location
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



7
8
9
# File 'lib/ci_in_a_can/web.rb', line 7

def params
  @params
end

#sessionObject

Returns the value of attribute session.



7
8
9
# File 'lib/ci_in_a_can/web.rb', line 7

def session
  @session
end

Instance Method Details

#assert_that_the_new_build_is_validObject



66
67
68
69
70
71
72
73
74
# File 'lib/ci_in_a_can/web.rb', line 66

def assert_that_the_new_build_is_valid
  capture = params[:captures].first.split('/')
  api_key = capture.pop
  id      = capture.join('/')

  repo = CiInACan::Repo.find id
  raise 'Could not find this repo' unless repo
  raise 'Invalid API Key' unless repo.api_key == api_key
end

#logged_in?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/ci_in_a_can/web.rb', line 25

def logged_in?
  return false if session[:passphrase].to_s == ''
  session[:passphrase] == ENV['PASSPHRASE']
end

#login_pageObject



13
14
15
# File 'lib/ci_in_a_can/web.rb', line 13

def 
  CiInACan::ViewModels::LoginForm.new.to_html
end

#show_a_list_of_the_runsObject



43
44
45
# File 'lib/ci_in_a_can/web.rb', line 43

def show_a_list_of_the_runs
  CiInACan::ViewModels::AListOfRuns.new(CiInACan::Run.all.to_a).to_html
end

#show_the_repo_edit_formObject



30
31
32
33
34
# File 'lib/ci_in_a_can/web.rb', line 30

def show_the_repo_edit_form
  id = params[:captures].first
  repo = CiInACan::Repo.find(id) || CiInACan::Repo.new(id: id)
  CiInACan::ViewModels::RepoForm.new(repo).to_html
end

#show_the_test_resultObject



47
48
49
50
# File 'lib/ci_in_a_can/web.rb', line 47

def show_the_test_result
  test_result = CiInACan::TestResult.find(params[:id])
  test_result.to_html
end

#show_the_test_result_in_jsonObject



21
22
23
# File 'lib/ci_in_a_can/web.rb', line 21

def show_the_test_result_in_json
  CiInACan::TestResult.find(params[:id]).to_json
end

#start_a_new_buildObject



36
37
38
39
40
41
# File 'lib/ci_in_a_can/web.rb', line 36

def start_a_new_build
  assert_that_the_new_build_is_valid

  write_a_file_with params
  params.to_json
end

#submit_a_passphraseObject



17
18
19
# File 'lib/ci_in_a_can/web.rb', line 17

def submit_a_passphrase
  session[:passphrase] = params[:passphrase]
end

#update_repo_detailsObject



52
53
54
55
56
57
58
# File 'lib/ci_in_a_can/web.rb', line 52

def update_repo_details
  CiInACan::Repo.create(id:             params[:captures].first, 
                        build_commands: params[:commands].gsub("\r\n", "\n")
                                                         .split("\n")
                                                         .map    { |x| x.strip }
                                                         .select { |x| x != '' } )
end

#write_a_file_with(params) ⇒ Object



60
61
62
63
64
# File 'lib/ci_in_a_can/web.rb', line 60

def write_a_file_with params
  data = params.to_json
  file = "#{self.class.jobs_location}/#{UUID.new.generate}.json"
  CiInACan::FileSystem.create_file file, data
end