Class: Clerq::Repositories::TextRepository
- Inherits:
-
FileRepository
- Object
- FileRepository
- Clerq::Repositories::TextRepository
- Defined in:
- lib/clerq/repositories/text_repository.rb
Instance Attribute Summary
Attributes inherited from FileRepository
Instance Method Summary collapse
-
#find(name) ⇒ Object
def find(filename) inside do return filename if File.exist?(filename) @patt.each do |p| fn = “#filename#1.1..-1” return fn if File.exist?(fn) end end ” end.
-
#initialize(path: Dir.pwd, pattern: ['*.md.erb', '*.md.tt']) ⇒ TextRepository
constructor
A new instance of TextRepository.
-
#text(name) ⇒ Object
Return template body @param name [String].
Methods inherited from FileRepository
Constructor Details
#initialize(path: Dir.pwd, pattern: ['*.md.erb', '*.md.tt']) ⇒ TextRepository
Returns a new instance of TextRepository.
9 10 11 |
# File 'lib/clerq/repositories/text_repository.rb', line 9 def initialize(path: Dir.pwd, pattern: ['*.md.erb', '*.md.tt']) super(path: path, pattern: pattern) end |
Instance Method Details
#find(name) ⇒ Object
def find(filename)
inside do
return filename if File.exist?(filename)
@patt.each do |p|
fn = "#{filename}#{p[1..-1]}"
return fn if File.exist?(fn)
end
end
''
end
34 35 36 37 38 39 40 41 42 |
# File 'lib/clerq/repositories/text_repository.rb', line 34 def find(name) inside { return name if File.exist?(name) and !File.directory?(name)} all = glob pos = @patt.map{|p| "#{name}#{p[1..-1]}"}.unshift(name) all.find(lambda {''}){|n| pos.include?(n) || n.start_with?(*pos) || n.end_with?(*pos) } end |
#text(name) ⇒ Object
Return template body @param name [String]
14 15 16 17 18 19 20 21 |
# File 'lib/clerq/repositories/text_repository.rb', line 14 def text(name) filename = find(name) if filename.empty? err = "File '#{name}' not found" raise StandardError, err end read(filename) end |