Sha256: ffb0388ccad6938d6278891336a877138a51809fa1979142cff6baeed0308ca6

Contents?: true

Size: 910 Bytes

Versions: 3

Compression:

Stored size: 910 Bytes

Contents

module Hound
  module Tools
    module Template
      class InvalidTemplate < RuntimeError
      end

      attr_reader :filename

      def initialize(filename)
        @filename = filename
      end

      def generate
        _validate(IO.read(@filename))
        $stdout.puts "#{@filename} (seems ok - skipped)"
        true
      rescue Errno::ENOENT
        Pathname.new(@filename).dirname.mkpath
        IO.write(@filename, _template_for(@filename))
        $stdout.puts "#{@filename} created"
      rescue InvalidTemplate => e
        $stderr.puts "Error: #{@filename} is invalid! (#{e.message})"
      end

      private

      def _template_for(file)
        template_dir = Pathname.new(__FILE__).expand_path.dirname + 'templates'
        path = template_dir + file.sub(/^\./, '_.')
        path.read
      end

      def _validate(_data)
        fail NotImplementedError
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hound-tools-0.0.6 lib/hound/tools/template.rb
hound-tools-0.0.5 lib/hound/tools/template.rb
hound-tools-0.0.4 lib/hound/tools/template.rb