LoginSignup
3
2

More than 5 years have passed since last update.

Hanamiにrake taskを追加する方法

Last updated at Posted at 2017-06-20

自分でRakeタスクを作る場合、Railsプロジェクトの場合はlib/tasks/.rakeファイルを作ります。しかしHanamiの場合はそのようなディレクトリはありません。なので一工夫する必要があります。

まず、Rakefileに以下の行を足します。

Rakefile
Dir[File.expand_path('../tasks', __FILE__) << '/*.rake'].each { |file| load file }

tasksディレクトリを作り、そこにrakeファイルを置きます。

tasks/clear_users.rake
desc "Clear users"
task clear_users: :environment do
  UserRepository.new.clear
end

:environmentをつけることでプロジェクトのエンティティなどを読み込んでくれます。

> bundle exec rake -T
rake create_user  # Clear users
rake environment  # Load the full project
rake spec         # Run RSpec code examples

認識してくれました!

以上です。

参考

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2