Skip to content

Commit 95bb2fb

Browse files
luke-hillshs96c
authored andcommitted
CrazyFun: Remaining Namespace work (Aside from the .rl items) (#7736)
Namespace all of RubyMappings classes, tasks (and make inheritance chain correct), and RakeMappings (in the same vein as RubyMappings)
1 parent 9d71800 commit 95bb2fb

18 files changed

+547
-471
lines changed

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ crazy_fun = SeleniumRake::CrazyFun.new
8080
#
8181
# If crazy fun doesn't know how to handle a particular output type ("java_library"
8282
# in the example above) then it will throw an exception, stopping the build
83-
RakeMappings.new.add_all(crazy_fun)
84-
RubyMappings.new.add_all(crazy_fun)
83+
CrazyFun::Mappings::RakeMappings.new.add_all(crazy_fun)
84+
CrazyFun::Mappings::RubyMappings.new.add_all(crazy_fun)
8585

8686
# Finally, find every file named "build.desc" in the project, and generate
8787
# rake tasks from them. These tasks are normal rake tasks, and can be invoked

rake_tasks/crazy_fun/mappings/rake_mappings.rb

Lines changed: 15 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,20 @@
1-
class RakeMappings
2-
def add_all(fun)
3-
fun.add_mapping("rake_task", CrazyFunRake::CheckPreconditions.new)
4-
fun.add_mapping("rake_task", CrazyFunRake::CreateTask.new)
5-
fun.add_mapping("rake_task", CrazyFunRake::CreateShortTask.new)
6-
7-
fun.add_mapping("rake_file", CrazyFunRake::CheckFilePreconditions.new)
8-
fun.add_mapping("rake_file", CrazyFunRake::CreateFileTask.new)
9-
fun.add_mapping("rake_file", CrazyFunRake::CreateShortTask.new)
10-
end
11-
end
12-
13-
module CrazyFunRake
14-
class CheckPreconditions
15-
def handle(fun, dir, args)
16-
raise StandardError, "name must be set" if args[:name].nil?
17-
raise StandardError, "task_name must be set" if args[:task_name].nil?
18-
raise StandardError, "out must be set" if args[:out].nil?
19-
end
20-
end
21-
22-
class CreateTask < Tasks
23-
def handle(fun, dir, args)
24-
name = task_name(dir, args[:name])
25-
task name => [ args[:task_name] ]
26-
Rake::Task[name].out = args[:out]
27-
end
28-
end
29-
30-
class CheckFilePreconditions
31-
def handle(fun, dir, args)
32-
raise StandardError, "name must be set" if args[:name].nil?
33-
raise StandardError, "src must be set" if args[:src].nil?
34-
35-
# The "one output rule" means that the srcs must either be a directory
36-
# or a single file.
37-
all_files = FileList[File.join(dir, args[:src])]
38-
raise StandardError, "src must be a single file or directory (#{dir}, #{args.inspect})" unless all_files.length == 1
39-
end
40-
end
41-
42-
class CreateFileTask < Tasks
43-
def handle(fun, dir, args)
44-
name = task_name(dir, args[:name])
45-
46-
src = File.join(dir, args[:src])
47-
if File.directory? src
48-
file name => FileList[File.join(src, "**")]
49-
else
50-
file name => src
51-
end
52-
# out = args[:out].nil? ? args[:name] : args[:out]
53-
54-
Rake::Task[name].out = src
55-
end
56-
end
57-
58-
class CreateShortTask < Tasks
59-
def handle(fun, dir, args)
60-
name = task_name(dir, args[:name])
61-
62-
if name.end_with?("/#{args[:name]}:#{args[:name]}")
63-
short_name = name.sub(/:.*$/, "")
1+
require_relative 'rake_mappings/check_preconditions'
2+
require_relative 'rake_mappings/create_task'
3+
require_relative 'rake_mappings/check_file_preconditions'
4+
require_relative 'rake_mappings/create_file_task'
5+
require_relative 'rake_mappings/create_short_task'
646

65-
task short_name => name
7+
module CrazyFun
8+
module Mappings
9+
class RakeMappings
10+
def add_all(fun)
11+
fun.add_mapping("rake_task", CrazyFun::Mappings::RakeMappings::CheckPreconditions.new)
12+
fun.add_mapping("rake_task", CrazyFun::Mappings::RakeMappings::CreateTask.new)
13+
fun.add_mapping("rake_task", CrazyFun::Mappings::RakeMappings::CreateShortTask.new)
6614

67-
Rake::Task[short_name].out = Rake::Task[name].out
15+
fun.add_mapping("rake_task", CrazyFun::Mappings::RakeMappings::CheckFilePreconditions.new)
16+
fun.add_mapping("rake_task", CrazyFun::Mappings::RakeMappings::CreateFileTask.new)
17+
fun.add_mapping("rake_file", CrazyFun::Mappings::RakeMappings::CreateShortTask.new)
6818
end
6919
end
7020
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module CrazyFun
2+
module Mappings
3+
class RakeMappings
4+
class CheckFilePreconditions
5+
def handle(fun, dir, args)
6+
raise StandardError, "name must be set" if args[:name].nil?
7+
raise StandardError, "src must be set" if args[:src].nil?
8+
9+
# The "one output rule" means that the srcs must either be a directory
10+
# or a single file.
11+
all_files = FileList[File.join(dir, args[:src])]
12+
raise StandardError, "src must be a single file or directory (#{dir}, #{args.inspect})" unless all_files.length == 1
13+
end
14+
end
15+
end
16+
end
17+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module CrazyFun
2+
module Mappings
3+
class RakeMappings
4+
class CheckPreconditions
5+
def handle(fun, dir, args)
6+
raise StandardError, "name must be set" if args[:name].nil?
7+
raise StandardError, "task_name must be set" if args[:task_name].nil?
8+
raise StandardError, "out must be set" if args[:out].nil?
9+
end
10+
end
11+
end
12+
end
13+
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module CrazyFun
2+
module Mappings
3+
class RakeMappings
4+
class CreateFileTask < CrazyFun::Mappings::Tasks
5+
def handle(fun, dir, args)
6+
name = task_name(dir, args[:name])
7+
8+
src = File.join(dir, args[:src])
9+
if File.directory? src
10+
file name => FileList[File.join(src, "**")]
11+
else
12+
file name => src
13+
end
14+
# out = args[:out].nil? ? args[:name] : args[:out]
15+
16+
Rake::Task[name].out = src
17+
end
18+
end
19+
end
20+
end
21+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module CrazyFun
2+
module Mappings
3+
class RakeMappings
4+
class CreateShortTask < CrazyFun::Mappings::Tasks
5+
def handle(fun, dir, args)
6+
name = task_name(dir, args[:name])
7+
8+
if name.end_with?("/#{args[:name]}:#{args[:name]}")
9+
short_name = name.sub(/:.*$/, "")
10+
11+
task short_name => name
12+
13+
Rake::Task[short_name].out = Rake::Task[name].out
14+
end
15+
end
16+
end
17+
end
18+
end
19+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module CrazyFun
2+
module Mappings
3+
class RakeMappings
4+
class CreateTask < CrazyFun::Mappings::Tasks
5+
def handle(fun, dir, args)
6+
name = task_name(dir, args[:name])
7+
task name => [ args[:task_name] ]
8+
Rake::Task[name].out = args[:out]
9+
end
10+
end
11+
end
12+
end
13+
end

rake_tasks/crazy_fun/mappings/ruby_mappings.rb

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,24 @@
88
require_relative 'ruby_mappings/ruby_linter'
99
require_relative 'ruby_mappings/ruby_test'
1010

11-
class RubyMappings
12-
def add_all(fun)
13-
fun.add_mapping "ruby_library", RubyLibrary.new
11+
module CrazyFun
12+
module Mappings
13+
class RubyMappings
14+
def add_all(fun)
15+
fun.add_mapping "ruby_library", RubyLibrary.new
1416

15-
fun.add_mapping "ruby_test", CheckTestArgs.new
16-
fun.add_mapping "ruby_test", AddTestDefaults.new
17-
fun.add_mapping "ruby_test", ExpandSourceFiles.new
18-
fun.add_mapping "ruby_test", RubyTest.new
19-
fun.add_mapping "ruby_test", AddTestDependencies.new
17+
fun.add_mapping "ruby_test", CheckTestArgs.new
18+
fun.add_mapping "ruby_test", AddTestDefaults.new
19+
fun.add_mapping "ruby_test", ExpandSourceFiles.new
20+
fun.add_mapping "ruby_test", RubyTest.new
21+
fun.add_mapping "ruby_test", AddTestDependencies.new
2022

21-
fun.add_mapping "ruby_lint", ExpandSourceFiles.new
22-
fun.add_mapping "ruby_lint", RubyLinter.new
23+
fun.add_mapping "ruby_lint", ExpandSourceFiles.new
24+
fun.add_mapping "ruby_lint", RubyLinter.new
2325

24-
fun.add_mapping "rubydocs", RubyDocs.new
25-
fun.add_mapping "rubygem", RubyGem.new
26+
fun.add_mapping "rubydocs", RubyDocs.new
27+
fun.add_mapping "rubygem", RubyGem.new
28+
end
29+
end
2630
end
2731
end
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
class RubyMappings
2-
class AddTestDefaults
3-
def handle(_fun, dir, args)
4-
args[:include] = Array(args[:include])
5-
args[:include] << "#{dir}/spec"
1+
module CrazyFun
2+
module Mappings
3+
class RubyMappings
4+
class AddTestDefaults
5+
def handle(_fun, dir, args)
6+
args[:include] = Array(args[:include])
7+
args[:include] << "#{dir}/spec"
68

7-
args[:command] = args[:command] || "rspec"
9+
args[:command] = args[:command] || "rspec"
10+
end
11+
end
812
end
913
end
1014
end

rake_tasks/crazy_fun/mappings/ruby_mappings/add_test_dependencies.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
class RubyMappings
2-
class AddTestDependencies < Tasks
3-
def handle(_fun, dir, args)
4-
task = Rake::Task[task_name(dir, "#{args[:name]}-test")]
1+
module CrazyFun
2+
module Mappings
3+
class RubyMappings
4+
class AddTestDependencies < CrazyFun::Mappings::Tasks
5+
def handle(_fun, dir, args)
6+
task = Rake::Task[task_name(dir, "#{args[:name]}-test")]
57

6-
if args.has_key?(:deps)
7-
add_dependencies task, dir, args[:deps]
8+
if args.has_key?(:deps)
9+
add_dependencies task, dir, args[:deps]
10+
end
11+
end
812
end
913
end
1014
end

0 commit comments

Comments
 (0)