require "rubygems" require "bundler/setup" require "active_record" require "state_pattern" project_root = File.dirname(File.absolute_path(__FILE__)) Dir.glob(project_root + "/app/models/*.rb").each{|f| require f} Dir.glob(project_root + "/app/helpers/SearchingForSyncState.rb").each{|f| require f} Dir.glob(project_root + "/app/helpers/*.rb").each{|f| require f} connection_details = YAML::load(File.open('config/database.yml')) ActiveRecord::Base.establish_connection(connection_details) if __FILE__ == $0 yesterday = Date.today.advance(days: -1) ReadingsMailer.deliver(yesterday) # are we at the start of a month? if (Date.today.beginning_of_month == Date.today) # then also send report for previous month (and year) ReadingsMailer.deliver_for_month(yesterday.month, yesterday.year) end end #p sync