Class: NanDoc::SpecDoc::CodeSnippet
- Inherits:
-
Object
- Object
- NanDoc::SpecDoc::CodeSnippet
- Defined in:
- lib/nandoc/spec-doc/code-snippet.rb
Instance Attribute Summary collapse
-
#start_at ⇒ Object
readonly
Returns the value of attribute start_at.
Instance Method Summary collapse
- #describe ⇒ Object
-
#file_lines ⇒ Object
just hide all the lines from dumps to make irb debugging prettier.
-
#initialize(matches_hash) ⇒ CodeSnippet
constructor
internally this does deferred parsing of the thing a code snippet holds meta information (or maybe content) for record_ruby nandoc commands in tests.
- #line_start ⇒ Object
- #line_stop ⇒ Object
- #lines_raw ⇒ Object
- #stop_at(data = nil) ⇒ Object
- #string_raw ⇒ Object
Constructor Details
#initialize(matches_hash) ⇒ CodeSnippet
internally this does deferred parsing of the thing a code snippet holds meta information (or maybe content) for record_ruby nandoc commands in tests.
9 10 11 12 13 |
# File 'lib/nandoc/spec-doc/code-snippet.rb', line 9 def initialize matches_hash @start_at = matches_hash @stop_at = nil @lines_proc = nil end |
Instance Attribute Details
#start_at ⇒ Object (readonly)
Returns the value of attribute start_at.
14 15 16 |
# File 'lib/nandoc/spec-doc/code-snippet.rb', line 14 def start_at @start_at end |
Instance Method Details
#describe ⇒ Object
19 20 21 22 |
# File 'lib/nandoc/spec-doc/code-snippet.rb', line 19 def describe last = method ? ":in `#{method}'" : '' "#{file}:#{line}#{tail}" end |
#file_lines ⇒ Object
just hide all the lines from dumps to make irb debugging prettier
24 25 26 27 28 29 30 31 32 |
# File 'lib/nandoc/spec-doc/code-snippet.rb', line 24 def file_lines @lines_proc ||= begin stop_at_assert # not really appropriate here same_file_assert # not really appropriate here all_lines = File.open(@start_at[:file],'r').lines.map # sure why not proc{ all_lines } end @lines_proc.call end |
#line_start ⇒ Object
33 34 35 |
# File 'lib/nandoc/spec-doc/code-snippet.rb', line 33 def line_start @start_at[:line] end |
#line_stop ⇒ Object
36 37 38 |
# File 'lib/nandoc/spec-doc/code-snippet.rb', line 36 def line_stop @stop_at[:line] end |
#lines_raw ⇒ Object
39 40 41 |
# File 'lib/nandoc/spec-doc/code-snippet.rb', line 39 def lines_raw @lines_raw ||= file_lines[line_start..(line_stop-2)] end |
#stop_at(data = nil) ⇒ Object
45 46 47 |
# File 'lib/nandoc/spec-doc/code-snippet.rb', line 45 def stop_at data=nil data ? (@stop_at = data) : @stop_at end |
#string_raw ⇒ Object
42 43 44 |
# File 'lib/nandoc/spec-doc/code-snippet.rb', line 42 def string_raw @string_raw ||= lines_raw.join('') end |