Sha256: 7ad35fdd5d886a390ea669148ceaada54a5ca78e517bb1659a66e7345c59861e

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

module Flipper
  module Gates
    class Actor < Gate
      # Internal: The name of the gate. Used for instrumentation, etc.
      def name
        :actor
      end

      # Internal: Name converted to value safe for adapter.
      def key
        :actors
      end

      def data_type
        :set
      end

      def description(value)
        if enabled?(value)
          actor_ids = value.to_a.sort.map { |id| id.inspect }
          "actors (#{actor_ids.join(', ')})"
        else
          'disabled'
        end
      end

      def enabled?(value)
        !Typecast.to_set(value).empty?
      end

      # Internal: Checks if the gate is open for a thing.
      #
      # Returns true if gate open for thing, false if not.
      def open?(thing, value, options = {})
        if thing.nil?
          false
        else
          if protects?(thing)
            actor = wrap(thing)
            enabled_actor_ids = value
            enabled_actor_ids.include?(actor.value)
          else
            false
          end
        end
      end

      def wrap(thing)
        Types::Actor.wrap(thing)
      end

      def protects?(thing)
        Types::Actor.wrappable?(thing)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flipper-0.7.0.beta2 lib/flipper/gates/actor.rb
flipper-0.7.0.beta1 lib/flipper/gates/actor.rb