strapless 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -23,12 +23,12 @@ Now you should have the tasks:
23
23
 
24
24
  $ rake -T bootstrap
25
25
  (in /path/to/your/rails/project)
26
- rake db:bootstrap:dump # Create a set of fixtures from the current database
27
- rake db:bootstrap:load # Load initial fixtures (from db/data/*.yml) into the current database
26
+ rake db:bootstrap:dump[table] # Create a set of fixtures from the current database
27
+ rake db:bootstrap:load[table] # Load initial fixtures (from db/data/*.yml) into the current database
28
28
 
29
29
  If you already have data then you can dump it to the db/data folder:
30
30
 
31
- $ rake db:bootstrap:dump
31
+ $ rake db:bootstrap:dump[all]
32
32
 
33
33
  This will load all of your ActiveRecord::Base models (in your app/models) and
34
34
  generate fixtures for them. Strapless will attempt to use your to\_param so that
@@ -44,7 +44,7 @@ YAML files in your db/data folder and try to read it in.
44
44
  <span style='color:red'><strong>Warning:</strong> when loading the data from a
45
45
  fixture, any existing data will be deleted from the related table.</span>
46
46
 
47
- $ rake db:bootstrap:load
47
+ $ rake db:bootstrap:load[all]
48
48
 
49
49
  Now you have some data!
50
50
 
data/Rakefile CHANGED
@@ -1,2 +1,49 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+ =begin
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new(:test => ["generator:cleanup", "generator:simple_admin"]) do |task|
6
+ task.libs << "lib" << "test"
7
+ task.pattern = "test/**/*_test.rb"
8
+ task.verbose = true
9
+ end
10
+
11
+ generators = %w(simple_admin)
12
+
13
+ namespace :generator do
14
+ desc "Cleans up the test app before running the generator"
15
+ task :cleanup do
16
+ FileUtils.rm_rf("test/rails")
17
+ system "cd test && rails new rails"
18
+
19
+ # I don't like testing performance!
20
+ FileUtils.rm_rf("test/rails/test/performance")
21
+
22
+ # system "echo \"\" >> test/rails/config/environments/test.rb"
23
+ # system "echo \"config.gem 'thoughtbot-shoulda', :lib => 'shoulda'\" >> test/rails/config/environments/test.rb"
24
+ # system "echo \"config.gem 'thoughtbot-factory_girl', :lib => 'factory_girl'\" >> test/rails/config/environments/test.rb"
25
+
26
+ # Make a thing
27
+ system "cd test/rails && rails generate scaffold thing name:string mood:string"
28
+
29
+ FileUtils.mkdir_p("test/rails/vendor/plugins")
30
+ spreadhead_root = File.expand_path(File.dirname(__FILE__))
31
+ system("ln -s #{simple_admin_root} test/rails/vendor/plugins/simple_admin_root")
32
+ end
33
+
34
+ desc "Prepares the application with an alternate database"
35
+ task :database do
36
+ puts "== Configuring the database =================================================="
37
+ system "cp config/database.yml.sample test/rails/config/database.yml"
38
+ system "cd test/rails && rake db:migrate:reset"
39
+ end
40
+
41
+ desc "Run the simple_admin generator"
42
+ task :simple_admin do
43
+ system "cd test/rails && rails generate simple_admin && rake db:migrate db:test:prepare"
44
+ end
45
+
46
+ end
47
+
48
+ task :default => :test
49
+ =end
@@ -1,3 +1,3 @@
1
1
  module Strapless
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -23,24 +23,34 @@ namespace :db do
23
23
  end
24
24
 
25
25
  namespace :bootstrap do
26
- desc "Create a set of fixtures from the current database"
27
- task :dump => :environment do
26
+ desc "Create a set of fixtures from the specified table (or all)"
27
+ task :dump, [:table] => [:environment] do |t, args|
28
+ unless args[:table]
29
+ puts "You must indicate which tables you want to make fixtures for. If you want to make fixtures for all, use rake db:bootstrap:dump[all]"
30
+ exit
31
+ end
28
32
  require 'active_record/fixtures'
29
33
  data = File.join(Rails.root, 'db', 'data')
30
34
  Dir.mkdir(data) unless File.exists?(data)
31
35
  Dir['app/models/*'].each {|f| require f }
32
- ActiveRecord::Base.descendants.select{|m| m.table_exists? }.each do |klass|
36
+ ActiveRecord::Base.descendants.select{|m| m.table_exists? && (m.table_name == args[:table] || args[:table] == 'all') }.each do |klass|
33
37
  klass.dump_fixtures(data)
34
38
  end
35
39
  end
36
40
 
37
41
  # Task is based on mephisto's bootstrap, by Rick Olson
38
- desc "Load initial fixtures (from db/data/*.yml) into the current database"
39
- task :load => :environment do
42
+ desc "Load initial fixtures (from db/data/*.yml) into the current database (or all)"
43
+ task :load, [:table] => [:environment] do |t, args|
40
44
  require 'active_record/fixtures'
45
+ unless args[:table]
46
+ puts "You must indicate the table name for the fixtures that you want to load into your database. The fixture data will overwrite all current data in the table. If you want to load all fixtures, use db:bootstrap:load[all]"
47
+ exit
48
+ end
41
49
  Dir.glob(File.join(Rails.root, 'db', 'data', '*.yml')).each do |fixture_file|
42
- puts 'Loading fixture: ' + fixture_file
43
- Fixtures.create_fixtures("db/data", File.basename(fixture_file, '.*'))
50
+ if File.basename(fixture_file, '.*') == args[:table] || args[:table] == 'all'
51
+ puts 'Loading fixture: ' + fixture_file
52
+ Fixtures.create_fixtures("db/data", File.basename(fixture_file, '.*'))
53
+ end
44
54
  end
45
55
  end
46
56
  end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeff Rafter
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-02 00:00:00 -07:00
18
+ date: 2011-07-21 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  requirements: []
69
69
 
70
70
  rubyforge_project: strapless
71
- rubygems_version: 1.3.8
71
+ rubygems_version: 1.4.1
72
72
  signing_key:
73
73
  specification_version: 3
74
74
  summary: Simple tasks for bootstrapping the data in your rails application