File: application_hostname.rb

package info (click to toggle)
ruby-unleash 3.2.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 252 kB
  • sloc: ruby: 1,098; makefile: 10; sh: 4
file content (25 lines) | stat: -rw-r--r-- 572 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require 'socket'

module Unleash
  module Strategy
    class ApplicationHostname < Base
      attr_accessor :hostname
      PARAM = 'hostnames'.freeze

      def initialize
        self.hostname = Socket.gethostname || 'undefined'
      end

      def name
        'applicationHostname'
      end

      # need: :params['hostnames']
      def is_enabled?(params = {}, _context = nil)
        return false unless params.is_a?(Hash) && params.has_key?(PARAM)

        params[PARAM].split(",").map(&:strip).map(&:downcase).include?(self.hostname)
      end
    end
  end
end