Sha256: 7512a2b31943aaa6679057134b45b35ff6afb2ac53de83b9b872d9cf68a41a31

Contents?: true

Size: 898 Bytes

Versions: 3

Compression:

Stored size: 898 Bytes

Contents

module Flipper
  module Types
    class Actor < Type
      def self.wrappable?(thing)
        return false if thing.nil?
        return true if thing.is_a?(Flipper::Types::Actor)
        thing.respond_to?(:flipper_id)
      end

      def self.wrap(thing)
        return thing if thing.is_a?(self)
        new(thing)
      end

      attr_reader :value

      def initialize(thing)
        if thing.nil?
          raise ArgumentError.new("thing cannot be nil")
        end

        unless thing.respond_to?(:flipper_id)
          raise ArgumentError.new("#{thing.inspect} must respond to flipper_id, but does not")
        end

        @thing = thing
        @value = thing.flipper_id.to_s
      end

      def respond_to?(*args)
        super || @thing.respond_to?(*args)
      end

      def method_missing(name, *args, &block)
        @thing.send name, *args, &block
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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