michaelbarton-gigantron 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,63 @@
1
+ = Gigantron: Processor of Data
2
+
3
+ == Description:
4
+
5
+ Gigantron is a simple framework for the creation and organisation of
6
+ data processing projects. Data-processing transforms are created as Rake tasks
7
+ and data is handled through ActiveRecord models.
8
+
9
+ == Install:
10
+
11
+ gem sources -a http://gems.github.com
12
+ sudo gem install michaelbarton-gigantron
13
+
14
+ == Getting started:
15
+
16
+ Create a new gigantron project at the command line specifying the name of the new project you are creating. This will create a new directory called projectname.
17
+
18
+ $ gigantron projectname
19
+
20
+ To get started using gigantron you first need to set up a database to store your data. The file database.yml.example has an example configuration to use an example sqlite3 database. Change the file database.yml.example to database.yml and the project will use these database settings.
21
+
22
+ To start storing data in the database, you'll next need to create a database model. These models act as bridge between the database tables, and the manipulating them in ruby code. Create a model using generate executable in the script directory.
23
+
24
+ $ script/generate model model_name
25
+
26
+ This creates a migration file and a model file. The migration can be used to define a database table to store your data. The model is used to access the database using object orientated programming. More information on using migrations and models can be found in the activerecord documentation.
27
+
28
+ One you have defined a model and migration, use rake at the command line to create the database. The following command will create the sqlite database.
29
+
30
+ $ rake db:migrate
31
+
32
+ You can can define and create your own rake task again using the script/generate script.
33
+
34
+ $ script/generate task task_name
35
+
36
+ More information on defining rake tasks can be found in the rake documentation. All your current rake tasks can be listed using the following command.
37
+
38
+ $ rake -T
39
+
40
+ == License:
41
+
42
+ (The MIT License)
43
+
44
+ Copyright (c) 2008 Ben Hughes
45
+
46
+ Permission is hereby granted, free of charge, to any person obtaining
47
+ a copy of this software and associated documentation files (the
48
+ 'Software'), to deal in the Software without restriction, including
49
+ without limitation the rights to use, copy, modify, merge, publish,
50
+ distribute, sublicense, and/or sell copies of the Software, and to
51
+ permit persons to whom the Software is furnished to do so, subject to
52
+ the following conditions:
53
+
54
+ The above copyright notice and this permission notice shall be
55
+ included in all copies or substantial portions of the Software.
56
+
57
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
58
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
59
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
60
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
61
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
62
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
63
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -12,7 +12,6 @@ begin
12
12
 
13
13
  s.files = FileList["[A-Z]*", "{bin,templates,lib,test}/**/*","README.markdown"]
14
14
 
15
- s.add_dependency('activesupport', '>= 2.0.2')
16
15
  s.add_dependency('templater', '>= 0.5.0')
17
16
  s.add_dependency('rake', '>= 0.8.1')
18
17
  s.add_dependency('Shoulda', '>= 1.1.1')
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 1
3
- :patch: 7
3
+ :patch: 8
4
4
  :major: 0
data/bin/gigantron CHANGED
@@ -6,19 +6,11 @@ require 'templater'
6
6
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
7
7
 
8
8
  require 'gigantron/generators/helper'
9
- require 'gigantron/generators/task_generator'
10
- require 'gigantron/generators/model_generator'
11
- require 'gigantron/generators/migration_generator'
12
9
  require 'gigantron/generators/new_project_generator'
13
10
 
14
11
  module GigantronGenerators
15
12
  extend Templater::Manifold
16
-
17
13
  add :project, NewProjectGenerator
18
- add :model, ModelGenerator
19
- add :migration, MigrationGenerator
20
- add :task, TaskGenerator
21
-
22
14
  end
23
15
 
24
- GigantronGenerators.run_cli Dir.pwd, 'gigantron', '0.1.5', ARGV
16
+ GigantronGenerators.run_cli Dir.pwd, 'gigantron', '0.1.5', ['project',ARGV].flatten
@@ -1,11 +1,13 @@
1
- require 'activesupport'
2
-
3
1
  class Templater::Generator
4
2
  def camel_case
5
- self.name.camel_case
3
+ self.name.split('_').map{|e| e.capitalize}.join
6
4
  end
7
5
  def underscore
8
- self.name.underscore
6
+ self.name.gsub(/::/, '/').
7
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
8
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
9
+ tr("-", "_").
10
+ downcase
9
11
  end
10
12
  def next_migration_num
11
13
  migrations = File.join(%W|#{self.destination_root} db migrate [0-9][0-9][0-9]_*.rb|)
@@ -8,18 +8,21 @@ class NewProjectGenerator < Templater::Generator
8
8
 
9
9
  empty_directory :root, '%root%'
10
10
  empty_directory :log, File.join('%root%','log')
11
+ empty_directory :db, File.join('%root%','db')
11
12
  empty_directory :tasks, File.join('%root%','tasks')
12
13
  empty_directory :test, File.join('%root%','test')
14
+ empty_directory :script, File.join('%root%','script')
13
15
  empty_directory :'test/models', File.join('%root%','test','models')
16
+ empty_directory :'test/tasks', File.join('%root%','test','tasks')
14
17
 
15
18
  files = [
16
19
  ['Rakefile'],
17
20
  ['initialize.rb'],
18
21
  ['database.yml.example'],
19
22
 
20
- ['tasks' ,'import.rake' ],
21
- ['test' ,'test_helper.rb' ],
22
- ['test' ,'tasks', 'test_import.rb'],
23
+ ['script' ,'generate' ],
24
+ ['tasks' ,'database.rake' ],
25
+ ['test' ,'test_helper.rb' ],
23
26
  ]
24
27
 
25
28
  files.each do |file_array|
@@ -1,10 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper.rb'
2
2
 
3
3
  class Test<%= name.camelcase %> < Test::Unit::TestCase
4
- def setup
5
- get_db_conn(GTRON_ENV)
6
- Gigantron.migrate_dbs
7
- end
8
4
 
9
5
  #replace with real tests
10
6
  should "be true" do
@@ -2,11 +2,11 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'fileutils'
4
4
 
5
- GTRON_ENV = :real
6
5
  require 'initialize'
7
-
8
6
  require 'gigantron/tasks/test'
9
- require 'gigantron/tasks/db'
10
7
 
11
8
  Dir['tasks/**/*.rake'].each {|r| load r }
12
9
 
10
+ task :environment do
11
+ Gigantron.boot :real
12
+ end
@@ -1,9 +1,6 @@
1
- # JRuby
2
- #:test:
3
- # :adapter: jdbcsqlite3
4
- # :url: jdbc:sqlite:db/test.sqlite3
5
-
6
- # Ruby 1.8
7
- #:test:
8
- # :adapter: sqlite3
9
- # :database: db/test.sqlite3
1
+ :real:
2
+ :adapter: sqlite3
3
+ :database: db/real.sqlite3
4
+ :test:
5
+ :adapter: sqlite3
6
+ :database: db/test.sqlite3
@@ -1,31 +1,32 @@
1
- # This file handles all the background initialization work that the programmer
2
- # shouldn't have to worry about.
3
- # This includes database startup, common requires, activesupport, and other
4
- # magic. I'm not sure if this is a good idea or not.
5
-
6
- # ENV works like in rails, except is :real or :test
7
- GTRON_ENV rescue GTRON_ENV = :real
8
- GTRON_ROOT = File.dirname(__FILE__)
1
+ require 'rubygems'
2
+ require 'activerecord'
9
3
 
10
- #set up autoload paths
11
- $: << "#{GTRON_ROOT}/lib/"
4
+ module Gigantron
5
+ class << self
6
+ def boot(environment)
7
+ ActiveRecord::Base.establish_connection(db[environment])
12
8
 
13
- require 'rubygems'
14
- require 'rake'
9
+ ActiveRecord::Base.logger = Logger.new(
10
+ File.join(File.dirname(__FILE__),'log',"#{environment}.log"))
15
11
 
16
- require 'active_record'
12
+ Dir[File.join(%W|#{File.dirname(__FILE__)} models ** *.rb |)].each {|r|
13
+ load r }
14
+ end
17
15
 
18
- def get_db_conn(env)
19
- env = env.to_sym
20
- #set up logging
21
- ActiveRecord::Base.logger = Logger.new("#{GTRON_ROOT}/log/#{env}.log")
16
+ def migrations
17
+ File.join(File.dirname(__FILE__), 'db', 'migrate')
18
+ end
22
19
 
23
- #load in dbs from database.yml
24
- ActiveRecord::Base.establish_connection(
25
- YAML::load(File.read("#{GTRON_ROOT}/database.yml"))[env])
20
+ def db
21
+ YAML::load(File.read(File.join(File.dirname(__FILE__),'database.yml')))
22
+ end
26
23
 
27
- #load all models
28
- Dir["#{GTRON_ROOT}/models/**/*.rb"].each {|r| load r }
24
+ def up!(version=nil)
25
+ ActiveRecord::Migrator.migrate migrations, version
26
+ end
29
27
 
30
- nil
28
+ def down!
29
+ up!
30
+ end
31
+ end
31
32
  end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'templater'
5
+
6
+ require 'gigantron/generators/helper'
7
+ require 'gigantron/generators/task_generator'
8
+ require 'gigantron/generators/model_generator'
9
+ require 'gigantron/generators/migration_generator'
10
+
11
+ module GigantronGenerators
12
+ extend Templater::Manifold
13
+
14
+ add :model, ModelGenerator
15
+ add :migration, MigrationGenerator
16
+ add :task, TaskGenerator
17
+
18
+ end
19
+
20
+ GigantronGenerators.run_cli Dir.pwd, 'gigantron', '0.1.5', ARGV
@@ -0,0 +1,16 @@
1
+ namespace :db do
2
+
3
+ desc "Drops all database tables"
4
+ task :drop => :environment do
5
+ Gigantron.down!
6
+ end
7
+
8
+ desc "Migrates database"
9
+ task :migrate => :environment do
10
+ version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
11
+ Gigantron.up! version
12
+ end
13
+
14
+ desc "Drops and remigrates the database"
15
+ task :reset => ['drop', 'migrate']
16
+ end
@@ -1,8 +1,24 @@
1
+ $:.unshift("..")
2
+
1
3
  require 'rubygems'
4
+ require 'rake'
2
5
  require 'test/unit'
3
6
  require 'shoulda'
4
7
 
5
- require 'gigantron/migrator'
6
- require File.dirname(__FILE__) + '/../initialize'
7
- silence_warnings { GTRON_ENV = :test }
8
- ENV['GTRON_ENV'] = 'test'
8
+ require 'initialize'
9
+
10
+ ActiveRecord::Migration.verbose = false
11
+
12
+ Gigantron.boot :test
13
+ Gigantron.down!
14
+ Gigantron.up!
15
+
16
+ def rake_up
17
+ Rake.application = Rake::Application.new
18
+ Rake::Task.define_task :environment
19
+ Rake.application
20
+ end
21
+
22
+ def rake_down
23
+ Rake.application = nil
24
+ end
@@ -1,4 +1,3 @@
1
1
  desc "Write a task description and write it good!"
2
- task :<%= name %> do
3
- get_db_conn(GTRON_ENV)
2
+ task :<%= name %> => :environment do
4
3
  end
@@ -2,17 +2,14 @@ require File.dirname(__FILE__) + '/../test_helper.rb'
2
2
 
3
3
  class Test<%= name.camelcase %> < Test::Unit::TestCase
4
4
  def setup
5
- get_db_conn(GTRON_ENV)
6
- @rake = Rake::Application.new
7
- Rake.application = @rake
5
+ @rake = rake_up
8
6
  load File.dirname(__FILE__) + '/../../tasks/<%= name %>.rake'
9
7
  end
10
8
 
11
9
  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
10
+ @rake["<%= name %>"].invoke
11
+
12
+ # Test expected behaviour after rake call
16
13
  assert true
17
14
  end
18
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: michaelbarton-gigantron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Hughes
@@ -9,19 +9,9 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-18 00:00:00 -07:00
12
+ date: 2009-06-03 00:00:00 -07:00
13
13
  default_executable: gigantron
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: activesupport
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 2.0.2
24
- version:
25
15
  - !ruby/object:Gem::Dependency
26
16
  name: templater
27
17
  type: :runtime
@@ -69,9 +59,9 @@ executables:
69
59
  extensions: []
70
60
 
71
61
  extra_rdoc_files:
72
- - README.markdown
62
+ - README.rdoc
73
63
  files:
74
- - README.markdown
64
+ - README.rdoc
75
65
  - Rakefile
76
66
  - VERSION.yml
77
67
  - bin/gigantron
@@ -81,22 +71,19 @@ files:
81
71
  - lib/gigantron/generators/model_generator.rb
82
72
  - lib/gigantron/generators/new_project_generator.rb
83
73
  - lib/gigantron/generators/task_generator.rb
84
- - lib/gigantron/migrator.rb
85
- - lib/gigantron/tasks/db.rb
86
74
  - lib/gigantron/tasks/test.rb
87
- - lib/gigantron/version.rb
88
75
  - templates/migration/db/migrate/migration.rb
89
76
  - templates/model/models/model.rb
90
77
  - templates/model/test/models/test_model.rb
91
78
  - templates/project/Rakefile
92
79
  - templates/project/database.yml.example
93
80
  - templates/project/initialize.rb
94
- - templates/project/tasks/import.rake
95
- - templates/project/test/tasks/test_import.rb
81
+ - templates/project/script/generate
82
+ - templates/project/tasks/database.rake
96
83
  - templates/project/test/test_helper.rb
97
84
  - templates/task/tasks/task.rake
98
85
  - templates/task/test/tasks/test_task.rb
99
- has_rdoc: false
86
+ has_rdoc: true
100
87
  homepage: http://github.com/schleyfox/gigantron
101
88
  post_install_message:
102
89
  rdoc_options:
data/README.markdown DELETED
@@ -1,75 +0,0 @@
1
- # Gigantron: Processor of Data
2
-
3
- * http://github.com/schleyfox/gigantron
4
-
5
- ## DESCRIPTION:
6
-
7
- Gigantron is a simple framework for the creation and organization of
8
- data processing projects. Data-processing transforms are created as Rake tasks
9
- and data is handled through ActiveRecord* models.
10
-
11
- * Will switch back to DataMapper once it plays nice with JRuby
12
-
13
- ## FEATURES/PROBLEMS:
14
-
15
- * Generates folder/file structure for new DP projects
16
- * Contains generators for both models and tasks
17
-
18
- ## SYNOPSIS:
19
-
20
- Use:
21
-
22
- shell> $ gigantron projectname
23
-
24
- to generate the project folder and then
25
-
26
- shell> $ script/generate model modelname
27
-
28
- OR
29
-
30
- shell> $ script/generate task taskname
31
-
32
- to add code.
33
-
34
- ## REQUIREMENTS:
35
-
36
- * RubyGems
37
- * RubiGen
38
- * Rake
39
- * ActiveRecord
40
- * ActiveSupport
41
- * Shoulda
42
-
43
- ## INSTALL:
44
-
45
- sudo gem install gigantron
46
-
47
- ## HACKING:
48
-
49
- Check out the website for a quick overview of how to fiddle with the generators
50
- behind Gigantron. http://gigantron.rubyforge.org.
51
-
52
- ## LICENSE:
53
-
54
- (The MIT License)
55
-
56
- Copyright (c) 2008 Ben Hughes
57
-
58
- Permission is hereby granted, free of charge, to any person obtaining
59
- a copy of this software and associated documentation files (the
60
- 'Software'), to deal in the Software without restriction, including
61
- without limitation the rights to use, copy, modify, merge, publish,
62
- distribute, sublicense, and/or sell copies of the Software, and to
63
- permit persons to whom the Software is furnished to do so, subject to
64
- the following conditions:
65
-
66
- The above copyright notice and this permission notice shall be
67
- included in all copies or substantial portions of the Software.
68
-
69
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
70
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
71
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
72
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
73
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
74
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
75
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,10 +0,0 @@
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
@@ -1,11 +0,0 @@
1
- require 'gigantron/migrator'
2
-
3
- namespace :db do
4
- desc "Migrate databases according to models"
5
- task :migrate do
6
- puts "Migrating your database"
7
- get_db_conn(GTRON_ENV)
8
-
9
- Gigantron.migrate_dbs
10
- end
11
- end
@@ -1,9 +0,0 @@
1
- module Gigantron #:nodoc:
2
- module VERSION #:nodoc:
3
- MAJOR = 0
4
- MINOR = 1
5
- TINY = 3
6
-
7
- STRING = [MAJOR, MINOR, TINY].join('.')
8
- end
9
- end
@@ -1,10 +0,0 @@
1
- desc "Import data into the database"
2
- task :import do
3
- # Acquire your data (e.g. from input/ or something) and parse it into
4
- # your database. Your models should probably be the ones doing the heavy
5
- # lifting on this one.
6
- #
7
- # Ex:
8
- # Foo.import_yaml(FileList["input/*.yml"].to_a)
9
- get_db_conn(ENV["GTRON_ENV"] || GTRON_ENV)
10
- end
@@ -1,23 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- class TestImport < 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/import.rake'
9
- end
10
-
11
- should "import data" 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
- @rake["import"].invoke
17
- assert true
18
- end
19
-
20
- def teardown
21
- Rake.application = nil
22
- end
23
- end