Sha256: 3037ddc2cfa3ff4ad1c2937096df9731f54447f9e3a69db1bed98bee1d7c74ac

Contents?: true

Size: 1.59 KB

Versions: 12

Compression:

Stored size: 1.59 KB

Contents

require 'rails/generators'
require 'rails/generators/named_base'

module Ratchetio
  module Generators
    class RatchetioGenerator < ::Rails::Generators::Base
      argument :access_token, :type => :string, :banner => "access_token"

      source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))

      def create_initializer
        puts "creating initializer..."
        if access_token_configured?
          puts "It looks like you've already configured Ratchetio."
          puts "To re-create the config file, remove it first: config/initializers/ratchetio.rb"
          exit
        end

        puts "access token: " << access_token

        template 'initializer.rb', 'config/initializers/ratchetio.rb',
          :assigns => { :access_token => access_token_expr }

        # TODO run rake test task
      end

      #def add_options!(opt)
      #  opt.on('-a', '--access-token=token', String, "Your Ratchet.io project access token") { |v| options[:access_token] = v }
      #end
#
#      def manifest
#        if !access_token_configured? && !options[:access_token]
#          puts "access_token is required. Pass --access-token=YOUR_ACCESS_TOKEN"
#          exit
#        end
#        
#        record do |m|
#          m.template 'initializer.rb', 'config/initializers/ratchetio.rb',
#            :assigns => { :access_token => access_token_expr }
#          # TODO run rake test task
#        end
#      end

      def access_token_expr
        "'#{access_token}'"
      end

      def access_token_configured?
        File.exists?('config/initializers/ratchetio.rb')
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ratchetio-0.4.2 lib/generators/ratchetio/ratchetio_generator.rb
ratchetio-0.4.1 lib/generators/ratchetio/ratchetio_generator.rb
ratchetio-0.4.0 lib/generators/ratchetio/ratchetio_generator.rb
ratchetio-0.3.2 lib/generators/ratchetio/ratchetio_generator.rb
ratchetio-0.3.1 lib/generators/ratchetio/ratchetio_generator.rb
ratchetio-0.3.0 lib/generators/ratchetio/ratchetio_generator.rb
ratchetio-0.2.1 lib/generators/ratchetio/ratchetio_generator.rb
ratchetio-0.2.0 lib/generators/ratchetio/ratchetio_generator.rb
ratchetio-0.1.2 lib/generators/ratchetio/ratchetio_generator.rb
ratchetio-0.1.1 lib/generators/ratchetio/ratchetio_generator.rb
ratchetio-0.1.0 lib/generators/ratchetio/ratchetio_generator.rb
ratchetio-0.0.5 lib/generators/ratchetio/ratchetio_generator.rb