Skip to content

Commit 71684fb

Browse files
committed
Add Capistrano task
1 parent 1d75a2a commit 71684fb

5 files changed

Lines changed: 46 additions & 8 deletions

File tree

ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
0.0.2 - 2012-11-14
2+
3+
Enhancements
4+
5+
* add Capistrano task
6+
7+
0.0.1 - 2012-11-03
8+
9+
Enhancements:
10+
11+
* Initial public release

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,22 @@ Place references in 'db/reference/'
2323
References will be loaded in ascending order, so if an order is desired, prepend 000, 001, 002... etc to the filename.
2424

2525
Run with:
26-
rake easy:reference_data:load
26+
rake easy:reference_data:refresh
27+
28+
## Deployment
29+
30+
Add this line to your application's deploy.rb file:
31+
32+
require 'easy/reference_data/capistrano'
2733

2834
## Example
2935

3036
The below example ensures that there are 3 users existing in the database after running the 'rake reference_data:load'
3137

32-
### db/reference/000_users.rb
33-
Easy::ReferenceData.refresh User, :system_code, 'nigel', name: 'Nigel Ramsay', email: 'nigel.ramsay@mailinator.com'
34-
Easy::ReferenceData.refresh User, :system_code, 'fred', name: 'Fred Schmitt', email: 'fred.schmitt@mailinator.com'
35-
Easy::ReferenceData.refresh User, :system_code, 'bert', name: 'Bert Symthe', email: 'bert.smythe@mailinator.com'
38+
### db/reference/000_users.rb
39+
Easy::ReferenceData.refresh User, :system_code, 'nigel', name: 'Nigel Ramsay', email: 'nigel.ramsay@mailinator.com'
40+
Easy::ReferenceData.refresh User, :system_code, 'fred', name: 'Fred Schmitt', email: 'fred.schmitt@mailinator.com'
41+
Easy::ReferenceData.refresh User, :system_code, 'bert', name: 'Bert Symthe', email: 'bert.smythe@mailinator.com'
3642

3743
## Contributing
3844

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# To load this capistrano configuration, require 'easy/deployment/dbreference' from deploy.rb
2+
Capistrano::Configuration.instance(:must_exist).load do
3+
namespace :easy do
4+
namespace :reference_data do
5+
desc "Refresh reference data"
6+
task :refresh, :roles => :db, :only => { :primary => true } do
7+
migrate_target = fetch(:migrate_target, :latest)
8+
9+
directory = case migrate_target.to_sym
10+
when :current then current_path
11+
when :latest then latest_release
12+
else raise ArgumentError, "unknown migration target #{migrate_target.inspect}"
13+
end
14+
15+
run "cd #{directory} && RAILS_ENV=#{rails_env} bundle exec rake easy:reference_data:load"
16+
end
17+
end
18+
end
19+
20+
after 'deploy:migrate', 'easy:reference_data:refresh'
21+
end

lib/easy/reference_data/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Easy
22
module ReferenceData
3-
VERSION = "0.0.1"
3+
VERSION = "0.0.2"
44
end
55
end

lib/tasks/easy_reference_data.rake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace :easy do
22
namespace :reference_data do
3-
desc "Loads reference data values for the current environment."
4-
task :load => :environment do
3+
desc "Refreshes reference data values for the current environment."
4+
task :refresh => :environment do
55
files = Dir[File.join(Rails.root, 'db', 'reference', '*.rb')].sort
66
files += Dir[File.join(Rails.root, 'db', 'reference', Rails.env, '*.rb')].sort
77

0 commit comments

Comments
 (0)