Sha256: 901f5a636bffa43be66ce277705a2db66a5a67200a613e59d944942871290bef

Contents?: true

Size: 1.03 KB

Versions: 50

Compression:

Stored size: 1.03 KB

Contents

module Switchman
  module Shackles
    module ClassMethods
      def ensure_handler
        raise "This should not be called with switchman installed"
      end

      # drops the save_handler and ensure_handler calls from the vanilla
      # Shackles' implementation.
      def activate!(environment)
        environment ||= :master
        activated_environments << environment
        old_environment = self.environment
        @environment = environment
        old_environment
      end

      # since activate! really is just a variable swap now, it's safe to use in
      # the ensure block, simplifying the implementation
      def activate(environment)
        old_environment = activate!(environment)
        yield
      ensure
        activate!(old_environment)
      end
    end

    def self.included(klass)
      klass.extend(ClassMethods)
      klass.singleton_class.send(:remove_method, :ensure_handler)
      klass.singleton_class.send(:remove_method, :activate!)
      klass.singleton_class.send(:remove_method, :activate)
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
switchman-1.2.26 lib/switchman/shackles.rb
switchman-1.2.25 lib/switchman/shackles.rb
switchman-1.2.24 lib/switchman/shackles.rb
switchman-1.2.23 lib/switchman/shackles.rb
switchman-1.2.22 lib/switchman/shackles.rb
switchman-1.2.21 lib/switchman/shackles.rb
switchman-1.2.20 lib/switchman/shackles.rb
switchman-1.2.19 lib/switchman/shackles.rb
switchman-1.2.18 lib/switchman/shackles.rb
switchman-1.2.17 lib/switchman/shackles.rb