Class: NanDoc::SpecDoc::CodeSnippet

Inherits:
Object
  • Object
show all
Defined in:
lib/nandoc/spec-doc/support-modules.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.



34
35
36
37
38
# File 'lib/nandoc/spec-doc/support-modules.rb', line 34

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.



39
40
41
# File 'lib/nandoc/spec-doc/support-modules.rb', line 39

def start_at
  @start_at
end

Instance Method Details

#describeObject



44
45
46
47
# File 'lib/nandoc/spec-doc/support-modules.rb', line 44

def describe
  last = method ? ":in `#{method}'" : ''
  "#{file}:#{line}#{tail}"
end

#file_linesObject

just hide all the lines from dumps to make irb debugging prettier



49
50
51
52
53
54
55
56
57
# File 'lib/nandoc/spec-doc/support-modules.rb', line 49

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



58
59
60
# File 'lib/nandoc/spec-doc/support-modules.rb', line 58

def line_start
  @start_at[:line]
end

#line_stopObject



61
62
63
# File 'lib/nandoc/spec-doc/support-modules.rb', line 61

def line_stop
  @stop_at[:line]
end

#ruby_string_rawObject



65
66
67
68
69
70
# File 'lib/nandoc/spec-doc/support-modules.rb', line 65

def ruby_string_raw
  @ruby_string_raw ||= begin
    these = all_lines[line_start..(line_stop-2)]
    these.join('') # they have newlines already
  end
end

#stop_at(data = nil) ⇒ Object



71
72
73
# File 'lib/nandoc/spec-doc/support-modules.rb', line 71

def stop_at data=nil
  data ? (@stop_at = data) : @stop_at
end