Class: RailsWayback::PagesController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- RailsWayback::PagesController
- Defined in:
- app/controllers/rails_wayback/pages_controller.rb
Overview
JSON endpoints consumed by the bar's JavaScript to populate the branch and commit selectors. All rendering of the actual UI lives in the middleware; this controller only exposes git metadata.
Constant Summary collapse
- WAYBACK_COOKIES =
%w[rails_wayback_ref rails_wayback_branch].freeze
Instance Method Summary collapse
- #branches ⇒ Object
- #commits ⇒ Object
-
#reset ⇒ Object
Emergency escape hatch that does not render any host application view.
Instance Method Details
#branches ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/rails_wayback/pages_controller.rb', line 14 def branches current_branch = safe_call { git.current_branch } current_commit = safe_call { git.current_commit } references = safe_call { git.references } list = references.value || [] render json: { current_branch: current_branch.value, current_commit: current_commit.value, branches: list.select { |reference| reference.kind == :branch }.map(&:name), refs: list.map { |reference| reference_json(reference) }, errors: [references.error].compact } end |
#commits ⇒ Object
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 |
# File 'app/controllers/rails_wayback/pages_controller.rb', line 29 def commits selector = params[:branch].to_s.sub(/\.json\z/, "") result = safe_call do reference = git.reference(selector) [reference, git.commits(reference.full_name)] end reference, commits = result.value list = (commits || []).map do |commit| { sha: commit.sha, short_sha: commit.short_sha, subject: commit.subject, author: commit., date: commit.date } end render json: { branch: reference&.name || selector, ref: reference && reference_json(reference), commits: list, error: result.error } end |
#reset ⇒ Object
Emergency escape hatch that does not render any host application view. It remains usable when a historical template crashes before the injected toolbar can render its normal Return to HEAD control.
58 59 60 61 |
# File 'app/controllers/rails_wayback/pages_controller.rb', line 58 def reset WAYBACK_COOKIES.each { |name| response.(name, path: "/") } redirect_to safe_return_to, allow_other_host: false end |