Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Formatting. Ordered adapter methods all the same.

  • Loading branch information...
commit 3cfb49b88b7086dbe3d78ff6678dc90d736bc9ec 1 parent ec71181
@jnunemaker authored
View
45 lib/flipper/adapters/instrumented.rb
@@ -23,11 +23,11 @@ def initialize(adapter, options = {})
@instrumenter = options.fetch(:instrumenter, Flipper::Instrumenters::Noop)
end
- def get(feature)
+ # Public
+ def features
payload = {
- :operation => :get,
+ :operation => :features,
:adapter_name => name,
- :feature_name => feature.name,
}
@instrumenter.instrument(InstrumentationName, payload) { |payload|
@@ -35,13 +35,12 @@ def get(feature)
}
end
- # Public: Enable feature gate for thing.
- def enable(feature, gate, thing)
+ # Public
+ def add(feature)
payload = {
- :operation => :enable,
+ :operation => :add,
:adapter_name => name,
:feature_name => feature.name,
- :gate_name => gate.name,
}
@instrumenter.instrument(InstrumentationName, payload) { |payload|
@@ -49,13 +48,12 @@ def enable(feature, gate, thing)
}
end
- # Public: Disable feature gate for thing.
- def disable(feature, gate, thing)
+ # Public
+ def remove(feature)
payload = {
- :operation => :disable,
+ :operation => :remove,
:adapter_name => name,
:feature_name => feature.name,
- :gate_name => gate.name,
}
@instrumenter.instrument(InstrumentationName, payload) { |payload|
@@ -63,11 +61,12 @@ def disable(feature, gate, thing)
}
end
- # Public: Returns all the features that the adapter knows of.
- def features
+ # Public
+ def clear(feature)
payload = {
- :operation => :features,
+ :operation => :clear,
:adapter_name => name,
+ :feature_name => feature.name,
}
@instrumenter.instrument(InstrumentationName, payload) { |payload|
@@ -75,10 +74,10 @@ def features
}
end
- # Internal: Adds a known feature to the set of features.
- def add(feature)
+ # Public
+ def get(feature)
payload = {
- :operation => :add,
+ :operation => :get,
:adapter_name => name,
:feature_name => feature.name,
}
@@ -88,11 +87,13 @@ def add(feature)
}
end
- def remove(feature)
+ # Public
+ def enable(feature, gate, thing)
payload = {
- :operation => :remove,
+ :operation => :enable,
:adapter_name => name,
:feature_name => feature.name,
+ :gate_name => gate.name,
}
@instrumenter.instrument(InstrumentationName, payload) { |payload|
@@ -100,11 +101,13 @@ def remove(feature)
}
end
- def clear(feature)
+ # Public
+ def disable(feature, gate, thing)
payload = {
- :operation => :clear,
+ :operation => :disable,
:adapter_name => name,
:feature_name => feature.name,
+ :gate_name => gate.name,
}
@instrumenter.instrument(InstrumentationName, payload) { |payload|
View
44 lib/flipper/adapters/memoizable.rb
@@ -27,58 +27,58 @@ def initialize(adapter)
end
# Public
- def get(feature)
+ def features
if memoizing?
- cache.fetch(feature) { cache[feature] = super }
+ cache.fetch(FeaturesKey) {
+ cache[FeaturesKey] = super
+ }
else
super
end
end
# Public
- def enable(feature, gate, thing)
+ def add(feature)
result = super
- cache.delete(feature) if memoizing?
+ cache.delete(FeaturesKey) if memoizing?
result
end
# Public
- def disable(feature, gate, thing)
+ def remove(feature)
+ result = super
+ if memoizing?
+ cache.delete(FeaturesKey)
+ cache.delete(feature)
+ end
+ result
+ end
+
+ # Public
+ def clear(feature)
result = super
cache.delete(feature) if memoizing?
result
end
# Public
- def features
+ def get(feature)
if memoizing?
- cache.fetch(FeaturesKey) {
- cache[FeaturesKey] = super
- }
+ cache.fetch(feature) { cache[feature] = super }
else
super
end
end
# Public
- def add(feature)
- result = super
- cache.delete(FeaturesKey) if memoizing?
- result
- end
-
- # Public
- def remove(feature)
+ def enable(feature, gate, thing)
result = super
- if memoizing?
- cache.delete(FeaturesKey)
- cache.delete(feature)
- end
+ cache.delete(feature) if memoizing?
result
end
# Public
- def clear(feature)
+ def disable(feature, gate, thing)
result = super
cache.delete(feature) if memoizing?
result
View
55 lib/flipper/adapters/memory.rb
@@ -16,6 +16,32 @@ def initialize(source = nil)
@name = :memory
end
+ # Public: The set of known features.
+ def features
+ set_members(FeaturesKey)
+ end
+
+ # Public: Adds a feature to the set of known features.
+ def add(feature)
+ features.add(feature.name.to_s)
+ true
+ end
+
+ # Public: Removes a feature from the set of known features and clears
+ # all the values for the feature.
+ def remove(feature)
+ features.delete(feature.name.to_s)
+ clear(feature)
+ true
+ end
+
+ # Public: Clears all the gate values for a feature.
+ def clear(feature)
+ feature.gates.each do |gate|
+ delete key(feature, gate)
+ end
+ end
+
# Public
def get(feature)
result = {}
@@ -64,32 +90,7 @@ def disable(feature, gate, thing)
true
end
- # Public: Adds a feature to the set of known features.
- def add(feature)
- features.add(feature.name.to_s)
- true
- end
-
- # Public: Clears all the gate values for a feature.
- def clear(feature)
- feature.gates.each do |gate|
- delete key(feature, gate)
- end
- end
-
- # Public: Removes a feature from the set of known features and clears
- # all the values for the feature.
- def remove(feature)
- features.delete(feature.name.to_s)
- clear(feature)
- true
- end
-
- # Public: The set of known features.
- def features
- set_members(FeaturesKey)
- end
-
+ # Public
def inspect
attributes = [
"name=:memory",
@@ -98,7 +99,7 @@ def inspect
"#<#{self.class.name}:#{object_id} #{attributes.join(', ')}>"
end
- # private
+ # Private
def key(feature, gate)
"#{feature.key}/#{gate.key}"
end
Please sign in to comment.
Something went wrong with that request. Please try again.