Book Image

Rake Task Management Essentials

By : Andrey Koleshko
Book Image

Rake Task Management Essentials

By: Andrey Koleshko

Overview of this book

Table of Contents (18 chapters)
Rake Task Management Essentials
Credits
About the Author
Acknowledgements
About the Reviewers
www.PacktPub.com
Preface
Index

Detecting a source for the rule dynamically


Say, we have this list of articles in our blog: article1.md, article2.md, and article3.markdown. When we get the value of task_name, which is one among article1.html, article2.html, or article3.html, there is no information on what the source is. If the value of task_name is article1.html, what is the source? Is it article1.md or article1.mardown? To understand this, we should define it dynamically. The possible solution is to go through articles and see if there is a file named article1.md or article1.mardown there. This is a possibility with proc too. Describing this is rather complicated.

The following example might give you some clarity:

require_relative 'blog_generator'

articles = Rake::FileList.new('**/*.md',
                 '**/*.markdown') do |files|
             files.exclude('~*')
             files.exclude(/^temp.+\//)
             files.exclude do |file|
               File.zero?(file)
             end
           end

task :default...