Skip to content
Permalink
Browse files

Update Rake guide

  • Loading branch information...
jodosha committed Nov 12, 2016
1 parent 4a6dcd9 commit cf6acd93541333a08c7943aacd96c5b9416f7f0e
Showing with 8 additions and 52 deletions.
  1. +8 −52 source/guides/projects/rake.md
@@ -1,5 +1,5 @@
---
title: Guides - Applications Rake Tasks
title: Guides - Rake Tasks
---

# Rake Tasks
@@ -8,19 +8,14 @@ Hanami ships with default Rake tasks that can be used as _prerequisites_ by deve

```shell
% bundle exec rake -T
rake environment # Load the full project
rake preload # Preload project configuration
rake test # Run tests
rake environment # Load the full project
rake test # Run tests (for Minitest)
rake spec # Run tests (for RSpec)
```

## Environment

This Rake task:

1. Executes all `preload` steps
2. Loads all the project code

Use this as a Rake task prerequisite when you **DO** need to access project code (eg. entities, actions, views, etc..)
Use this as a Rake task prerequisite when we need to access project code (eg. entities, actions, views, etc..)

### Example

@@ -30,54 +25,15 @@ Imagine we want to build a Rake task that is able to access project code (eg. a
# Rakefile
task clear_users: :environment do
UserRepository.clear
UserRepository.new.clear
end
```

```shell
bundle exec rake clear_users
```

<p class="notice">
The <code>:environment</code> Rake loads the entire project. It's slower than <code>:preload</code>, use it when you need to access project code.
</p>

## Preload

This Rake task is a fast way to preload:

* Gem dependencies in `Gemfile`
* The framework
* Project configurations such as env variables and application configurations (eg. `apps/web/application.rb`)

Use this as a Rake task prerequisite when you **DO NOT** need to access project code (eg. entities, actions, views, etc..)

### Example

Imagine we want to build a Rake task that prints information about our project:

```ruby
# Rakefile
task print_informations: :preload do
puts ENV['HANAMI_ENV'] # => "development"
puts ENV['DATABASE_URL'] # => "postgres://localhost/bookshelf_development"
puts defined?(User) # => nil
end
```

```shell
% bundle exec rake print_informations
"development"
"postgres://localhost/bookshelf_development"
""
```

<p class="notice">
The <code>:preload</code> Rake task preloads project and applications configurations. Use it when you need a fast way to access them.
</p>

## Test
## Test / Spec

This is the default Rake task, which runs the test suite

@@ -92,7 +48,7 @@ The following commands are equivalent:
```

<p class="convention">
The <code>:test</code> Rake task is the default.
The <code>:test</code> (or <code>:spec</code>) Rake task is the default.
</p>

## Ruby Ecosystem Compatibility

0 comments on commit cf6acd9

Please sign in to comment.
You can’t perform that action at this time.