lib/vedeu/support/template.rb in vedeu-0.4.5 vs lib/vedeu/support/template.rb in vedeu-0.4.6
- old
+ new
@@ -15,24 +15,36 @@
# @param object [Class]
# @param path [String]
# @return [Template]
def initialize(object, path)
- @object, @path = object, path
+ @object, @path = object, path.to_s
end
# @return [void]
def parse
ERB.new(load, nil, '-').result(binding)
end
private
- attr_reader :object, :path
+ # @!attribute [r] object
+ # @return [Class]
+ attr_reader :object
# @return [String]
def load
File.read(path)
+ end
+
+ # @raise [MissingRequired] when the path is empty.
+ # @raise [MissingRequired] when the path does not exist.
+ # @return [String]
+ def path
+ fail MissingRequired, 'No path to template specified.' if @path.empty?
+ fail MissingRequired, 'Template file cannot be found.' unless File.exist?(@path)
+
+ @path
end
end # Template
end # Vedeu