Module: Rabbit::Source::Base
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#force_modified ⇒ Object
Returns the value of attribute force_modified.
-
#tmp_base ⇒ Object
readonly
Returns the value of attribute tmp_base.
Class Method Summary collapse
Instance Method Summary collapse
- #extension ⇒ Object
- #full_path(path) ⇒ Object
- #initialize(encoding, logger) ⇒ Object
- #modified? ⇒ Boolean
- #need_read? ⇒ Boolean
- #old?(current, get_latest_method_name) ⇒ Boolean
- #open_full_path(path, mode = "rb") ⇒ Object
- #read ⇒ Object
- #reset ⇒ Object
- #source=(new_source) ⇒ Object
- #tmp_dir_name ⇒ Object
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
16 17 18 |
# File 'lib/rabbit/source/base.rb', line 16 def base @base end |
#encoding ⇒ Object
Returns the value of attribute encoding.
17 18 19 |
# File 'lib/rabbit/source/base.rb', line 17 def encoding @encoding end |
#force_modified ⇒ Object
Returns the value of attribute force_modified.
17 18 19 |
# File 'lib/rabbit/source/base.rb', line 17 def force_modified @force_modified end |
#tmp_base ⇒ Object (readonly)
Returns the value of attribute tmp_base.
16 17 18 |
# File 'lib/rabbit/source/base.rb', line 16 def tmp_base @tmp_base end |
Class Method Details
.append_features(klass) ⇒ Object
11 12 13 14 |
# File 'lib/rabbit/source/base.rb', line 11 def self.append_features(klass) super klass.send(:include, GetText) end |
Instance Method Details
#extension ⇒ Object
97 98 99 |
# File 'lib/rabbit/source/base.rb', line 97 def extension nil end |
#full_path(path) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/rabbit/source/base.rb', line 62 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 |
#initialize(encoding, logger) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/rabbit/source/base.rb', line 19 def initialize(encoding, logger) @encoding = encoding @logger = logger @source = nil @force_modified = false init_base end |
#modified? ⇒ Boolean
54 55 56 |
# File 'lib/rabbit/source/base.rb', line 54 def modified? @force_modified or need_read? end |
#need_read? ⇒ Boolean
58 59 60 |
# File 'lib/rabbit/source/base.rb', line 58 def need_read? @source.nil? end |
#old?(current, get_latest_method_name) ⇒ Boolean
78 79 80 81 |
# File 'lib/rabbit/source/base.rb', line 78 def old?(current, get_latest_method_name) current.nil? or (current and __send__(get_latest_method_name) > current) end |
#open_full_path(path, mode = "rb") ⇒ Object
72 73 74 75 76 |
# File 'lib/rabbit/source/base.rb', line 72 def open_full_path(path, mode="rb") open(full_path(path), mode) do |f| yield f end end |
#read ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rabbit/source/base.rb', line 35 def read if need_read? @source = _read if @encoding.nil? enc = guess_encoding(@source) else enc = @encoding end if /\Autf-?8\z/i =~ enc @source.force_encoding(enc) if @source.respond_to?(:force_encoding) else require "iconv" @source = Iconv.conv("UTF-8", enc, @source) end end @source end |
#reset ⇒ Object
32 33 |
# File 'lib/rabbit/source/base.rb', line 32 def reset end |
#source=(new_source) ⇒ Object
27 28 29 30 |
# File 'lib/rabbit/source/base.rb', line 27 def source=(new_source) source_type = self.class.name.split("::").last.downcase raise ImmutableSourceTypeError.new(source_type) end |
#tmp_dir_name ⇒ Object
83 84 85 86 87 |
# File 'lib/rabbit/source/base.rb', line 83 def tmp_dir_name dir = ::File.join(@tmp_base, TMP_DIR_NAME) FileUtils.mkdir_p(dir) unless ::File.exist?(dir) dir end |