strapless 0.0.1
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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +89 -0
- data/Rakefile +2 -0
- data/lib/strapless/tasks.rb +7 -0
- data/lib/strapless/version.rb +3 -0
- data/lib/strapless.rb +4 -0
- data/lib/tasks/strapless.rake +47 -0
- data/strapless.gemspec +21 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
Strapless
|
2
|
+
=========
|
3
|
+
|
4
|
+
Inspired by the ar\_fixtures plugin and the fixture loading in Rick Olson's
|
5
|
+
mephisto. Most of this was developed while working on Mateme with
|
6
|
+
Baobab Health and Partners in Health.
|
7
|
+
|
8
|
+
Overview
|
9
|
+
--------
|
10
|
+
|
11
|
+
Think of this as a better way to seed your data based on things that you
|
12
|
+
already have in your development database. It allows you to quickly load
|
13
|
+
and dump the records in your database to YAML.
|
14
|
+
|
15
|
+
Usage
|
16
|
+
-----
|
17
|
+
|
18
|
+
Add strapless to your <code>Gemfile</code> then:
|
19
|
+
|
20
|
+
$ bundle install
|
21
|
+
|
22
|
+
Now you should have the tasks:
|
23
|
+
|
24
|
+
$ rake -T bootstrap
|
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
|
28
|
+
|
29
|
+
If you already have data then you can dump it to the db/data folder:
|
30
|
+
|
31
|
+
$ rake db:bootstrap:dump
|
32
|
+
|
33
|
+
This will load all of your ActiveRecord::Base models (in your app/models) and
|
34
|
+
generate fixtures for them. Strapless will attempt to use your to\_param so that
|
35
|
+
the names are pretty. You can override the fixture\_name instance method in your
|
36
|
+
model if you want something custom.
|
37
|
+
|
38
|
+
Adding these fixtures to your repository makes a lot of sense, unless you have
|
39
|
+
crazy amounts of data.
|
40
|
+
|
41
|
+
When you get ready to load the data in, Strapless will take all of the fixture
|
42
|
+
YAML files in your db/data folder and try to read it in.
|
43
|
+
|
44
|
+
<span style='color:red'><strong>Warning:</strong> when loading the data from a
|
45
|
+
fixture, any existing data will be deleted from the related table.</span>
|
46
|
+
|
47
|
+
$ rake db:bootstrap:load
|
48
|
+
|
49
|
+
Now you have some data!
|
50
|
+
|
51
|
+
Installation
|
52
|
+
------------
|
53
|
+
|
54
|
+
If you are not using bundler just:
|
55
|
+
|
56
|
+
### [RubyGems](http://rubygems.org/)
|
57
|
+
|
58
|
+
$ gem install strapless
|
59
|
+
|
60
|
+
|
61
|
+
The tasks should automatically appear in Rails 3. If you are using Rails 2, then
|
62
|
+
you will need to load the tasks manually. In your Rakefile add
|
63
|
+
|
64
|
+
require 'strapless/tasks'
|
65
|
+
|
66
|
+
Acknowledgements
|
67
|
+
----------------
|
68
|
+
|
69
|
+
Thanks to [Nick Plante](http://twitter.com/zapnap) for prodding me to make this a
|
70
|
+
gem and for helping through some simplifications and [Eunji Choi](http://twitter.com/angelicism)
|
71
|
+
for the name "Strapless."
|
72
|
+
|
73
|
+
Contributing
|
74
|
+
------------
|
75
|
+
|
76
|
+
Once you've made your great commits:
|
77
|
+
|
78
|
+
1. [Fork][fk] Strapless.
|
79
|
+
2. Create a topic branch - `git checkout -b my_branch`
|
80
|
+
3. Push to your branch - `git push origin my_branch`
|
81
|
+
4. Create an [Issue][is] with a link to your branch
|
82
|
+
5. That's it!
|
83
|
+
|
84
|
+
Meta
|
85
|
+
----
|
86
|
+
|
87
|
+
* Code: `git clone git://github.com/jeffrafter/strapless.git`
|
88
|
+
* Home: <http://jeffrafter.github.com/strapless>
|
89
|
+
* Bugs: <http://github.com/jeffrafter/strapless/issues>
|
data/Rakefile
ADDED
data/lib/strapless.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
namespace :db do
|
2
|
+
|
3
|
+
# Loosely based on ar_fixtures, but with to_param support and some fixups
|
4
|
+
class ActiveRecord::Base
|
5
|
+
def self.dump_fixtures(path=nil)
|
6
|
+
path ||= File.expand_path("db/data/defaults/#{table_name}.yml", Rails.root)
|
7
|
+
path = File.join(path, "#{table_name}.yml") if File.directory?(path)
|
8
|
+
puts "Dumping fixtures: #{path}"
|
9
|
+
file = File.open(path, "w")
|
10
|
+
file.puts(self.find(:all).inject({}) { |hash, record|
|
11
|
+
hash.merge(record.fixture_name => record.attributes)
|
12
|
+
}.to_yaml(:SortKeys => true))
|
13
|
+
file.close
|
14
|
+
end
|
15
|
+
|
16
|
+
def fixture_name
|
17
|
+
n = "#{self.class.table_name.singularize}_#{'%05i' % to_param rescue to_param}"
|
18
|
+
n = n.downcase
|
19
|
+
n = n.gsub(/(\s|-|\/)/, '_')
|
20
|
+
n = n.gsub(/__/, '_')
|
21
|
+
n = n.gsub(/[^a-z0-9_]/, '')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
namespace :bootstrap do
|
26
|
+
desc "Create a set of fixtures from the current database"
|
27
|
+
task :dump => :environment do
|
28
|
+
require 'active_record/fixtures'
|
29
|
+
data = File.join(Rails.root, 'db', 'data')
|
30
|
+
Dir.mkdir(data) unless File.exists?(data)
|
31
|
+
Dir['app/models/*'].each {|f| require f }
|
32
|
+
ActiveRecord::Base.descendants.each do |klass|
|
33
|
+
klass.dump_fixtures(data)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# 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
|
40
|
+
require 'active_record/fixtures'
|
41
|
+
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, '.*'))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/strapless.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "strapless/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "strapless"
|
7
|
+
s.version = Strapless::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Jeff Rafter"]
|
10
|
+
s.email = ["jeffrafter@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/jeffrafter/strapless"
|
12
|
+
s.summary = %q{Simple tasks for bootstrapping the data in your rails application}
|
13
|
+
s.description = %q{To create seed data based on your development database? Run the dump tasks, commit the files, and on the next machine run the laod tasks.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "strapless"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strapless
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jeff Rafter
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-06 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: To create seed data based on your development database? Run the dump tasks, commit the files, and on the next machine run the laod tasks.
|
23
|
+
email:
|
24
|
+
- jeffrafter@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- lib/strapless.rb
|
37
|
+
- lib/strapless/tasks.rb
|
38
|
+
- lib/strapless/version.rb
|
39
|
+
- lib/tasks/strapless.rake
|
40
|
+
- strapless.gemspec
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://github.com/jeffrafter/strapless
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project: strapless
|
71
|
+
rubygems_version: 1.4.1
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Simple tasks for bootstrapping the data in your rails application
|
75
|
+
test_files: []
|
76
|
+
|