Class: FrontEndBuilds::Build
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- FrontEndBuilds::Build
- Defined in:
- app/models/front_end_builds/build.rb
Class Method Summary collapse
Instance Method Summary collapse
- #activate! ⇒ Object
- #automatic_activation? ⇒ Boolean
- #fetch! ⇒ Object
- #live? ⇒ Boolean
- #master? ⇒ Boolean
-
#matching_pubkey ⇒ Object
Public: Find the pubkey that can verify the builds signature.
- #serialize ⇒ Object
- #setup! ⇒ Object
-
#verify ⇒ Object
Public: Is the signature is valid for the build.
- #with_head_tag(tag) ⇒ Object
Class Method Details
.find_best(params = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/front_end_builds/build.rb', line 23 def self.find_best(params = {}) scope = self query = { fetched: true } if params[:app] query[:app_id] = params[:app].id app = App.find( params[:app].id ) end if params[:app_name] scope = scope .joins(:app) .where( front_end_builds_apps: { name: params[:app_name] } ) app = App.where( name: params[:app_name] ).first end if params[:id] query[:id] = params[:id] elsif params[:sha] query[:sha] = params[:sha] elsif params[:job] query[:job] = params[:job] elsif params[:branch] query[:branch] = params[:branch] elsif app query[:id] = app.live_build_id end scope .where(query) .limit(1) .order('created_at desc') .first end |
Instance Method Details
#activate! ⇒ Object
113 114 115 116 |
# File 'app/models/front_end_builds/build.rb', line 113 def activate! app.live_build = self app.save end |
#automatic_activation? ⇒ Boolean
118 119 120 |
# File 'app/models/front_end_builds/build.rb', line 118 def automatic_activation? !app.require_manual_activation? end |
#fetch! ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'app/models/front_end_builds/build.rb', line 104 def fetch! return if fetched? || endpoint.blank? html = URI.parse(endpoint).read self.html = html save end |
#live? ⇒ Boolean
96 97 98 |
# File 'app/models/front_end_builds/build.rb', line 96 def live? self == app.live_build end |
#master? ⇒ Boolean
100 101 102 |
# File 'app/models/front_end_builds/build.rb', line 100 def master? branch == 'master' end |
#matching_pubkey ⇒ Object
Public: Find the pubkey that can verify the builds signature.
75 76 77 78 79 |
# File 'app/models/front_end_builds/build.rb', line 75 def matching_pubkey Pubkey.all .detect { |key| key.verify(self) } .tap { |key| self.pubkey = key } end |
#serialize ⇒ Object
126 127 128 129 130 131 132 133 134 135 |
# File 'app/models/front_end_builds/build.rb', line 126 def serialize { id: id, app_id: app_id, sha: sha, branch: branch, job: job, created_at: created_at } end |
#setup! ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/models/front_end_builds/build.rb', line 81 def setup! # Fetching no longer makes senses since ember-cli-deploy will # directly give the HTML to front end builds. However, in order # to support old versions we're going to keep this around for # a while. fetch! if html.blank? self.fetched = true save if automatic_activation? && master? activate! end end |
#verify ⇒ Object
Public: Is the signature is valid for the build.
Returns boolean.
69 70 71 |
# File 'app/models/front_end_builds/build.rb', line 69 def verify !!matching_pubkey end |
#with_head_tag(tag) ⇒ Object
122 123 124 |
# File 'app/models/front_end_builds/build.rb', line 122 def with_head_tag(tag) html.clone.insert(head_pos, tag) end |