web_rake 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e09eac128735fb1e77c9cb595f2032e6ad1abb9760d09849b78a63bb78f3929
4
- data.tar.gz: eb5cd52b01f04054ba61c2f2968a1d1a04bb73bc4346dea81c296e4b2a470f36
3
+ metadata.gz: 335f7075a11c5508278517e04acd1a77ad37c7baa704475b3082c128b4bde1b5
4
+ data.tar.gz: 4107f317a0ed93c1eb4c5ae9b6cc9f58c790c5956185e82df04c75dd70625f37
5
5
  SHA512:
6
- metadata.gz: ef860e8563607df0fc3066f3c6c46a67d91067b9bc9ad83361d8e31bbdd37bbde867136d2f4971d7907740919e5c9666143bb3f4b3629d521899bdd4e464186a
7
- data.tar.gz: 0a1e20b4ec60af7c2144bcba16589dbac3892d09b6b68802689af677e67fe08a65692c461cd0735d6f20b80bc93158afa0546a7cec46af44fb5b6fe062dd68ce
6
+ metadata.gz: 56d5c6ca2d62e2dcff067c8b28512499a085f353ca29d4b0c5d2c23d17855d2767c84fa4cf62f24a767b84287a0aba0c83900be67d83f77b9c5d66d54bb7e612
7
+ data.tar.gz: ac6f472a51bf31a767e84d17c1575dcc5cc83127b981c2d72b1d1c5b67cee6557902206c0b9fc5b0e3579daecffb5675664766a3ef6f7148376fa0dac0c03b9c
@@ -1,3 +1,7 @@
1
+ require 'rake'
2
+ require 'open3'
3
+ require 'ostruct'
4
+
1
5
  module WebRake
2
6
  class TasksController < ApplicationController
3
7
  before_action :ensure_environment_loaded
@@ -14,9 +18,8 @@ module WebRake
14
18
  def execute
15
19
  task_name = params[:id].gsub('__', ':')
16
20
 
17
- # Check if this is one of our allowed tasks (custom tasks + db:seed)
18
- allowed_tasks = extract_task_names_from_files + ['db:seed']
19
- unless allowed_tasks.include?(task_name)
21
+ # Use find_task to validate the task is allowed
22
+ unless find_task
20
23
  redirect_to root_path, alert: "Task not found"
21
24
  return
22
25
  end
@@ -35,7 +38,6 @@ module WebRake
35
38
 
36
39
  # Run the rake task in a subprocess to avoid state issues
37
40
  # This ensures clean execution every time
38
- require 'open3'
39
41
 
40
42
  # Build the rake command
41
43
  rake_command = "bundle exec rake #{task_name}"
@@ -77,81 +79,43 @@ module WebRake
77
79
  end
78
80
 
79
81
  def custom_tasks
80
- # First, get the names of tasks defined in lib/tasks files
81
- custom_task_names = extract_task_names_from_files
82
-
83
- # Always include db:seed task
84
- custom_task_names << 'db:seed'
85
-
86
82
  # Ensure all tasks are loaded
87
83
  Rails.application.load_tasks
88
84
 
89
- # Get only the tasks that match our custom task names
90
- custom_task_names.filter_map do |name|
91
- Rake::Task[name] rescue nil
92
- end.select(&:actions)
93
- end
94
-
95
- def extract_task_names_from_files
96
- task_names = []
97
-
98
- # Parse each rake file to extract task names
99
- Dir.glob(Rails.root.join('lib/tasks/**/*.rake')).each do |file|
100
- content = File.read(file)
101
-
102
- # Match various task definition patterns
103
-
104
- # Pattern for: task({ :sample_data => :environment })
105
- content.scan(/task\s*\(\s*\{\s*:([a-zA-Z_][a-zA-Z0-9_]*)\s*=>/).each do |match|
106
- task_names << match[0]
107
- end
108
-
109
- # Pattern for: task({ sample_data: :environment }) - Ruby 1.9+ syntax with parens and braces
110
- content.scan(/task\s*\(\s*\{\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*:/).each do |match|
111
- task_names << match[0]
112
- end
113
-
114
- # Pattern for: task :sample_data => :environment
115
- content.scan(/task\s+:([a-zA-Z_][a-zA-Z0-9_]*)\s*=>/).each do |match|
116
- task_names << match[0]
117
- end
118
-
119
- # Pattern for: task "sample_data" => :environment
120
- content.scan(/task\s+["']([a-zA-Z_][a-zA-Z0-9_]*)["']\s*=>/).each do |match|
121
- task_names << match[0]
122
- end
85
+ tasks = []
123
86
 
124
- # Pattern for: task sample_data: :environment (Ruby 1.9+ syntax)
125
- content.scan(/task\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*:/).each do |match|
126
- task_names << match[0]
127
- end
128
-
129
- # Pattern for: task(:sample_data)
130
- content.scan(/task\s*\(\s*:([a-zA-Z_][a-zA-Z0-9_]*)\s*\)/).each do |match|
131
- task_names << match[0]
132
- end
87
+ # Find tasks defined in lib/tasks or db:seed
88
+ Rake.application.tasks.each do |task|
89
+ next if task.actions.blank?
133
90
 
134
- # Pattern for: desc "..." \n task :name
135
- content.scan(/desc\s+.*?\n\s*task\s+:([a-zA-Z_][a-zA-Z0-9_]*)/).each do |match|
136
- task_names << match[0]
91
+ if task_from_lib_tasks?(task) || task.name == "db:seed"
92
+ tasks << task
137
93
  end
138
94
  end
139
95
 
140
- task_names.uniq
96
+ tasks
141
97
  end
142
98
 
143
99
  def find_task
144
100
  task_name = params[:id].gsub('__', ':')
145
101
 
146
- # Check if this is one of our allowed tasks (custom tasks + db:seed)
147
- allowed_tasks = extract_task_names_from_files + ['db:seed']
148
- return nil unless allowed_tasks.include?(task_name)
149
-
150
102
  # Ensure tasks are loaded
151
103
  Rails.application.load_tasks
152
104
 
153
105
  # Find the task
154
- Rake::Task[task_name] rescue nil
106
+ task = Rake::Task[task_name] rescue nil
107
+
108
+ # Check if it's db:seed or defined in lib/tasks
109
+ return task if task_from_lib_tasks?(task) || task_name == "db:seed"
110
+
111
+ nil
112
+ end
113
+
114
+ def task_from_lib_tasks?(task)
115
+ return false if task.actions.blank?
116
+
117
+ source_path = task.actions.first.source_location&.first
118
+ source_path.present? && source_path.include?(Rails.root.join("lib/tasks").to_s)
155
119
  end
156
120
  end
157
- end
121
+ end
@@ -1,3 +1,3 @@
1
1
  module WebRake
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_rake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Purinton
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-09-16 00:00:00.000000000 Z
10
+ date: 2025-09-17 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails