Sha256: ee0625b3e80eca95259a4b8104f4c50c68aab07810eb3764ff500126f7b95af1

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

require 'thor'
require 'active_support/inflector'

module Gram
  module Gem
    class Generator < Thor
      include Thor::Actions

      source_root File.dirname(__FILE__)

      no_tasks do
        def generate(name, options)
          @rails = true if options.include?("--rails")
          @underscored = name.underscore
          @camelized = name.camelize

          run "bundle gem #{@underscored}"

          remove_file("#{@underscored}/Rakefile")
          template('templates/Rakefile.tt', "#{@underscored}/Rakefile")

          remove_file("#{@underscored}/.gitignore")
          template('templates/gitignore.tt', "#{@underscored}/.gitignore")

          template('templates/Readme.tt', "#{@underscored}/Readme.md")
          template('templates/rvmrc.tt', "#{@underscored}/.rvmrc")

          empty_directory "#{@underscored}/spec"
          template('templates/spec/spec_helper.tt', "#{@underscored}/spec/spec_helper.rb")

          inject_into_file "#{@underscored}/#{@underscored}.gemspec", :after => "s.rubyforge_project = \"#{@underscored}\"" do
            runtime_dependencies = []
            runtime_dependencies << "  s.add_runtime_dependency 'activerecord', '~> 3.0.5'" if rails

            development_dependencies = []
            development_dependencies << "  s.add_runtime_dependency 'sqlite3'" if rails
            development_dependencies += [
              "  s.add_development_dependency 'rspec', '~> 2.5.0'",
              "  s.add_development_dependency 'yard'",
              "  s.add_development_dependency 'bluecloth'" ]

            "\n\n" + runtime_dependencies.join("\n") << "\n\n"<< development_dependencies.join("\n")
          end
        end
      end

      private

      def underscored
        @underscored
      end

      def camelized
        @camelized
      end

      def rails
        @rails
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gram-0.1.0 lib/gram/gem/generator.rb