Visualizzazione post con etichetta ruby. Mostra tutti i post
Visualizzazione post con etichetta ruby. Mostra tutti i post

[Ruby] Last day of month in whenever gem



I'm using whenever gem for scheduling my own rake tasks:
https://github.com/javan/whenever

Sometimes it's useful to schedule a task the last day of the month.
The gem does not provide such alias.

The solution is the following:

job_type :only_last_day, "[ \"$(/bin/date +%d -d tomorrow)\" = \"01\" ] && cd :path && :environment_variable=:environment bundle exec rake :custom_rake_task"

every '30 10 28-31 * *' do
  only_last_day "custom_task", :custom_rake_task => "your_rake_task_name"
end


  • 30 10 28-31 * * means: try to launch the script every month at 28th,29th,30th,31th day at 10:30 am
  • if current date plus one equals 01 it means today is the last day of the month therefore the script is eligible to be run

[Rails] find not used partial ruby script

find_partial_not_used.rb
 

def string_between_markers string, marker1, marker2
  string[/#{Regexp.escape(marker1)}(.*?)#{Regexp.escape(marker2)}/m, 1]
end

all_erb_files=`find . -name '_*.erb'`.split("\n")
short_names = all_erb_files.collect {|f|
  string_between_markers f, "/_", "."
}.uniq
short_names.each {|s|
  how_many_times_is_called=`find . -name *.erb | xargs grep render | grep #{s} | wc -l`
  puts "partial #{s} not rendered in any file" if how_many_times_is_called.to_i == 0
}