Module: SchemaDev::Templates

Defined in:
lib/schema_dev/templates.rb

Class Method Summary collapse

Class Method Details

._install(src, dst, bound) ⇒ Object



24
25
26
27
28
29
# File 'lib/schema_dev/templates.rb', line 24

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



18
19
20
21
22
# File 'lib/schema_dev/templates.rb', line 18

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



11
12
13
14
15
16
# File 'lib/schema_dev/templates.rb', line 11

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



31
32
33
# File 'lib/schema_dev/templates.rb', line 31

def self.process(text, bound: nil)
  ERB.new(text).result(bound)
end

.rootObject



7
8
9
# File 'lib/schema_dev/templates.rb', line 7

def self.root
  @root ||= Pathname.new(__FILE__).dirname.parent.parent + 'templates'
end