Skip to content

Commit 0b8a5ef

Browse files
committed
Merge remote-tracking branch 'origin' into setup-ci
2 parents 91279a4 + ae776ac commit 0b8a5ef

File tree

71 files changed

+443
-254
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+443
-254
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/test/dummy/db/*.sqlite3
77
/test/dummy/db/*.sqlite3-*
88
/test/dummy/log/*.log
9+
/test/dummy/tmp/rake_ui/*
910
/test/dummy/storage/
1011
/test/dummy/tmp/cache/
1112
/test/dummy/tmp/development_secret.txt

Gemfile

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
33

44
# Specify your gem's dependencies in rake-ui.gemspec.
55
gemspec
66

7-
gem 'jbuilder'
8-
97
group :development do
10-
gem 'sqlite3'
8+
gem "sqlite3"
119
end
1210

13-
gem 'pry', group: [:development, :test], require: false
14-
gem 'rails', group: [:development, :test], require: false
11+
gem "pry", group: [:development, :test], require: false
12+
gem "rails", group: [:development, :test], require: false

Gemfile.lock

-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ PATH
44
rake-ui (0.1.0)
55
actionpack
66
activesupport
7-
jbuilder
87
railties
98
rake
109

@@ -75,8 +74,6 @@ GEM
7574
activesupport (>= 4.2.0)
7675
i18n (1.8.8)
7776
concurrent-ruby (~> 1.0)
78-
jbuilder (2.11.2)
79-
activesupport (>= 5.0.0)
8077
loofah (2.9.0)
8178
crass (~> 1.0.2)
8279
nokogiri (>= 1.5.9)
@@ -151,7 +148,6 @@ PLATFORMS
151148
x86_64-linux
152149

153150
DEPENDENCIES
154-
jbuilder
155151
pry
156152
rails
157153
rake-ui!

README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# RakeUi
2-
Short description and motivation.
3-
4-
## Usage
5-
How to use my plugin.
2+
Rake UI is a Rails engine that enables the discovery and execution rake tasks in a UI.
63

74
## Installation
85
Add this line to your application's Gemfile:

Rakefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ require "bundler/gem_tasks"
1010
require "rake/testtask"
1111

1212
Rake::TestTask.new(:test) do |t|
13-
t.libs << 'test'
14-
t.pattern = 'test/**/*_test.rb'
13+
t.libs << "test"
14+
t.pattern = "test/**/*_test.rb"
1515
t.verbose = false
1616
end
1717

Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
# frozen_string_literal: true
2+
13
module RakeUi
24
class ApplicationController < ActionController::Base
35
before_action :guard_not_production
46

57
private
68

79
def guard_not_production
8-
respond :unauthorized unless (Rails.env.test? || Rails.env.development?)
10+
respond :unauthorized unless Rails.env.test? || Rails.env.development?
911
end
1012
end
1113
end

app/controllers/rake_ui/rake_task_logs_controller.rb

+36-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1+
# frozen_string_literal: true
2+
13
module RakeUi
24
class RakeTaskLogsController < ApplicationController
5+
RAKE_TASK_LOG_ATTRS = [:id,
6+
:name,
7+
:args,
8+
:environment,
9+
:rake_command,
10+
:rake_definition_file,
11+
:log_file_name,
12+
:log_file_full_path].freeze
13+
314
def index
415
@rake_task_logs = RakeUi::RakeTaskLog.all.sort_by(&:id)
516

617
respond_to do |format|
718
format.html
8-
format.json
19+
format.json do
20+
render json: {
21+
rake_task_logs: rake_task_logs_as_json(@rake_task_logs)
22+
}
23+
end
924
end
1025
end
1126

@@ -18,8 +33,27 @@ def show
1833

1934
respond_to do |format|
2035
format.html
21-
format.json
36+
format.json do
37+
render json: {
38+
rake_task_log: rake_task_log_as_json(@rake_task_log),
39+
rake_task_log_content: @rake_task_log_content,
40+
rake_task_log_content_url: @rake_task_log_content_url,
41+
is_rake_task_log_finished: @is_rake_task_log_finished
42+
}
43+
end
44+
end
45+
end
46+
47+
private
48+
49+
def rake_task_log_as_json(task)
50+
RAKE_TASK_LOG_ATTRS.each_with_object({}) do |param, obj|
51+
obj[param] = task.send(param)
2252
end
2353
end
54+
55+
def rake_task_logs_as_json(tasks = [])
56+
tasks.map { |task| rake_task_log_as_json(task) }
57+
end
2458
end
2559
end
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
1+
# frozen_string_literal: true
2+
13
module RakeUi
24
class RakeTasksController < RakeUi::ApplicationController
5+
RAKE_TASK_ATTRS = [:id,
6+
:name,
7+
:name_with_args,
8+
:arg_description,
9+
:full_comment,
10+
:locations,
11+
:is_internal_task,
12+
:sources].freeze
13+
314
def index
415
@rake_tasks = RakeUi::RakeTask.all
516

6-
if !params[:show_all]
17+
unless params[:show_all]
718
@rake_tasks = @rake_tasks.select(&:internal_task?)
819
end
920

1021
respond_to do |format|
11-
format.json
1222
format.html
23+
format.json do
24+
render json: {
25+
rake_tasks: rake_tasks_as_json(@rake_tasks)
26+
}
27+
end
1328
end
1429
end
1530

1631
def show
1732
@rake_task = RakeUi::RakeTask.find_by_id(params[:id])
1833

1934
respond_to do |format|
20-
format.json
2135
format.html
36+
format.json do
37+
render json: {
38+
rake_task: rake_task_as_json(@rake_task)
39+
}
40+
end
2241
end
2342
end
2443

@@ -29,5 +48,17 @@ def execute
2948

3049
redirect_to rake_task_log_path rake_task_log.id
3150
end
51+
52+
private
53+
54+
def rake_task_as_json(task)
55+
RAKE_TASK_ATTRS.each_with_object({}) do |param, obj|
56+
obj[param] = task.send(param)
57+
end
58+
end
59+
60+
def rake_tasks_as_json(tasks)
61+
tasks.map { |task| rake_task_as_json(task) }
62+
end
3263
end
3364
end

app/helpers/rake_ui/application_helper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module RakeUi
24
module ApplicationHelper
35
end

app/models/rake_ui/rake_task.rb

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module RakeUi
24
class RakeTask
35
def self.load
@@ -12,9 +14,9 @@ def self.all
1214
end
1315

1416
def self.internal
15-
self.load.map do |task|
17+
self.load.map { |task|
1618
new(task)
17-
end.select(&:is_internal_task)
19+
}.select(&:is_internal_task)
1820
end
1921

2022
def self.find_by_id(id)
@@ -39,8 +41,14 @@ def id
3941

4042
# actions will be something like #<Proc:0x000055a2737fe778@/some/rails/app/lib/tasks/auto_annotate_models.rake:4>
4143
def rake_definition_file
42-
actions.first
43-
rescue StandardError
44+
definition = actions.first || ""
45+
46+
if definition.respond_to?(:source_location)
47+
definition.source_location.join(":")
48+
else
49+
definition
50+
end
51+
rescue
4452
"unable_to_determine_defining_file"
4553
end
4654

@@ -50,7 +58,7 @@ def is_internal_task
5058

5159
# thinking this is the sanest way to discern application vs gem defined tasks (like rails, devise etc)
5260
def internal_task?
53-
actions.any? {|a| !a.to_s.include? "/ruby/gems" }
61+
actions.any? { |a| !a.to_s.include? "/ruby/gems" }
5462

5563
# this was my initial thought here, leaving for posterity in case we need to or the definition of custom
5664
# from initial investigation the actions seemed like the most consistent as locations is sometimes empty
@@ -90,16 +98,16 @@ def build_rake_command(args: nil, environment: nil)
9098
command = ""
9199

92100
if environment
93-
command += "#{environment.to_s} "
101+
command += "#{environment} "
94102
end
95103

96104
command += "rake #{name}"
97105

98106
if args
99-
command += "[#{args.to_s}]"
107+
command += "[#{args}]"
100108
end
101109

102110
command
103111
end
104112
end
105-
end
113+
end

app/models/rake_ui/rake_task_log.rb

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,42 @@
1+
# frozen_string_literal: true
2+
13
module RakeUi
24
class RakeTaskLog < OpenStruct
35
# year-month-day-hour(24hour time)-minute-second-utc
46
ID_DATE_FORMAT = "%Y-%m-%d-%H-%M-%S%z"
5-
REPOSITORY_DIR = Rails.root.join('tmp', 'rake_ui')
7+
REPOSITORY_DIR = Rails.root.join("tmp", "rake_ui")
68
FILE_DELIMITER = "____"
79
FINISHED_STRING = "+++++ COMMAND FINISHED +++++"
810
TASK_HEADER_OUTPUT_DELIMITER = "-------------------------------"
911
FILE_ITEM_SEPARATOR = ": "
1012

13+
def self.create_tmp_file_dir
14+
FileUtils.mkdir_p(REPOSITORY_DIR.to_s)
15+
end
16+
1117
def self.truncate
12-
FileUtils.rm_rf(Dir.glob(REPOSITORY_DIR.to_s + '/*'))
18+
FileUtils.rm_rf(Dir.glob(REPOSITORY_DIR.to_s + "/*"))
1319
end
1420

1521
def self.build_from_file(log_file_name)
1622
log_file_name.split(FILE_DELIMITER)
1723

1824
new(
19-
id: log_file_name.gsub('.txt', ''),
25+
id: log_file_name.gsub(".txt", ""),
2026
log_file_name: log_file_name,
2127
log_file_full_path: Rails.root.join(REPOSITORY_DIR, log_file_name).to_s
2228
)
2329
end
2430

25-
def self.build_new_for_command(name:, args: nil, environment: nil,rake_definition_file:, rake_command:, raker_id:)
31+
def self.build_new_for_command(name:, rake_definition_file:, rake_command:, raker_id:, args: nil, environment: nil)
32+
create_tmp_file_dir
33+
2634
date = Time.now.strftime(ID_DATE_FORMAT)
2735
id = "#{date}#{FILE_DELIMITER}#{raker_id}"
2836
log_file_name = "#{id}.txt"
29-
log_file_full_path = Rails.root.join('tmp', 'rake_ui', log_file_name).to_s
37+
log_file_full_path = REPOSITORY_DIR.join(log_file_name).to_s
3038

31-
File.open(log_file_full_path, 'w+') do |f|
39+
File.open(log_file_full_path, "w+") do |f|
3240
f.puts "id#{FILE_ITEM_SEPARATOR}#{id}"
3341
f.puts "name#{FILE_ITEM_SEPARATOR}#{name}"
3442
f.puts "date#{FILE_ITEM_SEPARATOR}#{date}"
@@ -39,9 +47,9 @@ def self.build_new_for_command(name:, args: nil, environment: nil,rake_definitio
3947
f.puts "log_file_name#{FILE_ITEM_SEPARATOR}#{log_file_name}"
4048
f.puts "log_file_full_path#{FILE_ITEM_SEPARATOR}#{log_file_full_path}"
4149

42-
f.puts "#{TASK_HEADER_OUTPUT_DELIMITER}"
50+
f.puts TASK_HEADER_OUTPUT_DELIMITER.to_s
4351
f.puts " INVOKED RAKE TASK OUTPUT BELOW"
44-
f.puts "#{TASK_HEADER_OUTPUT_DELIMITER}"
52+
f.puts TASK_HEADER_OUTPUT_DELIMITER.to_s
4553
end
4654

4755
new(id: id,
@@ -55,9 +63,11 @@ def self.build_new_for_command(name:, args: nil, environment: nil,rake_definitio
5563
end
5664

5765
def self.all
58-
Dir.entries(REPOSITORY_DIR).reject do |file|
59-
file == '.' || file == '..'
60-
end.map do |log|
66+
create_tmp_file_dir
67+
68+
Dir.entries(REPOSITORY_DIR).reject { |file|
69+
file == "." || file == ".."
70+
}.map do |log|
6171
RakeUi::RakeTaskLog.build_from_file(log)
6272
end
6373
end
@@ -148,7 +158,7 @@ def parsed_file_contents
148158
name, value = line.split(FILE_ITEM_SEPARATOR, 2)
149159
next unless name
150160

151-
parsed[name] = value && value.gsub("\n", '')
161+
parsed[name] = value && value.delete("\n")
152162
end
153163
end.with_indifferent_access
154164
end

app/views/layouts/rake_ui/application.html.erb

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
<%= csp_meta_tag %>
77

88
<link rel="stylesheet" href="https://cdn.rawgit.com/doximity/vital/v2.2.1/dist/css/vital.min.css">
9-
10-
<%= stylesheet_link_tag "rake_ui/application", media: "all" %>
119
</head>
1210
<body>
1311

@@ -22,7 +20,12 @@
2220
</nav>
2321
</div>
2422
</div>
23+
24+
<p id="notice"><%= notice %></p>
25+
2526
<!-- End Nav Menu -->
26-
<%= yield %>
27+
<div class="contents">
28+
<%= yield %>
29+
</div>
2730
</body>
2831
</html>

0 commit comments

Comments
 (0)