Sha256: fc3d66e2edf111e6af034a63bcde033aa97ce1e803f6db6c063cfd013d1f884b

Contents?: true

Size: 1.45 KB

Versions: 7

Compression:

Stored size: 1.45 KB

Contents

require 'active_support/deprecation'

module TbCheckout
  module Schema

    def self.included(base)
      ActiveRecord::ConnectionAdapters::Table.send :include, TableDefinition
      ActiveRecord::ConnectionAdapters::TableDefinition.send :include, TableDefinition
      ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, Statements
      ActiveRecord::Migration::CommandRecorder.send :include, CommandRecorder
    end

    module Statements
      # Add purchasable columns to the given database table
      # 
      def add_tb_checkout_purchasable(table_name)
        add_column(table_name, :description, :string)
        add_column(table_name, :price, :decimal, :precision => 8, :scale => 2)
      end

      # Remove purchasable columns from the given database table
      #
      def remove_tb_checkout_purchasable(table_name)
        remove_column(table_name, :description)
        remove_column(table_name, :price)
      end
    end

    module TableDefinition
      # Add purchasable columns to the given database table
      # 
      def tb_checkout_purchasable
        column(:description, :string)
        column(:price, :decimal, :precision => 8, :scale => 2)
      end
    end

    module CommandRecorder #:nodoc:
      def add_tb_checkout_purchasable(*args)
        record(:add_tb_checkout_purchasable, args)
      end

private

      def invert_add_tb_checkout_purchasable(args)
        [:remove_tb_checkout_purchasable, args]
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tb_checkout-1.1.1 lib/tb_checkout/schema.rb
tb_checkout-1.1.0 lib/tb_checkout/schema.rb
tb_checkout-1.0.7 lib/tb_checkout/schema.rb
tb_checkout-1.0.6 lib/tb_checkout/schema.rb
tb_checkout-1.0.5 lib/tb_checkout/schema.rb
tb_checkout-1.0.4 lib/tb_checkout/schema.rb
tb_checkout-1.0.3 lib/tb_checkout/schema.rb