Sha256: 945ff94a44883c1b15362f16b6c7e38c6fe9ea843360235de993f59a7cc47a60

Contents?: true

Size: 795 Bytes

Versions: 3

Compression:

Stored size: 795 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

3 entries across 3 versions & 1 rubygems

Version Path
gem-release-0.0.16 lib/gem_release/template.rb
gem-release-0.0.15 lib/gem_release/template.rb
gem-release-0.0.14 lib/gem_release/template.rb