Class: Flipper::Gate

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/flipper/gate.rb

Constant Summary collapse

InstrumentationName =

Private: The name of instrumentation events.

"gate_operation.#{InstrumentationNamespace}"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature_name, options = {}) ⇒ Gate

Public



18
19
20
21
# File 'lib/flipper/gate.rb', line 18

def initialize(feature_name, options = {})
  @feature_name = feature_name
  @instrumenter = options.fetch(:instrumenter, Flipper::Instrumenters::Noop)
end

Instance Attribute Details

#feature_nameObject (readonly)

Private



12
13
14
# File 'lib/flipper/gate.rb', line 12

def feature_name
  @feature_name
end

#instrumenterObject (readonly)

Private: What is used to instrument all the things.



15
16
17
# File 'lib/flipper/gate.rb', line 15

def instrumenter
  @instrumenter
end

Instance Method Details

#data_typeObject



33
34
35
# File 'lib/flipper/gate.rb', line 33

def data_type
  raise 'Not implemented'
end

#description(value) ⇒ Object



49
50
51
# File 'lib/flipper/gate.rb', line 49

def description(value)
  raise 'Not implemented'
end

#disable(thing) ⇒ Object



41
42
43
# File 'lib/flipper/gate.rb', line 41

def disable(thing)
  raise 'Not implemented'
end

#enable(thing) ⇒ Object



37
38
39
# File 'lib/flipper/gate.rb', line 37

def enable(thing)
  raise 'Not implemented'
end

#enabled?(value) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/flipper/gate.rb', line 45

def enabled?(value)
  raise 'Not implemented'
end

#inspectObject

Public: Pretty string version for debugging.



74
75
76
77
78
79
# File 'lib/flipper/gate.rb', line 74

def inspect
  attributes = [
    "feature_name=#{feature_name.inspect}",
  ]
  "#<#{self.class.name}:#{object_id} #{attributes.join(', ')}>"
end

#instrument(operation, thing) ⇒ Object

Private



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/flipper/gate.rb', line 82

def instrument(operation, thing)
  payload = {
    :thing => thing,
    :operation => operation,
    :gate_name => name,
    :feature_name => @feature_name,
  }

  @instrumenter.instrument(InstrumentationName, payload) {
    payload[:result] = yield(payload) if block_given?
  }
end

#keyObject

Private: Name converted to value safe for adapter. Implemented in subclass.



29
30
31
# File 'lib/flipper/gate.rb', line 29

def key
  raise 'Not implemented'
end

#nameObject

Public: The name of the gate. Implemented in subclass.



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

def name
  raise 'Not implemented'
end

#open?(thing) ⇒ Boolean

Internal: Check if a gate is open for a thing. Implemented in subclass.

Returns true if gate open for thing, false if not.

Returns:

  • (Boolean)


56
57
58
# File 'lib/flipper/gate.rb', line 56

def open?(thing)
  false
end

#protects?(thing) ⇒ Boolean

Internal: Check if a gate is protects a thing. Implemented in subclass.

Returns true if gate protects thing, false if not.

Returns:

  • (Boolean)


63
64
65
# File 'lib/flipper/gate.rb', line 63

def protects?(thing)
  false
end

#wrap(thing) ⇒ Object

Internal: Allows gate to wrap thing using one of the supported flipper types so adapters always get something that responds to value.



69
70
71
# File 'lib/flipper/gate.rb', line 69

def wrap(thing)
  thing
end