Class: Trekky::Source
- Inherits:
-
Object
show all
- Defined in:
- lib/trekky/source.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(context, path) ⇒ Source
Returns a new instance of Source.
7
8
9
10
11
|
# File 'lib/trekky/source.rb', line 7
def initialize(context, path)
@path = path
@context = context
@errors = []
end
|
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
5
6
7
|
# File 'lib/trekky/source.rb', line 5
def context
@context
end
|
#errors ⇒ Object
Returns the value of attribute errors.
5
6
7
|
# File 'lib/trekky/source.rb', line 5
def errors
@errors
end
|
#output ⇒ Object
Returns the value of attribute output.
5
6
7
|
# File 'lib/trekky/source.rb', line 5
def output
@output
end
|
#path ⇒ Object
Returns the value of attribute path.
5
6
7
|
# File 'lib/trekky/source.rb', line 5
def path
@path
end
|
Instance Method Details
#add_error(error) ⇒ Object
33
34
35
36
37
|
# File 'lib/trekky/source.rb', line 33
def add_error(error)
STDOUT.puts "ERROR: #{error.message} (#{path})"
@errors << error
nil
end
|
#clear_errors ⇒ Object
39
40
41
|
# File 'lib/trekky/source.rb', line 39
def clear_errors
@errors = []
end
|
#extension ⇒ Object
25
26
27
|
# File 'lib/trekky/source.rb', line 25
def extension
File.extname(path)
end
|
29
30
31
|
# File 'lib/trekky/source.rb', line 29
def input
File.read(path)
end
|
#render(&block) ⇒ Object
13
14
15
|
# File 'lib/trekky/source.rb', line 13
def render(&block)
raise NotImplementedError
end
|
#render_error(error) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/trekky/source.rb', line 49
def render_error(error)
Haml::Engine.new(" %h1 File: \#{path}\n %h3 Error: \#{error.message}\n %pre\n %code\n - error.backtrace.each do |line|\n = line\n %br\n INPUT\nend\n".gsub(" "*8, "")).render(self, {error: error})
|
#render_errors ⇒ Object
43
44
45
46
47
|
# File 'lib/trekky/source.rb', line 43
def render_errors
@errors.map do |error|
render_error(error)
end.join("<br/>")
end
|
#type ⇒ Object
21
22
23
|
# File 'lib/trekky/source.rb', line 21
def type
extension[1..-1].intern
end
|
#valid? ⇒ Boolean
17
18
19
|
# File 'lib/trekky/source.rb', line 17
def valid?
@errors.empty?
end
|