Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What is going on with this article?
@Esfahan

sinatraでrake taskの作成

More than 3 years have passed since last update.

rake taskの作成

sinatraでrake taskを作成するメモ。

環境

  • ruby 2.2.3p173
  • sinatra-1.4.7

Rakefileの作成

Rakefileに下記を記載すると、lib/tasks/の下にある、拡張子がrakeのファイルを全て読み込んでくれる。

Rakefile
Dir.glob('lib/tasks/*.rake').each { |r| load r}

taskの作成

sample_task.rakeを作成する。

lib/tasks/sample_task.rake
namespace :sample_task do
  desc "It is sample task!!"

  task :say_hello do
    puts 'Hello!! Rake!!'
  end
end

taskが登録されているか確認

rake -Tで下記のように表示されたらOK。

$ bundle exec rake -T
rake sample_task:say_hello  # It is sample task!!

task実行

実行結果。

$ bundle exec rake sample_task:say_hello
Hello!! Rake!!

以上

3
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Esfahan
WEB系出身。現在はビッグデータの基盤構築、ETLなどがメイン。 / YouTubeで料理チャンネルやってます → https://www.youtube.com/channel/UCDnYBh2TtUAfQ0Z-tl0jTyw / ゲームもやってます -> https://www.youtube.com/channel/UCeqPhExV09EF5o8lZLO15Eg

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
3
Help us understand the problem. What is going on with this article?