Sha256: c79096d1f8b1876d814c9aaf6456c7bed3a5f96b2897140befe6dfdbaa97ffd5

Contents?: true

Size: 911 Bytes

Versions: 5

Compression:

Stored size: 911 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'
      ]
    }
  }.freeze

  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

5 entries across 5 versions & 1 rubygems

Version Path
message-driver-1.0.1 features/support/firewall_helper.rb
message-driver-1.0.0 features/support/firewall_helper.rb
message-driver-0.7.2 features/support/firewall_helper.rb
message-driver-0.7.1 features/support/firewall_helper.rb
message-driver-0.7.0 features/support/firewall_helper.rb