Sha256: 10bbb340878602a68059e07c5aef0d09736db0c20e00562714e8a60950843d8e

Contents?: true

Size: 916 Bytes

Versions: 3

Compression:

Stored size: 916 Bytes

Contents

require "scenic/command_recorder/statement_arguments"

module Scenic
  module CommandRecorder
    def create_view(*args)
      record(:create_view, args)
    end

    def drop_view(*args)
      record(:drop_view, args)
    end

    def update_view(*args)
      record(:update_view, args)
    end

    def invert_create_view(args)
      [:drop_view, args]
    end

    def invert_drop_view(args)
      perform_scenic_inversion(:create_view, args)
    end

    def invert_update_view(args)
      perform_scenic_inversion(:update_view, args)
    end

    private

    def perform_scenic_inversion(method, args)
      scenic_args = StatementArguments.new(args)

      if scenic_args.revert_to_version.nil?
        message = "#{method} is reversible only if given a revert_to_version"
        raise ActiveRecord::IrreversibleMigration, message
      end

      [method, scenic_args.invert_version.to_a]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
scenic-0.3.0 lib/scenic/command_recorder.rb
scenic-0.2.1 lib/scenic/command_recorder.rb
scenic-0.2.0 lib/scenic/command_recorder.rb