Sha256: ac8d3eb2c34b58337fa1955fd96f1d70e10814fd7ecc9f3873201abc7ef979cd
Contents?: true
Size: 1.41 KB
Versions: 1
Compression:
Stored size: 1.41 KB
Contents
module FileScheduler class Base attr_accessor :root, :log, :status_file def initialize(attributes = {}) case attributes when String attributes = { (attributes.url? ? :playlist : :directory) => attributes } when Pathname attributes = { :directory => attributes } end @root = if attributes.has_key?(:directory) FileScheduler::File.new(attributes[:directory]) elsif attributes.has_key?(:playlist) FileScheduler::Playlist.new(attributes[:playlist]) end end def log @log ||= Log.new.tap do |log| log.load(status_file) if status_file end end def contents root.contents end def scheduling(time = Time.now) Scheduling.new(root, time).tap do |scheduling| scheduling.log = log end end def next(time = Time.now) scheduling(time).next end def forced_next(time = Time.now) scheduling(time).forced_next end def after_next(content) log.save(status_file) if status_file end [:next, :forced_next].each do |method| alias_method :"#{method}_without_callback", method define_method("#{method}_with_callback") do |*arguments| content = send "#{method}_without_callback", *arguments after_next content content end alias_method method, :"#{method}_with_callback" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
file_scheduler-0.0.2 | lib/file_scheduler/base.rb |