[RUBY] Introduction to Rakefile that can be done in about 10 minutes

Target

Makefile can be written Ruby is installed

What is Rakefile?

Makefile that can be written in Ruby

environment

ruby 2.7.1p83

Hello Rakefile! First, create a suitable working folder. Here, create it with the folder name rakefile-sample.

Create a Rakefile there and write as follows

Rakefile


task :first_task do
  puts 'Hello Rakefile!'
end

Run

rakefile-sample $ rake first_task
Hello Rakefile!

Executing unix command

Rakefile


task :run_sh do
  sh %{echo Hello Rakefile sh!}
end

Run

rakefile-sample $ rake run_sh
echo Hello Rakefile sh!
Hello Rakefile sh!

instance method FileUtils#sh

Perform multiple tasks in sequence

Rakefile


task :task1 do 
  puts 'task1'
end

task :task2 do 
  puts 'task2'
end

# task1,Execute task3 after task2
task :task3 => [:task1, :task2] do 
  puts 'task3'
end

Run

rakefile-sample $ rake task3
task1
task2
task3

Create a file

If file is used instead of task, it will be executed only when the target file (Gemfile in this case) does not exist.

Rakefile


file 'Gemfile' do
  f = File.open('Gemfile', 'w')
  f.puts("source 'https://rubygems.org'")
  f.puts("gem 'rails', '~>5'")

  puts 'Gemfile created'
end

Execute (correctly not executed the second time)

rakefile-sample $ rake Gemfile
Gemfile created
rakefile-sample $ rake Gemfile
rakefile-sample $ 

reference

library rake Summary of basic usage of Rake How to write a File in Ruby [For beginners]

Recommended Posts

Introduction to Rakefile that can be done in about 10 minutes
Basic functional interface that can be understood in 3 minutes
Introduction to Java that can be understood even with Krillin (Part 1)
Write a class that can be ordered in Java
Understand the characteristics of Scala in 5 minutes (Introduction to Scala)
About the matter that hidden_field can be used insanely
Convenient shortcut keys that can be used in Eclipse
List of devices that can be previewed in Swift UI
[Introduction to MVEL] Aiming to be the best MVELer in the world
Create a jar file that can be executed in Gradle
Find a Switch statement that can be converted to a Switch expression
Java (super beginner edition) that can be understood in 180 seconds
Object-oriented design that can be used when you want to return a response in form format
How to make a key pair of ecdsa in a format that can be read by Java
Reference memo / In-memory LDAP server that can be embedded in Java
Summary of ORM "uroboroSQL" that can be used in enterprise Java
SwiftUI View that can be used in combination with other frameworks
Mecab installation that can be done almost by typing a command
About the language to be learned
[Introduction to Java] About lambda expressions
Introduction to algorithms in java-cumulative sum
[Introduction to Java] About Stream API
[Super Introduction] About Symbols in Ruby
Correspond to "error that basic authentication does not pass" in the test code "The story that could not be done"
Are you still exhausted to implement the search function? Gem'ransack' that can be implemented in an instant
How to override in a model unit test so that Faker can be used to generate random values
About the problem that the server can not be started with rails s
[Android Studio] Description that can be continuously input in SQLite Database [Java]
Object-oriented that can be understood by fairies
Understand in 5 minutes !! How to use Docker
Log out a CSV file that can be read in Excel using logback
[Android] I want to create a ViewPager that can be used for tutorials
About the case that ("b" .. "aa") could not be used in Ruby Range
Technology excerpt that can be used for creating EC sites in Java training
[iOS] [MVVM] Should Date to String conversion be done in ViewModel or View?
Try to save the data that can be read by JavaFX as PNG