嗨,我是 ruby on rails 的新手,目前正在做一个项目..
我对下面给出的两个文件的使用有点困惑..
以下文件是在应用程序的 Tasks 文件夹中找到的 cron_tasks.rb
class CronTasks
#----------------------------------------------------------------------------
# perform
#----------------------------------------------------------------------------
def self.perform(method)
with_logging method do
self.new.send(method)
end
end
#----------------------------------------------------------------------------
# with_logging
#----------------------------------------------------------------------------
def self.with_logging(method, &block)
log("Starting...", method)
time = Benchmark.ms do
yield block
end
log("Completed in (%.1fms)" % [time], method)
end
#----------------------------------------------------------------------------
# log
#----------------------------------------------------------------------------
def self.log(message, method = nil)
now = Time.now.strftime("%Y-%m-%d %H:%M:%S")
Rails.logger.info "#{now} %s#%s - #{message}" % [self.name, method]
end
############# Instance Methods ####################
#----------------------------------------------------------------------------
# calculate_fines
#----------------------------------------------------------------------------
def calculate_fines
LmsTasks.calculate_fines
end
#----------------------------------------------------------------------------
# overdue_alert
#----------------------------------------------------------------------------
def overdue_alert
LmsTasks.overdue_alert
end
#----------------------------------------------------------------------------
# due_alert
#----------------------------------------------------------------------------
def due_alert
LmsTasks.due_alert
end
end
另一个文件是在 Helpers 文件夹中找到的 Lov_helper.rb
module LovHelper
#----------------------------------------------------------------------------
# getLov - Get a list of values for a particular LOV type
#----------------------------------------------------------------------------
def self.getLov(lov_type)
lovs = LovValue.unscoped
lovs = lovs.select('lov_values.id, lov_value')
lovs = lovs.joins(:lov_name)
lovs = lovs.where('lov_names.name = ? ', lov_type)
lovs = lovs.order('sequence asc')
lovs.all
return lovs
end
#----------------------------------------------------------------------------
# getValue - Get the value pertaining to a particular LOV Value id
#----------------------------------------------------------------------------
def self.getValue(lov_value_id)
lov = LovValue.find(:all,
:select => 'lov_value',
:conditions => ['id = ? ', lov_value_id]).first
return lov.lov_value
end
#----------------------------------------------------------------------------
# getLovNames - Get a list of LOV names
#----------------------------------------------------------------------------
def self.getLovNames
lov_names = LovName.all
return lov_names
end
end
谁能告诉我以下文件的重要性以及使用它们的原因。