Sha256: b355ea4ee1000a9eccf1db92b4d4e80c44025a882edb4c13bdd2ced73cf354ed

Contents?: true

Size: 897 Bytes

Versions: 4

Compression:

Stored size: 897 Bytes

Contents

require 'lib/attributes.rb'
require 'rubygems'
require 'active_record'
require 'yaml'

options = YAML.load <<-txt
  adapter: postgresql
  database: votelink
  username: www
  host: localhost 
  encoding: UTF8
txt
ActiveRecord::Base.establish_connection options

module MigrationDSL
  attribute :migration

  def migration_class
    model = self
    Class.new(::ActiveRecord::Migration) do
      singleton_class =
        class << self
          self
        end
      singleton_class.module_eval{ attribute :model => model }
      singleton_class.module_eval &model.migration
    end
  end
end

class Table < ActiveRecord::Base
  extend MigrationDSL
end

class Jobs < Table
  migration do
    def up
      create_table model.table_name, :primary_key => model.primary_key do |t|
        t.column 'rockin', :text
      end
    end

    def down
      create_table model.table_name
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
attributes1-5.0.3 b.rb
attributes1-5.0.2 b.rb
attributes-5.0.0 b.rb
attributes-5.0.1 b.rb