Class: XMP2Assert::Quasifile
- Inherits:
-
Object
- Object
- XMP2Assert::Quasifile
- Includes:
- PrettierInspect
- Defined in:
- lib/xmp2assert/quasifile.rb
Overview
XMP2Assert converts a ruby script into a test file but we want to hold original path name / line number for diagnostic purposes. So this class.
Instance Attribute Summary collapse
-
#__ENCODING__ ⇒ Encoding
readonly
Script encoding.
-
#__FILE__ ⇒ String
readonly
File name of this script.
-
#__LINE__ ⇒ Integer
readonly
Line offset.
-
#read ⇒ String
readonly
Content of the ruby script.
Inspection collapse
-
#pretty_print_instance_variables ⇒ Object
For pretty print.
Class Method Summary collapse
-
.new(obj, file = nil, line = nil) ⇒ Quasifile
A new quasifile.
Instance Method Summary collapse
-
#eval(b = TOPLEVEL_BINDING) ⇒ Object
Eavluate the content script.
-
#initialize(content, file, line) ⇒ Quasifile
constructor
A new instance of Quasifile.
Methods included from PrettierInspect
Constructor Details
#initialize(content, file, line) ⇒ Quasifile
Returns a new instance of Quasifile.
120 121 122 123 124 125 |
# File 'lib/xmp2assert/quasifile.rb', line 120 def initialize(content, file, line) @__FILE__ = file @__LINE__ = line @__ENCODING__ = content.encoding @read = content end |
Instance Attribute Details
#__ENCODING__ ⇒ Encoding (readonly)
Returns script encoding.
114 115 116 |
# File 'lib/xmp2assert/quasifile.rb', line 114 def __ENCODING__ @__ENCODING__ end |
#__FILE__ ⇒ String (readonly)
Returns file name of this script.
112 113 114 |
# File 'lib/xmp2assert/quasifile.rb', line 112 def __FILE__ @__FILE__ end |
#__LINE__ ⇒ Integer (readonly)
Returns line offset.
113 114 115 |
# File 'lib/xmp2assert/quasifile.rb', line 113 def __LINE__ @__LINE__ end |
#read ⇒ String (readonly)
Returns content of the ruby script.
115 116 117 |
# File 'lib/xmp2assert/quasifile.rb', line 115 def read @read end |
Class Method Details
.new(qfile) ⇒ Quasifile .new(uri, file = uri.to_s, line = 1) ⇒ Quasifile .new(path, file = path.to_path, line = 1) ⇒ Quasifile .new(io, file = '(eval)', line = io.lineno+1) ⇒ Quasifile .new(str, file = '(eval)', line = 1) ⇒ Quasifile
Returns a new quasifile.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/xmp2assert/quasifile.rb', line 87 def self.new(obj, file = nil, line = nil) case when src = switch { obj.to_str } then # LIKELY return allocate.tap do |ret| ret.send(:initialize, src, file||'(eval)', line||1) end when self === obj then return obj when OpenURI::OpenRead === obj then src, path = obj.read, obj.to_s when path = switch { obj.to_path } then src = obj.read when io = switch { obj.to_io } then off, src = io.lineno+1, io.read when src = switch { obj.read } then # unknown class but works else raise TypeError, "something readable expected but given: #{obj.class}" end return new(src, file || path, line || off) # recur end |
Instance Method Details
#eval(b = TOPLEVEL_BINDING) ⇒ Object
Eavluate the content script
130 131 132 |
# File 'lib/xmp2assert/quasifile.rb', line 130 def eval b = TOPLEVEL_BINDING Kernel.eval @read, b, @__FILE__, @__LINE__ end |
#pretty_print_instance_variables ⇒ Object
For pretty print
138 139 140 |
# File 'lib/xmp2assert/quasifile.rb', line 138 def pretty_print_instance_variables return %w'@__FILE__ @__LINE__' end |