class AdLint::Benchmark::AnalysisTarget
Attributes
name[R]
Public Class Methods
load(name)
click to toggle source
# File lib/adlint/benchmark/target.rb, line 41 def self.load(name) require(name_to_rb_fname(name)) eval "#{name_to_rb_cname(name)}.new('#{name}')" rescue LoadError nil end
new(name)
click to toggle source
# File lib/adlint/benchmark/target.rb, line 53 def initialize(name) @name = name end
Private Class Methods
cleanpath(str)
click to toggle source
# File lib/adlint/benchmark/target.rb, line 48 def self.cleanpath(str) Pathname.new(str).cleanpath end
name_to_rb_cname(name)
click to toggle source
# File lib/adlint/benchmark/target.rb, line 197 def self.name_to_rb_cname(name) "Target::T_#{normalize(name)}" end
name_to_rb_fname(name)
click to toggle source
# File lib/adlint/benchmark/target.rb, line 192 def self.name_to_rb_fname(name) "adlint/benchmark/target/#{normalize(name)}.rb" end
normalize(name)
click to toggle source
# File lib/adlint/benchmark/target.rb, line 202 def self.normalize(name) name.gsub("/", "-").gsub("-", "_").gsub(".", "_") end
Public Instance Methods
analyze()
click to toggle source
# File lib/adlint/benchmark/target.rb, line 59 def analyze patch_libraries do _analyze end end
Private Instance Methods
_analyze()
click to toggle source
# File lib/adlint/benchmark/target.rb, line 66 def _analyze subclass_responsibility end
patch_libraries() { || ... }
click to toggle source
# File lib/adlint/benchmark/target.rb, line 70 def patch_libraries(&block) eval <<EOS class ::File class <<self alias :_orig_open :open def open(path, mode = "r", perm = 0666, &block) path = path.to_s if content = #{self.class.name}::FILES[Pathname.new(path).cleanpath] if content == :new io = File.open(File::NULL, "w") else io = StringIO.new(content) end io.set_encoding(Encoding::UTF_8) if block_given? yield(io) else io end else _orig_open(path, mode, perm, &block) end end alias :_orig_exist? :exist? def exist?(path) path = path.to_s paths = #{self.class.name}::DIRS + #{self.class.name}::FILES.keys if paths.include?(Pathname.new(path).cleanpath) true else _orig_exist?(path) end end alias :_orig_file? :file? def file?(path) path = path.to_s if #{self.class.name}::FILES.include?(Pathname.new(path).cleanpath) true else _orig_file?(path) end end alias :_orig_directory? :directory? def directory?(path) path = path.to_s if #{self.class.name}::DIRS.include?(Pathname.new(path).cleanpath) true else _orig_directory?(path) end end end end class ::IO class <<self alias :_orig_read :read def read(path, *args) path = path.to_s if content = #{self.class.name}::FILES[Pathname.new(path).cleanpath] content.to_default_external else _orig_read(path, *args) end end end end class ::Pathname alias :_orig_readable? :readable? def readable? if #{self.class.name}::FILES.include?(self.cleanpath) true else _orig_readable? end end end module ::FileUtils class <<self alias :_orig_mkdir_p :mkdir_p def mkdir_p(list, options = {}) [] end end end EOS yield eval <<EOS class ::File class <<self alias :open :_orig_open alias :exist? :_orig_exist? alias :file? :_orig_file? alias :directory? :_orig_directory? end end class ::IO class <<self alias :read :_orig_read end end class ::Pathname alias :readable? :_orig_readable? end module ::FileUtils class <<self alias :mkdir_p :_orig_mkdir_p end end EOS end