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.



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

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

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:



24
25
26
# File 'lib/flipper/types/actor.rb', line 24

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