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(actor) ⇒ 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(actor)
  raise ArgumentError, 'actor cannot be nil' if actor.nil?

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

  @actor = actor
  @value = actor.flipper_id.to_s
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

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

Instance Attribute Details

#actorObject (readonly)

Returns the value of attribute actor.



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

def actor
  @actor
end

Class Method Details

.wrappable?(actor) ⇒ Boolean

Returns:



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

def self.wrappable?(actor)
  return false if actor.nil?
  actor.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 || @actor.respond_to?(*args)
end