1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

第八回講義メモ

Last updated at Posted at 2020-12-31

!Mac OS X-10.15.7 !ruby-2.6.3p62

Rake

rakeはmakeのantのruby版.以下に典型的な礼を示す.

task :default do
  system 'rake -T'
  exit
end

desc 'hello NAME'
task :hello do
  name = ARGV[1]
  puts "Hello #{name}!"
  exit
end

これをRakefileに書き込むことで,

> rake

とすることで, taskを表示させることができる.

System call

Rakefileに最も記述する多い関数はsystemらしい.たとえば, gitのコマンドをいちいち覚えるのがめんどくさいものをメモしておきます.

desc 'git push'
task :push2 do
  ["git add -A",
   "git commit -m \'hoge\'",
   "git pull origin main",
   "git push origin main"].each do |comm|
    p comm  #puts comm.green after require 'colorize' 
    system comm
  end
  exit
end

Command line

systemで使える外部のコマンドは遅いので, 別の組み込み関数を使用するらしい.rubyにも用意されているらしく, 以下例.

desc 'make list'
task :mk_list do
  # system 'ls -1 ../members/*/README.org'
  Dir.glob('../members/*/README.org')[0..4].each do |file|
    p file
    system "grep qiita_id #{file}"
  end
  exit
end

まとめ

これで, gitにあげる作業をgit pushだけで行えるようになった.これは作業効率化以外にも, 一連の流れを忘れてもRakefileさえ覚えておけば簡単に実行できるようになるので超便利.

参考サイト

https://qiita.com/daddygongon/items/1c2d6d2895333ccf5e62


  • source ~/my_ruby/grad_members_20f/members/drop-sd/lectures/no8.org
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?