Class: Flipper::Types::Actor

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(thing) ⇒ Actor

Returns a new instance of Actor.

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
# File 'lib/flipper/types/actor.rb', line 20

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

  @thing = thing
  @identifier = if thing.respond_to?(:identifier)
    thing.identifier
  else
    thing
  end.to_i
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



39
40
41
# File 'lib/flipper/types/actor.rb', line 39

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

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



18
19
20
# File 'lib/flipper/types/actor.rb', line 18

def identifier
  @identifier
end

Class Method Details

.wrap(thing) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/flipper/types/actor.rb', line 10

def self.wrap(thing)
  if thing.is_a?(Flipper::Types::Actor)
    thing
  else
    new(thing)
  end
end

.wrappable?(thing) ⇒ Boolean

Returns:



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

def self.wrappable?(thing)
  thing.is_a?(Flipper::Types::Actor) ||
    thing.respond_to?(:identifier) ||
    thing.respond_to?(:to_i)
end

Instance Method Details

#respond_to?(*args) ⇒ Boolean

Returns:



35
36
37
# File 'lib/flipper/types/actor.rb', line 35

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

#valueObject



31
32
33
# File 'lib/flipper/types/actor.rb', line 31

def value
  @identifier
end