Sha256: ecaa7f94333ae17d89aefa29c85de3881e9a7896af551f0e8f9156552e8dfcf0

Contents?: true

Size: 794 Bytes

Versions: 4

Compression:

Stored size: 794 Bytes

Contents

require 'erb'
require 'fileutils'
require 'core_ext/string/camelize'

module GemRelease
  class Template
    include GemRelease::Helpers

    attr_reader :name, :module_name, :module_path, :options

    def initialize(options = {})
      @options = options
      options.each { |key, value| instance_variable_set(:"@#{key}", value) }

      @name        ||= gem_name_from_directory
      @module_path ||= name.gsub('-', '_')
      @module_name ||= module_path.camelize
    end

    def write
      FileUtils.mkdir_p(File.dirname(filename))
      File.open(filename, 'w+') { |f| f.write(render) }
    end

    def render
      ERB.new(template, nil, "%").result(binding)
    end

    def template
      File.new(File.expand_path("../templates/#{template_name}", __FILE__)).read
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gem-release-0.0.13 lib/gem_release/template.rb
gem-release-0.0.12 lib/gem_release/template.rb
gem-release-0.0.11 lib/gem_release/template.rb
gem-release-0.0.10 lib/gem_release/template.rb