Skip to content

Commit c90d302

Browse files
authored
Merge pull request #356 from Dynamoid/simplify-requiring-rake-rasks-in-non-rails-environment
Simplify using Rake tasks in non-Rails environment
2 parents f51d189 + 6bf7a67 commit c90d302

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,9 +869,23 @@ end
869869

870870
## Rake Tasks
871871

872+
There are a few Rake tasks available out of the box:
873+
872874
* `rake dynamoid:create_tables`
873875
* `rake dynamoid:ping`
874876

877+
In order to use them in non-Rails application they should be required explicitly:
878+
879+
```ruby
880+
# Rakefile
881+
882+
Rake::Task.define_task(:environment)
883+
require 'dynamoid/tasks'
884+
```
885+
886+
The Rake tasks depend on `:environment` task so it should be declared
887+
as well.
888+
875889
## Test Environment
876890

877891
In test environment you will most likely want to clean the database between test runs to keep tests completely isolated. This can be achieved like so

lib/dynamoid/tasks.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
load "dynamoid/tasks/database.rake"

lib/dynamoid/tasks/database.rake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ namespace :dynamoid do
3030
end
3131

3232
msg = "Connection to DynamoDB #{success ? 'OK' : 'FAILED'}"
33-
msg << if Dynamoid.config.endpoint
33+
msg += if Dynamoid.config.endpoint
3434
" at local endpoint '#{Dynamoid.config.endpoint}'"
3535
else
3636
' at remote AWS endpoint'
3737
end
38-
msg << ", reason being '#{failure_reason}'" unless success
38+
msg += ", reason being '#{failure_reason}'" unless success
3939
puts msg
4040
end
4141
end

0 commit comments

Comments
 (0)