Sha256: 1a84c87bcd9a8858199ef85ce01352fe087000818b6c1a962dd4676e500ddb75

Contents?: true

Size: 874 Bytes

Versions: 3

Compression:

Stored size: 874 Bytes

Contents

require 'rails/generators'
module Heracles
  module Wrapper
    class InstallGenerator < Rails::Generators::Base
      source_root File.expand_path('../templates', __FILE__)

      class_option(
        :api_key,
        :aliases => "-k",
        :type => :string,
        :desc => "Your Heracles API key",
        :required => true
      )

      def install
        ensure_api_key_was_configured
        generate_config
      end

      private
      def ensure_api_key_was_configured
        if api_key_configured?
          puts "Already configured"
          exit
        end
      end

      def generate_config
        template 'config.rb', initializer_filename
      end

      def initializer_filename
        'config/initializers/heracles-wrapper.rb'
      end

      def api_key_configured?
        File.exists?(initializer_filename)
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
heracles-wrapper-0.0.3 lib/rails/generators/heracles/wrapper/install/install_generator.rb
heracles-wrapper-0.0.2 lib/rails/generators/heracles/wrapper/install/install_generator.rb
heracles-wrapper-0.0.1 lib/rails/generators/heracles/wrapper/install/install_generator.rb