Sha256: 06ac6a5203afe78ad4d9ccbfa467e94887c9368184fe7c06724e607860ea018f

Contents?: true

Size: 1.67 KB

Versions: 15

Compression:

Stored size: 1.67 KB

Contents

#!/usr/bin/env ruby            
require 'optparse'

require File.expand_path(
    File.join(File.dirname(__FILE__), '..', 'lib', 'mole') )
    
require 'mole/db/migrate'

module Mole
  class Molify  
    # Performs db migration when the MOle is to be used in a persistent mode.
    def initialize( argv=ARGV )   
      option_parser = default_option_parser 
      option_parser.parse!(argv)
      puts options.inspect
      ::Mole::Db::Migrate.new( options ).apply
    end                  
            
    # access the options
    def options  #:nodoc:
      if not @options then      
        @options = OpenStruct.new 
        # Unless specified attempt to lookup config/database.yml
        @options.configuration = File.join( Dir.pwd, %w[config database.yml] )
        # Unless specified assumes test env
        @options.environment   = "test"    
        # Unless specficied migrates up
        @options.direction     = :up
      end
      return @options
    end

    def default_option_parser #:nodoc:
      OptionParser.new do |op|
        op.separator ""
        op.separator "Molify options"

        op.on( "-c", "--config FILE", "The location of the database configuration file." ) do |db|
          options.configuration = db
        end

        op.on("-e", "--env ENV", "The environment to run in." ) do |env|
          options.environment = env
        end
        
        op.on("-u", "--up", "Install MOle related tables") do |dir|
          options.direction= :up
        end

        op.on("-d", "--down", "Uninstall MOle related tables") do |dir|
          options.direction= :down
        end

        op.separator ""
      end
    end   
  end
end  

Mole::Molify.new(ARGV)



    

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
derailed-mole-1.0.10 bin/molify
mole-1.0.15 bin/molify
mole-1.0.0 bin/molify
mole-1.0.1 bin/molify
mole-0.0.1 bin/molify
mole-1.0.11 bin/molify
mole-1.0.9 bin/molify
mole-1.0.2 bin/molify
mole-1.0.3 bin/molify
mole-1.0.4 bin/molify
mole-1.0.5 bin/molify
mole-1.0.6 bin/molify
mole-1.0.7 bin/molify
mole-1.0.8 bin/molify
mole-1.0.12 bin/molify