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.
124 125 126 127 128 129 |
# File 'lib/xmp2assert/quasifile.rb', line 124 def initialize(content, file, line) @__FILE__ = file @__LINE__ = line @__ENCODING__ = content.encoding @read = content end |
Instance Attribute Details
#__ENCODING__ ⇒ Encoding (readonly)
Returns script encoding.
118 119 120 |
# File 'lib/xmp2assert/quasifile.rb', line 118 def __ENCODING__ @__ENCODING__ end |
#__FILE__ ⇒ String (readonly)
Returns file name of this script.
116 117 118 |
# File 'lib/xmp2assert/quasifile.rb', line 116 def __FILE__ @__FILE__ end |
#__LINE__ ⇒ Integer (readonly)
Returns line offset.
117 118 119 |
# File 'lib/xmp2assert/quasifile.rb', line 117 def __LINE__ @__LINE__ end |
#read ⇒ String (readonly)
Returns content of the ruby script.
119 120 121 |
# File 'lib/xmp2assert/quasifile.rb', line 119 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.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/xmp2assert/quasifile.rb', line 91 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
134 135 136 |
# File 'lib/xmp2assert/quasifile.rb', line 134 def eval b = TOPLEVEL_BINDING Kernel.eval @read, b, @__FILE__, @__LINE__ end |
#pretty_print_instance_variables ⇒ Object
For pretty print
142 143 144 |
# File 'lib/xmp2assert/quasifile.rb', line 142 def pretty_print_instance_variables return %w'@__FILE__ @__LINE__' end |