Class: NanDoc::SpecDoc::CodeSnippet

Inherits:
Object
  • Object
show all
Defined in:
lib/nandoc/spec-doc/code-snippet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_atObject (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

#describeObject



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_linesObject

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_startObject



33
34
35
# File 'lib/nandoc/spec-doc/code-snippet.rb', line 33

def line_start
  @start_at[:line]
end

#line_stopObject



36
37
38
# File 'lib/nandoc/spec-doc/code-snippet.rb', line 36

def line_stop
  @stop_at[:line]
end

#lines_rawObject



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_rawObject



42
43
44
# File 'lib/nandoc/spec-doc/code-snippet.rb', line 42

def string_raw
  @string_raw ||= lines_raw.join('')
end