Sha256: 92e79f3ccf0d504e233079f0429196f6b746e9093fef10fae4de5c92cac2caaa

Contents?: true

Size: 1.18 KB

Versions: 16

Compression:

Stored size: 1.18 KB

Contents

require 'diesel/generators/install_base'

module Clearance
  module Generators
    class InstallGenerator < Diesel::Generators::InstallBase
      def install
        template "clearance.rb", "config/initializers/clearance.rb"

        inject_into_class "app/controllers/application_controller.rb", ApplicationController do
          "  include Clearance::Authentication\n"
        end

        user_model = "app/models/user.rb"
        if File.exists?(user_model)
          inject_into_class user_model, User do
            "include Clearance::User"
          end
        else
          template "user.rb", user_model
        end

        if File.exists?("spec")
          template "spec/factories.rb", "spec/factories/clearance.rb"
        else
          template "spec/factories.rb", "test/factories/clearance.rb"
        end

        readme "README"
      end

      private

      def migrations
        if users_table_exists?
          super.reject { |name| name.include?("create") } + ["db/migrate/upgrade_clearance_to_diesel.rb"]
        else
          super
        end
      end

      def users_table_exists?
        ActiveRecord::Base.connection.table_exists?(:users)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
clearance-1.0.0.rc2 lib/generators/clearance/install/install_generator.rb
clearance-1.0.0.rc1 lib/generators/clearance/install/install_generator.rb
clearance-0.16.3 lib/generators/clearance/install/install_generator.rb
clearance-0.16.2 lib/generators/clearance/install/install_generator.rb
clearance-0.16.1 lib/generators/clearance/install/install_generator.rb
clearance-0.16.0 lib/generators/clearance/install/install_generator.rb
clearance-0.15.0 lib/generators/clearance/install/install_generator.rb
clearance-0.14.0 lib/generators/clearance/install/install_generator.rb
clearance-0.13.2 lib/generators/clearance/install/install_generator.rb
clearance-0.13.0 lib/generators/clearance/install/install_generator.rb
clearance-0.12.0 lib/generators/clearance/install/install_generator.rb
clearance-0.11.2 lib/generators/clearance/install/install_generator.rb
clearance-0.11.1 lib/generators/clearance/install/install_generator.rb
clearance-0.11.0 lib/generators/clearance/install/install_generator.rb
clearance-0.10.5 lib/generators/clearance/install/install_generator.rb
clearance-0.10.4 lib/generators/clearance/install/install_generator.rb