Sha256: 455e7055f9f02fa8525443e70063385b9f53f0b06cab5b5108aa51c8a3c7370e

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'rails'
require 'rails/generators'
require 'rails/generators/migration'

# = Earth Distance Railtie
#
# Creates a new railtie for 2 reasons:
#
# * Initialize ActiveRecord properly
# * Add earthdistance:setup generator 
class EarthDistance < Rails::Railtie
  # Creates the earthdistance:setup generator. This generator creates a migration that
  # adds earthdistance support for your database. If fact, it's just the sql from the
  # contrib inside a migration. But it' s handy, isn't it?
  #
  # To use your generator, simply run it in your project:
  #
  #   rails g earthdistance:setup
  class Setup < Rails::Generators::Base
    include Rails::Generators::Migration

    def self.source_root
      @source_root ||= File.join(File.dirname(__FILE__), '..', 'templates')
    end

    def self.next_migration_number(dirname)
      if ActiveRecord::Base.timestamped_migrations
        Time.now.utc.strftime("%Y%m%d%H%M%S")
      else
        "%.3d" % (current_migration_number(dirname) + 1)
      end
    end

    def create_migration_file
      migration_template 'setup_earthdistance.rb', 'db/migrate/setup_earthdistance.rb'
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-postgres-earthdistance-0.3.0 lib/activerecord-postgres-earthdistance/railties.rb