Sha256: b44bc95a693c52e96cac24123d17732566c9a829d037560474d8c052c41768d6

Contents?: true

Size: 866 Bytes

Versions: 3

Compression:

Stored size: 866 Bytes

Contents

module Gemsmith
  module Skeletons
    # Configures Rake support.
    class RakeSkeleton < BaseSkeleton
      def self.allowed_options
        {
          rspec: "spec",
          rubocop: "rubocop"
        }
      end

      def create
        cli.template "%gem_name%/Rakefile.tt", cli.template_options
        configure_rakefile
      end

      private

      def allowed_options?
        cli.template_options.keys.any? { |key| self.class.allowed_options.keys.include? key }
      end

      def default_tasks
        cli.template_options.each.with_object([]) do |(key, _), tasks|
          tasks.push self.class.allowed_options[key]
        end
      end

      def configure_rakefile
        return unless allowed_options?
        cli.append_to_file "%gem_name%/Rakefile", "\ntask default: %w(#{default_tasks.compact.join(' ')})\n"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gemsmith-5.6.0 lib/gemsmith/skeletons/rake_skeleton.rb
gemsmith-5.5.0 lib/gemsmith/skeletons/rake_skeleton.rb
gemsmith-5.4.0 lib/gemsmith/skeletons/rake_skeleton.rb