Module: SchemaDev::Templates
- Defined in:
- lib/schema_dev/templates.rb
Class Method Summary collapse
- ._install(src, dst, bound) ⇒ Object
- .install_relative(src:, dst:, bound: nil) ⇒ Object
- .install_subtree(src:, dst:, bound: nil) ⇒ Object
- .process(text, bound: nil) ⇒ Object
- .root ⇒ Object
Class Method Details
._install(src, dst, bound) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/schema_dev/templates.rb', line 22 def self._install(src, dst, bound) src = Pathname(src.to_s + ".erb") unless src.file? dst.sub_ext '' if dst.extname == '.erb' dst.dirname.mkpath dst.write process(src.read, bound: bound) end |
.install_relative(src:, dst:, bound: nil) ⇒ Object
16 17 18 19 20 |
# File 'lib/schema_dev/templates.rb', line 16 def self.install_relative(src:, dst:, bound: nil) srcfile = root + src dstfile = dst + src _install(srcfile, dstfile, bound) end |
.install_subtree(src:, dst:, bound: nil) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/schema_dev/templates.rb', line 9 def self.install_subtree(src:, dst:, bound: nil) src = root + src Pathname.glob(src + "**/*").select(&:file?).each do |p| _install(p, dst + p.relative_path_from(src).sub_ext(''), bound) end end |
.process(text, bound: nil) ⇒ Object
29 30 31 |
# File 'lib/schema_dev/templates.rb', line 29 def self.process(text, bound: nil) ERB.new(text).result(bound) end |
.root ⇒ Object
5 6 7 |
# File 'lib/schema_dev/templates.rb', line 5 def self.root @root ||= Pathname.new(__FILE__).dirname.parent.parent + "templates" end |