Class: Rusky::Task
Class Method Summary collapse
Instance Method Summary collapse
- #define_task(hook_name, rake_task_name) ⇒ Object
-
#initialize(base = nil) ⇒ Task
constructor
A new instance of Task.
- #install ⇒ Object
Constructor Details
#initialize(base = nil) ⇒ Task
Returns a new instance of Task.
15 16 17 18 19 |
# File 'lib/rusky/task.rb', line 15 def initialize(base=nil) @base = base || `lsof -p #{Process.ppid} | grep cwd`.split(" ").last rusky_setting_file_path = File.join(@base, '.rusky') @yaml = File.exists?(rusky_setting_file_path) ? YAML.load_file(File.join(@base, '.rusky')) : Hash.new([]) end |
Class Method Details
.install(base = nil) ⇒ Object
10 11 12 |
# File 'lib/rusky/task.rb', line 10 def install(base=nil) new(base).install end |
Instance Method Details
#define_task(hook_name, rake_task_name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rusky/task.rb', line 32 def define_task(hook_name, rake_task_name) task "#{rake_task_name}" do commands = @yaml[hook_name] if commands.empty? puts "rusky > No command for #{hook_name} is defined in .rusky file" next end commands.each do |command| puts "rusky > #{command}" system(command) || raise("rusky > #{command} failed") end end end |
#install ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rusky/task.rb', line 21 def install Rusky::HOOKS.each do |hook_name| rake_task_name = "rusky:#{hook_name.gsub('-', '_')}" # prioritize existing user hook next if Rake::Task.task_defined? rake_task_name define_task hook_name, rake_task_name end end |