Sha256: 822aad6d6b42dbffc9fac96f542a7116e7521a79286697f2916b10faab62c62a

Contents?: true

Size: 904 Bytes

Versions: 1

Compression:

Stored size: 904 Bytes

Contents

module FirewallHelper
  def self.port
    BrokerConfig.current_adapter_port
  end

  COMMANDS = {
    darwin: {
      setup: [
        'lunchy stop rabbit'
      ],
      teardown: [
        'lunchy start rabbit'
      ]
    },
    linux: {
      setup: [
        'sudo service rabbitmq-server stop'
      ],
      teardown: [
        'sudo service rabbitmq-server start'
      ]
    }
  }

  def block_broker_port
    run_commands(:setup)
    @firewall_rule_set = true
  end

  def unblock_broker_port
    run_commands(:teardown) if @firewall_rule_set
    @firewall_rule_set = false
  end

  def run_commands(step)
    COMMANDS[os][step].each do |cmd|
      result = system(cmd)
      raise "command `#{cmd}` failed!" unless result
    end
  end

  def os
    if darwin?
      :darwin
    else
      :linux
    end
  end

  def darwin?
    system('uname | grep Darwin')
  end
end

World(FirewallHelper)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
message-driver-0.4.0 features/support/firewall_helper.rb