module Rabbit::Source::Base
Attributes
Public Class Methods
Source
# File lib/rabbit/source/base.rb, line 25 def self.append_features(klass) super klass.send(:include, GetText) end
Calls superclass method
Source
# File lib/rabbit/source/base.rb, line 33 def initialize(encoding, logger) @encoding = encoding @logger = logger @source = nil @force_modified = false init_base end
Public Instance Methods
Source
# File lib/rabbit/source/base.rb, line 106 def base=(new_value) if new_value.nil? init_base else set_base(new_value) end end
Source
# File lib/rabbit/source/base.rb, line 79 def full_path(path) if @base_uri.nil? or @base_uri.relative? ::File.join(@base, path) else uri = @base_uri.dup uri.path = @base_uri.path + "/" unless /\/$/ =~ @base_uri.path (uri + path).to_s end end
Source
# File lib/rabbit/source/base.rb, line 71 def modified? @force_modified or need_read? end
Source
# File lib/rabbit/source/base.rb, line 95 def old?(current, get_latest_method_name) current.nil? or (current and __send__(get_latest_method_name) > current) end
Source
# File lib/rabbit/source/base.rb, line 89 def open_full_path(path, mode="rb") open(full_path(path), mode) do |f| yield f end end
Source
# File lib/rabbit/source/base.rb, line 49 def read if need_read? @source = _read case @encoding when nil enc = guess_encoding(@source) || Encoding::ASCII_8BIT when Encoding enc = @encoding else enc = Encoding.find(@encoding) end case enc when Encoding::UTF_8, Encoding::ASCII_8BIT @source.force_encoding(enc) else @source = @source.encode(Encoding::UTF_8, enc) end end @source end
Source
# File lib/rabbit/source/base.rb, line 41 def source=(new_source) source_type = self.class.name.split("::").last.downcase raise ImmutableSourceTypeError.new(source_type) end
Source
# File lib/rabbit/source/base.rb, line 100 def tmp_dir_name dir = ::File.join(@tmp_base, TMP_DIR_NAME) FileUtils.mkdir_p(dir) unless ::File.exist?(dir) dir end
Private Instance Methods
Source
# File lib/rabbit/source/base.rb, line 167 def extract_extension(path) components = ::File.basename(path).split(/\./) return nil if components.size < 2 components.last end
Source
# File lib/rabbit/source/base.rb, line 147 def guess_encoding(string) string = string.dup candidates = [ Encoding::UTF_8, Encoding::EUCJP_MS, Encoding::EUCJP, Encoding::WINDOWS_31J, Encoding::Shift_JIS, Encoding::CP51932, Encoding::CP50221, Encoding::ISO2022_JP, Encoding::UTF_16BE, Encoding::UTF_16LE, ] candidates.find do |candidate| next if candidate.dummy? string.force_encoding(candidate).valid_encoding? end end
Source
# File lib/rabbit/source/base.rb, line 139 def parse_uri(str) begin ::URI.parse(str) rescue ::URI::InvalidURIError nil end end
Source
# File lib/rabbit/source/base.rb, line 123 def set_base(new_value) if ::File::ALT_SEPARATOR new_value = new_value.gsub(::File::ALT_SEPARATOR, ::File::SEPARATOR) end @base = new_value @base_uri = parse_uri(@base) if @base_uri.nil? or @base_uri.scheme.nil? @tmp_base = @base else @tmp_base = "." end unless ::File.writable?(@tmp_base) @tmp_base = Dir.tmpdir end end