gigantron 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +11 -0
- data/README.txt +10 -3
- data/app_generators/gigantron/gigantron_generator.rb +1 -0
- data/app_generators/gigantron/templates/database.yml +5 -6
- data/app_generators/gigantron/templates/initialize.rb +12 -4
- data/app_generators/gigantron/templates/tasks/import.rake +1 -1
- data/app_generators/gigantron/templates/test/test_helper.rb +2 -0
- data/config/hoe.rb +6 -4
- data/config/requirements.rb +1 -1
- data/gigantron_generators/mapreduce_task/USAGE +5 -0
- data/gigantron_generators/mapreduce_task/mapreduce_task_generator.rb +54 -0
- data/gigantron_generators/mapreduce_task/templates/mapreduce/mr_task.rb +22 -0
- data/gigantron_generators/mapreduce_task/templates/tasks/task.rake +5 -0
- data/gigantron_generators/mapreduce_task/templates/test/tasks/test_task.rb +22 -0
- data/gigantron_generators/migration/USAGE +5 -0
- data/gigantron_generators/migration/migration_generator.rb +61 -0
- data/gigantron_generators/migration/templates/db/migrate/migration.rb +7 -0
- data/gigantron_generators/model/model_generator.rb +3 -2
- data/gigantron_generators/model/templates/models/model.rb +1 -4
- data/gigantron_generators/model/templates/test/models/test_model.rb +1 -1
- data/gigantron_generators/task/task_generator.rb +3 -2
- data/lib/gigantron/migrator.rb +10 -0
- data/lib/gigantron/tasks/db.rb +6 -3
- data/lib/gigantron/version.rb +2 -2
- data/test/test_gigantron_generator.rb +75 -17
- data/test/test_mapreduce_task_generator.rb +50 -0
- data/test/test_migration_generator.rb +49 -0
- data/test/test_model_generator.rb +3 -3
- data/test/test_task_generator.rb +3 -3
- data/website/index.html +67 -3
- data/website/index.txt +53 -1
- metadata +66 -51
data/Manifest.txt
CHANGED
@@ -15,6 +15,14 @@ app_generators/gigantron/templates/test/test_helper.rb
|
|
15
15
|
bin/gigantron
|
16
16
|
config/hoe.rb
|
17
17
|
config/requirements.rb
|
18
|
+
gigantron_generators/mapreduce_task/USAGE
|
19
|
+
gigantron_generators/mapreduce_task/mapreduce_task_generator.rb
|
20
|
+
gigantron_generators/mapreduce_task/templates/mapreduce/mr_task.rb
|
21
|
+
gigantron_generators/mapreduce_task/templates/tasks/task.rake
|
22
|
+
gigantron_generators/mapreduce_task/templates/test/tasks/test_task.rb
|
23
|
+
gigantron_generators/migration/USAGE
|
24
|
+
gigantron_generators/migration/migration_generator.rb
|
25
|
+
gigantron_generators/migration/templates/db/migrate/migration.rb
|
18
26
|
gigantron_generators/model/USAGE
|
19
27
|
gigantron_generators/model/model_generator.rb
|
20
28
|
gigantron_generators/model/templates/models/model.rb
|
@@ -24,6 +32,7 @@ gigantron_generators/task/task_generator.rb
|
|
24
32
|
gigantron_generators/task/templates/tasks/task.rake
|
25
33
|
gigantron_generators/task/templates/test/tasks/test_task.rb
|
26
34
|
lib/gigantron.rb
|
35
|
+
lib/gigantron/migrator.rb
|
27
36
|
lib/gigantron/tasks/db.rb
|
28
37
|
lib/gigantron/tasks/test.rb
|
29
38
|
lib/gigantron/version.rb
|
@@ -39,6 +48,8 @@ test/test_generator_helper.rb
|
|
39
48
|
test/test_gigantron.rb
|
40
49
|
test/test_gigantron_generator.rb
|
41
50
|
test/test_helper.rb
|
51
|
+
test/test_mapreduce_task_generator.rb
|
52
|
+
test/test_migration_generator.rb
|
42
53
|
test/test_model_generator.rb
|
43
54
|
test/test_task_generator.rb
|
44
55
|
website/index.html
|
data/README.txt
CHANGED
@@ -7,7 +7,9 @@ http://github.com/schleyfox/gigantron
|
|
7
7
|
|
8
8
|
Gigantron is a simple framework for the creation and organization of
|
9
9
|
data processing projects. Data-processing transforms are created as Rake tasks
|
10
|
-
and data is handled through
|
10
|
+
and data is handled through ActiveRecord* models.
|
11
|
+
|
12
|
+
* Will switch back to DataMapper once it plays nice with JRuby
|
11
13
|
|
12
14
|
== FEATURES/PROBLEMS:
|
13
15
|
|
@@ -36,7 +38,7 @@ to add code.
|
|
36
38
|
* RubyGems
|
37
39
|
* RubiGen
|
38
40
|
* Rake
|
39
|
-
*
|
41
|
+
* ActiveRecord
|
40
42
|
* ActiveSupport
|
41
43
|
* Shoulda
|
42
44
|
|
@@ -44,11 +46,16 @@ to add code.
|
|
44
46
|
|
45
47
|
sudo gem install gigantron
|
46
48
|
|
49
|
+
== HACKING:
|
50
|
+
|
51
|
+
Check out the website for a quick overview of how to fiddle with the generators
|
52
|
+
behind Gigantron. http://gigantron.rubyforge.org.
|
53
|
+
|
47
54
|
== LICENSE:
|
48
55
|
|
49
56
|
(The MIT License)
|
50
57
|
|
51
|
-
Copyright (c) 2008
|
58
|
+
Copyright (c) 2008 Ben Hughes
|
52
59
|
|
53
60
|
Permission is hereby granted, free of charge, to any person obtaining
|
54
61
|
a copy of this software and associated documentation files (the
|
@@ -1,9 +1,8 @@
|
|
1
1
|
:real:
|
2
|
-
:adapter:
|
3
|
-
:
|
4
|
-
:timeout: 5000
|
2
|
+
:adapter: jdbcsqlite3
|
3
|
+
:url: jdbc:sqlite:db/real.sqlite3
|
5
4
|
|
6
5
|
:test:
|
7
|
-
:adapter:
|
8
|
-
:
|
9
|
-
|
6
|
+
:adapter: jdbcsqlite3
|
7
|
+
:url: jdbc:sqlite:db/test.sqlite3
|
8
|
+
|
@@ -15,12 +15,20 @@ require 'activesupport'
|
|
15
15
|
#set up autoload paths
|
16
16
|
Dependencies.load_paths << "#{GTRON_ROOT}/lib/"
|
17
17
|
|
18
|
-
|
19
|
-
require 'data_mapper'
|
18
|
+
require 'active_record'
|
20
19
|
|
21
20
|
|
22
21
|
def get_db_conn(env)
|
23
|
-
|
24
|
-
|
22
|
+
env = env.to_sym
|
23
|
+
#set up logging
|
24
|
+
ActiveRecord::Base.logger = Logger.new("#{GTRON_ROOT}/log/#{env}.log")
|
25
|
+
|
26
|
+
#load in dbs from database.yml
|
27
|
+
ActiveRecord::Base.establish_connection(
|
28
|
+
YAML::load(File.read("#{GTRON_ROOT}/database.yml"))[env])
|
29
|
+
|
30
|
+
#load all models
|
31
|
+
Dir["#{GTRON_ROOT}/models/**/*.rb"].each {|r| load r }
|
32
|
+
|
25
33
|
nil
|
26
34
|
end
|
data/config/hoe.rb
CHANGED
@@ -12,10 +12,7 @@ EXTRA_DEPENDENCIES = [
|
|
12
12
|
['rubigen', '>= 1.3.2'],
|
13
13
|
['rake', '>= 0.8.1'],
|
14
14
|
['Shoulda', '>= 1.1.1'],
|
15
|
-
['
|
16
|
-
['do_sqlite3', '>= 0.9.1'],
|
17
|
-
['data_objects', '>= 0.9.1'],
|
18
|
-
['dm-more', '>= 0.9.1']
|
15
|
+
['activerecord', '>= 2.0.2'],
|
19
16
|
] # An array of rubygem dependencies [name, version]
|
20
17
|
|
21
18
|
@config_file = "~/.rubyforge/user-config.yml"
|
@@ -48,7 +45,12 @@ RDOC_OPTS = ['--quiet', '--title', 'gigantron documentation',
|
|
48
45
|
"--main", "README",
|
49
46
|
"--inline-source"]
|
50
47
|
|
48
|
+
|
51
49
|
class Hoe
|
50
|
+
silence_warnings do
|
51
|
+
RUBY_FLAGS = "-I#{%w(lib ext bin test).join(File::PATH_SEPARATOR)}" +
|
52
|
+
(ENV['RUBY_DEBUG'] ? " #{ENV['RUBY_DEBUG']}" : '')
|
53
|
+
end
|
52
54
|
def extra_deps
|
53
55
|
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
54
56
|
@extra_deps
|
data/config/requirements.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
class MapreduceTaskGenerator < RubiGen::Base
|
2
|
+
|
3
|
+
default_options :author => nil
|
4
|
+
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize(runtime_args, runtime_options = {})
|
8
|
+
super
|
9
|
+
usage if args.empty?
|
10
|
+
@name = args.shift
|
11
|
+
extract_options
|
12
|
+
end
|
13
|
+
|
14
|
+
def manifest
|
15
|
+
record do |m|
|
16
|
+
# Ensure appropriate folder(s) exists
|
17
|
+
m.directory 'test/'
|
18
|
+
m.directory 'test/tasks/'
|
19
|
+
m.template "test/tasks/test_task.rb", "test/tasks/test_#{@name}.rb"
|
20
|
+
m.directory 'tasks/'
|
21
|
+
m.template "tasks/task.rake", "tasks/#{@name}.rake"
|
22
|
+
m.directory 'mapreduce/'
|
23
|
+
m.template "mapreduce/mr_task.rb", "mapreduce/mr_#{@name}.rb"
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
def banner
|
30
|
+
<<-EOS
|
31
|
+
Creates a ...
|
32
|
+
|
33
|
+
USAGE: #{$0} #{spec.name} name
|
34
|
+
EOS
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_options!(opts)
|
38
|
+
# opts.separator ''
|
39
|
+
# opts.separator 'Options:'
|
40
|
+
# For each option below, place the default
|
41
|
+
# at the top of the file next to "default_options"
|
42
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
43
|
+
# "Some comment about this option",
|
44
|
+
# "Default: none") { |options[:author]| }
|
45
|
+
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
46
|
+
end
|
47
|
+
|
48
|
+
def extract_options
|
49
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
50
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
51
|
+
# raw instance variable value.
|
52
|
+
# @author = options[:author]
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class MapReduce<%= name.capitalize %>
|
2
|
+
include SkynetDebugger
|
3
|
+
|
4
|
+
def self.run
|
5
|
+
job = Skynet::Job.new(
|
6
|
+
:mappers => 2, #change to whatever is a good number
|
7
|
+
:reducers => 1, #same
|
8
|
+
:map_reduce_class => self,
|
9
|
+
:map_data => [] #acquire your data!
|
10
|
+
)
|
11
|
+
job.run
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.map(profiles)
|
15
|
+
#map code
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.reduce(pairs)
|
19
|
+
#reduce code
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
class Test<%= name.capitalize %> < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
get_db_conn(GTRON_ENV)
|
6
|
+
@rake = Rake::Application.new
|
7
|
+
Rake.application = @rake
|
8
|
+
load File.dirname(__FILE__) + '/../../tasks/<%= name %>.rake'
|
9
|
+
end
|
10
|
+
|
11
|
+
should "be true" do
|
12
|
+
# Testing rake is a bit different
|
13
|
+
# http://blog.nicksieger.com/articles/2007/06/11/test-your-rake-tasks
|
14
|
+
# Example:
|
15
|
+
# @rake["task_name"].invoke
|
16
|
+
assert true
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
Rake.application = nil
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class MigrationGenerator < RubiGen::Base
|
2
|
+
|
3
|
+
default_options :author => nil
|
4
|
+
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize(runtime_args, runtime_options = {})
|
8
|
+
super
|
9
|
+
usage if args.empty?
|
10
|
+
@name = args.shift
|
11
|
+
extract_options
|
12
|
+
end
|
13
|
+
|
14
|
+
def manifest
|
15
|
+
record do |m|
|
16
|
+
# Ensure appropriate folder(s) exists
|
17
|
+
m.directory "db/"
|
18
|
+
m.directory "db/migrate/"
|
19
|
+
m.template "db/migrate/migration.rb",
|
20
|
+
"db/migrate/#{next_migration_num}_#{name.underscore}.rb"
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
def banner
|
27
|
+
<<-EOS
|
28
|
+
Creates a ...
|
29
|
+
|
30
|
+
USAGE: #{$0} #{spec.name} name
|
31
|
+
EOS
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_options!(opts)
|
35
|
+
# opts.separator ''
|
36
|
+
# opts.separator 'Options:'
|
37
|
+
# For each option below, place the default
|
38
|
+
# at the top of the file next to "default_options"
|
39
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
40
|
+
# "Some comment about this option",
|
41
|
+
# "Default: none") { |options[:author]| }
|
42
|
+
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
43
|
+
end
|
44
|
+
|
45
|
+
def extract_options
|
46
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
47
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
48
|
+
# raw instance variable value.
|
49
|
+
# @author = options[:author]
|
50
|
+
end
|
51
|
+
|
52
|
+
def next_migration_num
|
53
|
+
#blegh, catalog existing migrations, find next
|
54
|
+
current = Dir.glob(
|
55
|
+
"#{@destination_root}/db/migrate/[0-9][0-9][0-9]_*.rb").map{|x|
|
56
|
+
/(\d{3})_.*\.rb/.match(x)[1].to_i
|
57
|
+
}.max
|
58
|
+
current ||= 0
|
59
|
+
"%03d" % current.succ
|
60
|
+
end
|
61
|
+
end
|
@@ -14,11 +14,12 @@ class ModelGenerator < RubiGen::Base
|
|
14
14
|
def manifest
|
15
15
|
record do |m|
|
16
16
|
m.directory "models/"
|
17
|
-
m.template "models/model.rb", "models/#{@name}.rb"
|
17
|
+
m.template "models/model.rb", "models/#{@name.underscore}.rb"
|
18
18
|
|
19
19
|
m.directory "test/"
|
20
20
|
m.directory "test/models/"
|
21
|
-
m.template "test/models/test_model.rb",
|
21
|
+
m.template "test/models/test_model.rb",
|
22
|
+
"test/models/test_#{name.underscore}.rb"
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
@@ -14,10 +14,11 @@ class TaskGenerator < RubiGen::Base
|
|
14
14
|
def manifest
|
15
15
|
record do |m|
|
16
16
|
m.directory "tasks/"
|
17
|
-
m.template "tasks/task.rake", "tasks/#{@name}.rake"
|
17
|
+
m.template "tasks/task.rake", "tasks/#{@name.underscore}.rake"
|
18
18
|
m.directory "test/"
|
19
19
|
m.directory "test/tasks/"
|
20
|
-
m.template "test/tasks/test_task.rb",
|
20
|
+
m.template "test/tasks/test_task.rb",
|
21
|
+
"test/tasks/test_#{@name.underscore}.rb"
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
# simple function to handle migrating Gigantron databases
|
3
|
+
module Gigantron
|
4
|
+
def self.migrate_dbs
|
5
|
+
ActiveRecord::Migration.verbose =
|
6
|
+
ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
|
7
|
+
ActiveRecord::Migrator.migrate("#{GTRON_ROOT}/db/migrate/",
|
8
|
+
ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
|
9
|
+
end
|
10
|
+
end
|
data/lib/gigantron/tasks/db.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
require 'gigantron/migrator'
|
2
|
+
|
1
3
|
namespace :db do
|
2
|
-
desc "
|
3
|
-
task :
|
4
|
+
desc "Migrate databases according to models"
|
5
|
+
task :migrate do
|
4
6
|
puts "Migrating your database"
|
5
7
|
get_db_conn(GTRON_ENV)
|
6
|
-
|
8
|
+
|
9
|
+
Gigantron.migrate_dbs
|
7
10
|
end
|
8
11
|
end
|
data/lib/gigantron/version.rb
CHANGED
@@ -11,21 +11,7 @@ class TestGigantronGenerator < Test::Unit::TestCase
|
|
11
11
|
bare_teardown
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
# assert_generated_file(name, &block) # block passed the file contents
|
16
|
-
# assert_directory_exists(name)
|
17
|
-
# assert_generated_class(name, &block)
|
18
|
-
# assert_generated_module(name, &block)
|
19
|
-
# assert_generated_test_for(name, &block)
|
20
|
-
# The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
|
21
|
-
# assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
|
22
|
-
#
|
23
|
-
# Other helper methods are:
|
24
|
-
# app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
|
25
|
-
# bare_setup - place this in setup method to create the APP_ROOT folder for each test
|
26
|
-
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
|
27
|
-
|
28
|
-
def test_generator_without_options
|
14
|
+
should "generate correct directory and file structure" do
|
29
15
|
run_generator('gigantron', [APP_ROOT], sources)
|
30
16
|
assert_directory_exists "tasks/"
|
31
17
|
assert_generated_file "tasks/import.rake"
|
@@ -43,14 +29,86 @@ class TestGigantronGenerator < Test::Unit::TestCase
|
|
43
29
|
assert_generated_file "Rakefile"
|
44
30
|
assert_generated_file "initialize.rb"
|
45
31
|
end
|
32
|
+
|
33
|
+
context "Generated project" do
|
34
|
+
setup do
|
35
|
+
run_generator('gigantron', [APP_ROOT], sources)
|
36
|
+
|
37
|
+
silence_warnings { GTRON_ENV = :test }
|
38
|
+
ENV["GTRON_ENV"] = "test"
|
39
|
+
|
40
|
+
initialize_gigantron
|
41
|
+
configure_gigantron_db
|
42
|
+
get_db_conn(GTRON_ENV)
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with migration and model" do
|
46
|
+
setup do
|
47
|
+
run_generator('model', ['Foo'], sources)
|
48
|
+
|
49
|
+
create_test_migration
|
50
|
+
get_db_conn(GTRON_ENV)
|
51
|
+
|
52
|
+
ENV["VERBOSE"] = "false"
|
53
|
+
Gigantron.migrate_dbs
|
54
|
+
end
|
55
|
+
|
56
|
+
should "create test db" do
|
57
|
+
assert File.exists?("#{APP_ROOT}/db/test.sqlite3")
|
58
|
+
end
|
59
|
+
|
60
|
+
should "create table foos and populate" do
|
61
|
+
assert_equal Foo.find(:all).size, 2
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "with Rake tasks" do
|
66
|
+
setup do
|
67
|
+
@rake = Rake::Application.new
|
68
|
+
Rake.application = @rake
|
69
|
+
load "#{APP_ROOT}/tasks/import.rake"
|
70
|
+
end
|
71
|
+
|
72
|
+
teardown { Rake.application = nil }
|
73
|
+
|
74
|
+
should "run empty import task" do
|
75
|
+
assert @rake['import'].invoke
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
46
79
|
|
47
80
|
private
|
48
81
|
def sources
|
49
|
-
[RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
|
50
|
-
]
|
82
|
+
[RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path)),
|
83
|
+
RubiGen::PathSource.new(:test_components, File.join(File.dirname(__FILE__),"..", "gigantron_generators"))]
|
51
84
|
end
|
52
85
|
|
53
86
|
def generator_path
|
54
87
|
"app_generators"
|
55
88
|
end
|
89
|
+
|
90
|
+
def initialize_gigantron
|
91
|
+
require File.join(APP_ROOT, "initialize.rb")
|
92
|
+
require 'gigantron/migrator'
|
93
|
+
end
|
94
|
+
|
95
|
+
def configure_gigantron_db
|
96
|
+
if !File.exists? "test/template_database.yml"
|
97
|
+
flunk "No Database Configuration. Configure test DB in 'test/template_database.yml'!"
|
98
|
+
end
|
99
|
+
File.open("#{APP_ROOT}/database.yml", "w") do |f|
|
100
|
+
f.write ERB.new(
|
101
|
+
File.read("test/template_database.yml")).result(binding)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def create_test_migration
|
106
|
+
if !File.exists? "#{APP_ROOT}/db/migrate/001_create_foos.rb"
|
107
|
+
run_generator('migration', ['CreateFoos'], sources)
|
108
|
+
end
|
109
|
+
|
110
|
+
assert File.exists?("#{APP_ROOT}/db/migrate/001_create_foos.rb")
|
111
|
+
FileUtils.cp("test/template_migration.rb",
|
112
|
+
"#{APP_ROOT}/db/migrate/001_create_foos.rb")
|
113
|
+
end
|
56
114
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
|
2
|
+
|
3
|
+
|
4
|
+
class TestMapreduceTaskGenerator < Test::Unit::TestCase
|
5
|
+
include RubiGen::GeneratorTestHelper
|
6
|
+
|
7
|
+
def setup
|
8
|
+
bare_setup
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
bare_teardown
|
13
|
+
end
|
14
|
+
|
15
|
+
# Some generator-related assertions:
|
16
|
+
# assert_generated_file(name, &block) # block passed the file contents
|
17
|
+
# assert_directory_exists(name)
|
18
|
+
# assert_generated_class(name, &block)
|
19
|
+
# assert_generated_module(name, &block)
|
20
|
+
# assert_generated_test_for(name, &block)
|
21
|
+
# The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
|
22
|
+
# assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
|
23
|
+
#
|
24
|
+
# Other helper methods are:
|
25
|
+
# app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
|
26
|
+
# bare_setup - place this in setup method to create the APP_ROOT folder for each test
|
27
|
+
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
|
28
|
+
|
29
|
+
def test_generator_without_options
|
30
|
+
name = "myapp"
|
31
|
+
run_generator('mapreduce_task', [name], sources)
|
32
|
+
assert_directory_exists "mapreduce/"
|
33
|
+
assert_generated_file "mapreduce/mr_#{name}.rb"
|
34
|
+
assert_directory_exists "tasks/"
|
35
|
+
assert_generated_file "tasks/#{name}.rake"
|
36
|
+
assert_directory_exists "test/"
|
37
|
+
assert_directory_exists "test/tasks/"
|
38
|
+
assert_generated_file "test/tasks/test_#{name}.rb"
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def sources
|
43
|
+
[RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
|
44
|
+
]
|
45
|
+
end
|
46
|
+
|
47
|
+
def generator_path
|
48
|
+
"gigantron_generators"
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
|
2
|
+
|
3
|
+
|
4
|
+
class TestMigrationGenerator < Test::Unit::TestCase
|
5
|
+
include RubiGen::GeneratorTestHelper
|
6
|
+
|
7
|
+
def setup
|
8
|
+
bare_setup
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
bare_teardown
|
13
|
+
end
|
14
|
+
|
15
|
+
# Some generator-related assertions:
|
16
|
+
# assert_generated_file(name, &block) # block passed the file contents
|
17
|
+
# assert_directory_exists(name)
|
18
|
+
# assert_generated_class(name, &block)
|
19
|
+
# assert_generated_module(name, &block)
|
20
|
+
# assert_generated_test_for(name, &block)
|
21
|
+
# The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
|
22
|
+
# assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
|
23
|
+
#
|
24
|
+
# Other helper methods are:
|
25
|
+
# app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
|
26
|
+
# bare_setup - place this in setup method to create the APP_ROOT folder for each test
|
27
|
+
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
|
28
|
+
|
29
|
+
def test_generator_without_options
|
30
|
+
name = "CreateFoo"
|
31
|
+
run_generator('migration', [name], sources)
|
32
|
+
assert_directory_exists "db/"
|
33
|
+
assert_directory_exists "db/migrate/"
|
34
|
+
assert_generated_file "db/migrate/001_create_foo.rb"
|
35
|
+
name2 = "AlterFoo"
|
36
|
+
run_generator('migration', [name2], sources)
|
37
|
+
assert_generated_file "db/migrate/002_alter_foo.rb"
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def sources
|
42
|
+
[RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
|
43
|
+
]
|
44
|
+
end
|
45
|
+
|
46
|
+
def generator_path
|
47
|
+
"gigantron_generators"
|
48
|
+
end
|
49
|
+
end
|
@@ -27,13 +27,13 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
27
27
|
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
|
28
28
|
|
29
29
|
def test_generator_without_options
|
30
|
-
name = "
|
30
|
+
name = "FooBaz"
|
31
31
|
run_generator('model', [name], sources)
|
32
32
|
assert_directory_exists "models/"
|
33
|
-
assert_generated_file "models
|
33
|
+
assert_generated_file "models/foo_baz.rb"
|
34
34
|
assert_directory_exists "test/"
|
35
35
|
assert_directory_exists "test/models/"
|
36
|
-
assert_generated_file "test/models/
|
36
|
+
assert_generated_file "test/models/test_foo_baz.rb"
|
37
37
|
end
|
38
38
|
|
39
39
|
private
|
data/test/test_task_generator.rb
CHANGED
@@ -27,13 +27,13 @@ class TestTaskGenerator < Test::Unit::TestCase
|
|
27
27
|
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
|
28
28
|
|
29
29
|
def test_generator_without_options
|
30
|
-
name = "
|
30
|
+
name = "FooBar"
|
31
31
|
run_generator('task', [name], sources)
|
32
32
|
assert_directory_exists "tasks/"
|
33
|
-
assert_generated_file "tasks
|
33
|
+
assert_generated_file "tasks/foo_bar.rake"
|
34
34
|
assert_directory_exists "test/"
|
35
35
|
assert_directory_exists "test/tasks"
|
36
|
-
assert_generated_file "test/tasks/
|
36
|
+
assert_generated_file "test/tasks/test_foo_bar.rb"
|
37
37
|
end
|
38
38
|
|
39
39
|
private
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>Gigantron: Processor of Data</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/gigantron"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/gigantron" class="numbers">0.0
|
36
|
+
<a href="http://rubyforge.org/projects/gigantron" class="numbers">0.1.0</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ ‘gigantron’</h1>
|
39
39
|
|
@@ -43,7 +43,8 @@
|
|
43
43
|
|
44
44
|
<p>Gigantron is a simple framework for the creation and organization of
|
45
45
|
data processing projects. Data-processing transforms are created as Rake tasks
|
46
|
-
and data is handled through DataMapper
|
46
|
+
and data is handled through ActiveRecord models. (DataMapper was the original
|
47
|
+
plan, but it has problems playing nicely with JRuby for now).</p>
|
47
48
|
|
48
49
|
|
49
50
|
<p>Ruby is great for exploratory data processing. Data processing projects tend
|
@@ -110,6 +111,67 @@ shell> $ script/generate task modis_to_kml
|
|
110
111
|
ActiveSupport for convenience.</p>
|
111
112
|
|
112
113
|
|
114
|
+
<h2>Hacking</h2>
|
115
|
+
|
116
|
+
|
117
|
+
<p>Gigantron is super minimal now, so modifying it is pretty easy. The gigantron
|
118
|
+
application generator (that which is invoked by the <code>gigantron</code> command) lives
|
119
|
+
in <code>app_generators/gigantron/</code>. The template files and the template dir
|
120
|
+
structure are in <code>app_generators/gigantron/templates/</code>. When adding new
|
121
|
+
templates, directories, or files, add the names first to the tests in
|
122
|
+
<code>test/test_gigantron_generator.rb</code>, then the stubs to
|
123
|
+
<code>app_generators/gigantron/templates</code>, and then finally describe them in the
|
124
|
+
manifest section of <code>app_generators/gigantron/gigantron_generator.rb</code>. It
|
125
|
+
should look something like</p>
|
126
|
+
|
127
|
+
|
128
|
+
<p><pre class='syntax'>
|
129
|
+
<span class="keyword">def </span><span class="method">manifest</span>
|
130
|
+
<span class="ident">record</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">m</span><span class="punct">|</span>
|
131
|
+
<span class="punct">...</span>
|
132
|
+
<span class="ident">m</span><span class="punct">.</span><span class="ident">file</span> <span class="punct">"</span><span class="string">new_file</span><span class="punct">",</span> <span class="punct">"</span><span class="string">new_file</span><span class="punct">"</span> <span class="comment">#straight file copy</span>
|
133
|
+
<span class="ident">m</span><span class="punct">.</span><span class="ident">directory</span> <span class="punct">"</span><span class="string">my_new_dir</span><span class="punct">"</span> <span class="comment">#create directory</span>
|
134
|
+
<span class="ident">m</span><span class="punct">.</span><span class="ident">template</span> <span class="punct">"</span><span class="string">new_thing</span><span class="punct">",</span> <span class="punct">"</span><span class="string">new_thing</span><span class="punct">"</span> <span class="comment">#runs file through ERB when copying</span>
|
135
|
+
<span class="keyword">end</span>
|
136
|
+
<span class="keyword">end</span>
|
137
|
+
</pre></p>
|
138
|
+
|
139
|
+
|
140
|
+
<p>It might be handy to know that in <code>gigantron_generator.rb</code> the name provided to the generator can be referenced as <code>@name</code>. This can be used like</p>
|
141
|
+
|
142
|
+
|
143
|
+
<p><pre class='syntax'>
|
144
|
+
<span class="ident">record</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">m</span><span class="punct">|</span>
|
145
|
+
<span class="ident">m</span><span class="punct">.</span><span class="ident">file</span> <span class="punct">"</span><span class="string">renamed_file</span><span class="punct">",</span> <span class="punct">"</span><span class="string"><span class="expr">#{@name}</span>_file</span><span class="punct">"</span>
|
146
|
+
<span class="keyword">end</span>
|
147
|
+
</pre></p>
|
148
|
+
|
149
|
+
|
150
|
+
<p>The same value is available to your templates as just <code>name</code>. You can template
|
151
|
+
a file like</p>
|
152
|
+
|
153
|
+
|
154
|
+
<p><pre class='syntax'>
|
155
|
+
<span class="keyword">class </span><span class="class">Test</span><span class="punct"><%=</span><span class="string"> name.capitalize %> < Test::Unit::TestCase
|
156
|
+
...
|
157
|
+
end<span class="normal">
|
158
|
+
</span></span></pre></p>
|
159
|
+
|
160
|
+
|
161
|
+
<p>The same process applies to the model and task generator for gigantron
|
162
|
+
projects. These generators live in <code>gigantron_generators/</code>. Modifying them
|
163
|
+
is exactly the same as modifying the application generator.</p>
|
164
|
+
|
165
|
+
|
166
|
+
<p>All of this is pretty vanilla <a href="http://rubigen.rubyforge.org">RubiGen</a>, so if in doubt, check out the docos on that fine piece of work.</p>
|
167
|
+
|
168
|
+
|
169
|
+
<p>The only other place for code in Gigantron is is <code>lib/gigantron/tasks/</code> where a few boilerplate test and db tasks live. I think I ripped the test tasks off of rails.</p>
|
170
|
+
|
171
|
+
|
172
|
+
<p>If you have any questions, do contact me. I am interested in anything that will make Gigantron suck less and be useful to people.</p>
|
173
|
+
|
174
|
+
|
113
175
|
<h2>How to submit patches</h2>
|
114
176
|
|
115
177
|
|
@@ -124,6 +186,8 @@ ActiveSupport for convenience.</p>
|
|
124
186
|
|
125
187
|
|
126
188
|
<pre>cd gigantron
|
189
|
+
cp test/template_database.yml.example test/template_database.yml
|
190
|
+
vim test/template_database.yml
|
127
191
|
rake test
|
128
192
|
rake install_gem</pre>
|
129
193
|
|
@@ -138,7 +202,7 @@ rake install_gem</pre>
|
|
138
202
|
|
139
203
|
<p>Comments are welcome. Send an email to <a href="mailto:ben@pixelmachine.org">Ben Hughes</a></p>
|
140
204
|
<p class="coda">
|
141
|
-
<a href="ben@pixelmachine.org">Ben Hughes</a>,
|
205
|
+
<a href="ben@pixelmachine.org">Ben Hughes</a>, 18th June 2008<br>
|
142
206
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
143
207
|
</p>
|
144
208
|
</div>
|
data/website/index.txt
CHANGED
@@ -7,7 +7,8 @@ h2. What
|
|
7
7
|
|
8
8
|
Gigantron is a simple framework for the creation and organization of
|
9
9
|
data processing projects. Data-processing transforms are created as Rake tasks
|
10
|
-
and data is handled through
|
10
|
+
and data is handled through ActiveRecord models. (DataMapper was the original
|
11
|
+
plan, but it has problems playing nicely with JRuby for now).
|
11
12
|
|
12
13
|
Ruby is great for exploratory data processing. Data processing projects tend
|
13
14
|
to grow up and encompass large numbers of random scripts and input files. It
|
@@ -67,6 +68,55 @@ shell> $ script/generate task modis_to_kml
|
|
67
68
|
One can edit these files to add functionality. Gigantron by default includes
|
68
69
|
ActiveSupport for convenience.
|
69
70
|
|
71
|
+
h2. Hacking
|
72
|
+
|
73
|
+
Gigantron is super minimal now, so modifying it is pretty easy. The gigantron
|
74
|
+
application generator (that which is invoked by the @gigantron@ command) lives
|
75
|
+
in @app_generators/gigantron/@. The template files and the template dir
|
76
|
+
structure are in @app_generators/gigantron/templates/@. When adding new
|
77
|
+
templates, directories, or files, add the names first to the tests in
|
78
|
+
@test/test_gigantron_generator.rb@, then the stubs to
|
79
|
+
@app_generators/gigantron/templates@, and then finally describe them in the
|
80
|
+
manifest section of @app_generators/gigantron/gigantron_generator.rb@. It
|
81
|
+
should look something like
|
82
|
+
|
83
|
+
<pre syntax="ruby">
|
84
|
+
def manifest
|
85
|
+
record do |m|
|
86
|
+
...
|
87
|
+
m.file "new_file", "new_file" #straight file copy
|
88
|
+
m.directory "my_new_dir" #create directory
|
89
|
+
m.template "new_thing", "new_thing" #runs file through ERB when copying
|
90
|
+
end
|
91
|
+
end
|
92
|
+
</pre>
|
93
|
+
|
94
|
+
It might be handy to know that in @gigantron_generator.rb@ the name provided to the generator can be referenced as @@name@. This can be used like
|
95
|
+
|
96
|
+
<pre syntax="ruby">
|
97
|
+
record do |m|
|
98
|
+
m.file "renamed_file", "#{@name}_file"
|
99
|
+
end
|
100
|
+
</pre>
|
101
|
+
|
102
|
+
The same value is available to your templates as just @name@. You can template
|
103
|
+
a file like
|
104
|
+
|
105
|
+
<pre syntax="ruby">
|
106
|
+
class Test<%%= name.capitalize %> < Test::Unit::TestCase
|
107
|
+
...
|
108
|
+
end
|
109
|
+
</pre>
|
110
|
+
|
111
|
+
The same process applies to the model and task generator for gigantron
|
112
|
+
projects. These generators live in @gigantron_generators/@. Modifying them
|
113
|
+
is exactly the same as modifying the application generator.
|
114
|
+
|
115
|
+
All of this is pretty vanilla "RubiGen":http://rubigen.rubyforge.org, so if in doubt, check out the docos on that fine piece of work.
|
116
|
+
|
117
|
+
The only other place for code in Gigantron is is @lib/gigantron/tasks/@ where a few boilerplate test and db tasks live. I think I ripped the test tasks off of rails.
|
118
|
+
|
119
|
+
If you have any questions, do contact me. I am interested in anything that will make Gigantron suck less and be useful to people.
|
70
120
|
|
71
121
|
h2. How to submit patches
|
72
122
|
|
@@ -79,6 +129,8 @@ h2. How to submit patches
|
|
79
129
|
h3. Build and test instructions
|
80
130
|
|
81
131
|
<pre>cd gigantron
|
132
|
+
cp test/template_database.yml.example test/template_database.yml
|
133
|
+
vim test/template_database.yml
|
82
134
|
rake test
|
83
135
|
rake install_gem</pre>
|
84
136
|
|
metadata
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
2
|
-
|
3
|
-
specification_version: 1
|
4
|
-
name: gigantron
|
5
|
-
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.1
|
7
|
-
date: 2008-06-01 00:00:00 -04:00
|
8
|
-
summary: description of gem
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email:
|
12
|
-
- ben@pixelmachine.org
|
13
|
-
homepage: http://gigantron.rubyforge.org
|
14
|
-
rubyforge_project: gigantron
|
15
|
-
description: description of gem
|
16
|
-
autorequire:
|
17
|
-
default_executable:
|
18
|
-
bindir: bin
|
19
|
-
has_rdoc: true
|
20
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
21
3
|
requirements:
|
22
|
-
- -
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 0
|
4
|
+
- - '>='
|
5
|
+
- !ruby/object:Gem::Version
|
6
|
+
version: !str 0
|
25
7
|
version:
|
26
|
-
|
27
|
-
|
28
|
-
cert_chain:
|
8
|
+
email:
|
9
|
+
- ben@pixelmachine.org
|
10
|
+
cert_chain: []
|
11
|
+
summary: description of gem
|
29
12
|
post_install_message: |
|
30
13
|
|
31
14
|
For more information on gigantron, see http://gigantron.rubyforge.org
|
32
|
-
|
33
|
-
Do you enjoy the tangy zip of miracle whip?
|
34
15
|
|
35
|
-
|
36
|
-
|
16
|
+
Do you enjoy the tangy zip of miracle whip?
|
17
|
+
extra_rdoc_files:
|
18
|
+
- History.txt
|
19
|
+
- License.txt
|
20
|
+
- Manifest.txt
|
21
|
+
- PostInstall.txt
|
22
|
+
- README.txt
|
23
|
+
- website/index.txt
|
24
|
+
homepage: http://gigantron.rubyforge.org
|
25
|
+
signing_key:
|
26
|
+
name: gigantron
|
27
|
+
rdoc_options:
|
28
|
+
- --main
|
29
|
+
- README.txt
|
30
|
+
autorequire:
|
31
|
+
rubyforge_project: gigantron
|
32
|
+
executables:
|
33
|
+
- gigantron
|
34
|
+
description: description of gem
|
35
|
+
specification_version: 2
|
36
|
+
default_executable:
|
37
37
|
files:
|
38
38
|
- History.txt
|
39
39
|
- License.txt
|
@@ -52,6 +52,14 @@ files:
|
|
52
52
|
- bin/gigantron
|
53
53
|
- config/hoe.rb
|
54
54
|
- config/requirements.rb
|
55
|
+
- gigantron_generators/mapreduce_task/USAGE
|
56
|
+
- gigantron_generators/mapreduce_task/mapreduce_task_generator.rb
|
57
|
+
- gigantron_generators/mapreduce_task/templates/mapreduce/mr_task.rb
|
58
|
+
- gigantron_generators/mapreduce_task/templates/tasks/task.rake
|
59
|
+
- gigantron_generators/mapreduce_task/templates/test/tasks/test_task.rb
|
60
|
+
- gigantron_generators/migration/USAGE
|
61
|
+
- gigantron_generators/migration/migration_generator.rb
|
62
|
+
- gigantron_generators/migration/templates/db/migrate/migration.rb
|
55
63
|
- gigantron_generators/model/USAGE
|
56
64
|
- gigantron_generators/model/model_generator.rb
|
57
65
|
- gigantron_generators/model/templates/models/model.rb
|
@@ -61,6 +69,7 @@ files:
|
|
61
69
|
- gigantron_generators/task/templates/tasks/task.rake
|
62
70
|
- gigantron_generators/task/templates/test/tasks/test_task.rb
|
63
71
|
- lib/gigantron.rb
|
72
|
+
- lib/gigantron/migrator.rb
|
64
73
|
- lib/gigantron/tasks/db.rb
|
65
74
|
- lib/gigantron/tasks/test.rb
|
66
75
|
- lib/gigantron/version.rb
|
@@ -76,6 +85,8 @@ files:
|
|
76
85
|
- test/test_gigantron.rb
|
77
86
|
- test/test_gigantron_generator.rb
|
78
87
|
- test/test_helper.rb
|
88
|
+
- test/test_mapreduce_task_generator.rb
|
89
|
+
- test/test_migration_generator.rb
|
79
90
|
- test/test_model_generator.rb
|
80
91
|
- test/test_task_generator.rb
|
81
92
|
- website/index.html
|
@@ -83,28 +94,32 @@ files:
|
|
83
94
|
- website/javascripts/rounded_corners_lite.inc.js
|
84
95
|
- website/stylesheets/screen.css
|
85
96
|
- website/template.html.erb
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: !str 0
|
102
|
+
version:
|
103
|
+
extensions: []
|
104
|
+
rubygems_version: 1.1.1
|
105
|
+
requirements: []
|
106
|
+
authors:
|
107
|
+
- Ben Hughes
|
108
|
+
date: 2008-06-18 04:00:00 +00:00
|
109
|
+
platform: ruby
|
86
110
|
test_files:
|
87
|
-
- test/test_generator_helper.rb
|
88
|
-
- test/test_gigantron.rb
|
89
|
-
- test/test_task_generator.rb
|
90
|
-
- test/test_gigantron_generator.rb
|
91
111
|
- test/test_model_generator.rb
|
112
|
+
- test/test_migration_generator.rb
|
92
113
|
- test/test_helper.rb
|
93
|
-
|
94
|
-
-
|
95
|
-
-
|
96
|
-
|
97
|
-
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
-
|
102
|
-
- website/index.txt
|
103
|
-
executables:
|
104
|
-
- gigantron
|
105
|
-
extensions: []
|
106
|
-
|
107
|
-
requirements: []
|
108
|
-
|
114
|
+
- test/test_task_generator.rb
|
115
|
+
- test/test_gigantron_generator.rb
|
116
|
+
- test/test_mapreduce_task_generator.rb
|
117
|
+
- test/test_gigantron.rb
|
118
|
+
- test/test_generator_helper.rb
|
119
|
+
version: !ruby/object:Gem::Version
|
120
|
+
version: 0.1.0
|
121
|
+
require_paths:
|
122
|
+
- lib
|
109
123
|
dependencies: []
|
110
|
-
|
124
|
+
bindir: bin
|
125
|
+
has_rdoc: true
|