3
require 'rabbit/rabbit'
10
def self.append_features(klass)
15
attr_reader :base, :tmp_base
16
attr_accessor :encoding, :force_modified
18
def initialize(encoding, logger)
22
@force_modified = false
26
def source=(new_source)
27
source_type = self.class.name.split("::").last.downcase
28
raise ImmutableSourceTypeError.new(source_type)
38
enc = guess_encoding(@source)
43
unless /\Autf-?8\z/i =~ enc
45
@source = Iconv.conv("UTF-8", enc, @source)
52
@force_modified or need_read?
60
if @base_uri.nil? or @base_uri.relative?
61
::File.join(@base, path)
64
uri.path = @base_uri.path + "/" unless /\/$/ =~ @base_uri.path
69
def open_full_path(path, mode="rb")
70
open(full_path(path), mode) do |f|
75
def old?(current, get_latest_method_name)
77
(current and __send__(get_latest_method_name) > current)
81
dir = ::File.join(@tmp_base, TMP_DIR_NAME)
82
FileUtils.mkdir_p(dir) unless ::File.exist?(dir)
99
def set_base(new_value)
100
if ::File::ALT_SEPARATOR
101
new_value = new_value.gsub(::File::ALT_SEPARATOR, ::File::SEPARATOR)
104
@base_uri = parse_uri(@base)
105
if @base_uri.nil? or @base_uri.scheme.nil?
115
rescue ::URI::InvalidURIError
120
def guess_encoding(str)
139
module LimitAccessInterval
140
MINIMUM_ACCESS_TIME = 60
142
def initialize(*args, &block)
143
update_last_access_time
147
def old?(current, get_latest_method_name)
148
result = (can_access? and super)
149
update_last_access_time if result
154
def update_last_access_time
155
@last_access_time = Time.now
159
Time.now - @last_access_time > MINIMUM_ACCESS_TIME