Class: Flipper::Types::Actor

Inherits:
Flipper::Type show all
Defined in:
lib/flipper/types/actor.rb

Instance Attribute Summary collapse

Attributes inherited from Flipper::Type

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Flipper::Type

#eql?, wrap

Constructor Details

#initialize(thing) ⇒ Actor

Returns a new instance of Actor.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
# File 'lib/flipper/types/actor.rb', line 11

def initialize(thing)
  raise ArgumentError, 'thing cannot be nil' if thing.nil?

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

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



26
27
28
# File 'lib/flipper/types/actor.rb', line 26

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

Instance Attribute Details

#thingObject (readonly)

Returns the value of attribute thing.



9
10
11
# File 'lib/flipper/types/actor.rb', line 9

def thing
  @thing
end

Class Method Details

.wrappable?(thing) ⇒ Boolean

Returns:



4
5
6
7
# File 'lib/flipper/types/actor.rb', line 4

def self.wrappable?(thing)
  return false if thing.nil?
  thing.respond_to?(:flipper_id)
end

Instance Method Details

#respond_to?(*args) ⇒ Boolean

Returns:



22
23
24
# File 'lib/flipper/types/actor.rb', line 22

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