Sha256: 365f58c815bea98754dac238dd498fe7cccf64f4e7427ae2a33fb2ed0bf3c957

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

module UsesguidMigrations::ActiveRecordExtensions::ConnectionAdapters
  module TableDefinition

    def self.included( base )
      base.class_eval do
        include InstanceMethods
        attr_accessor :primary_key_name
        attr_accessor :associative_keys
      end
    end

    module InstanceMethods
      def guid_primary_key( name )
        @primary_key_name = name
        column( name, :binary, :limit => 22, :null => false )
      end

      def references_with_guid( name, options={} )
        name = name.to_s
        name = "#{name}_id" unless name.end_with?( "_id" )
        guid( name, options )
      end

      def guid( name, options={} )
        @associative_keys = [] if @associative_keys.nil?
        options.merge!( :limit => 22 )
        # make not nullable the default for a guid column as it is likely a foreign key
        options.merge!( :null => false ) unless options[:null] == true
        @associative_keys << OpenStruct.new( :name => name, :options => options )
        column( name, :binary, options )
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
usesguid_migrations-1.0.3 lib/usesguid_migrations/active_record_extensions/connection_adapters/table_definition.rb
usesguid_migrations-1.0.2 lib/usesguid_migrations/active_record_extensions/connection_adapters/table_definition.rb