Permalink
Browse files

Adapters should return symbolized hash from #get.

Having adapter return gate => value seems weird. I'm thinking keep the
data transport really stupid and just return a hash with keys and
values.
  • Loading branch information...
1 parent 51d50b4 commit 04e981b0c37283a847afc8cc77dd031ad321fc27 @jnunemaker committed Feb 15, 2013
Showing with 33 additions and 33 deletions.
  1. +1 −1 lib/flipper/adapters/memory.rb
  2. +5 −5 lib/flipper/feature.rb
  3. +27 −27 lib/flipper/spec/shared_adapter_specs.rb
@@ -19,7 +19,7 @@ def get(feature)
result = {}
feature.gates.each do |gate|
- result[gate] = case gate.data_type
+ result[gate.key] = case gate.data_type
when :boolean, :integer
read key(feature, gate)
when :set
@@ -71,7 +71,7 @@ def enabled?(thing = nil)
gate_values = adapter.get(self)
gate = gates.detect { |gate|
- gate.open?(thing, gate_values[gate])
+ gate.open?(thing, gate_values[gate.key])
}
if gate.nil?
@@ -86,7 +86,7 @@ def enabled?(thing = nil)
# Public
def state
gate_values = adapter.get(self)
- boolean_value = gate_values[boolean_gate]
+ boolean_value = gate_values[:boolean]
if boolean_gate.enabled?(boolean_value)
:on
@@ -100,14 +100,14 @@ def state
# Public
def description
gate_values = adapter.get(self)
- boolean_value = gate_values[boolean_gate]
+ boolean_value = gate_values[:boolean]
conditional_gates = conditional_gates(gate_values)
if boolean_gate.enabled?(boolean_value)
boolean_gate.description(boolean_value).capitalize
elsif conditional_gates.any?
fragments = conditional_gates.map { |gate|
- value = gate_values[gate]
+ value = gate_values[gate.key]
gate.description(value)
}
@@ -172,7 +172,7 @@ def non_boolean_gates
# Private
def conditional_gates(gate_values)
@conditional_gates ||= non_boolean_gates.select { |gate|
- value = gate_values[gate]
+ value = gate_values[gate.key]
gate.enabled?(value)
}
end
@@ -33,24 +33,24 @@
it "returns correct default values for the gates if none are enabled" do
subject.get(feature).should eq({
- boolean_gate => nil,
- group_gate => Set.new,
- actor_gate => Set.new,
- actors_gate => nil,
- random_gate => nil,
+ :boolean => nil,
+ :groups => Set.new,
+ :actors => Set.new,
+ :percentage_of_actors => nil,
+ :percentage_of_random => nil,
})
end
it "can enable get value for boolean gate" do
subject.enable(feature, boolean_gate, flipper.boolean).should be_true
result = subject.get(feature)
- result[boolean_gate].should eq('true')
+ result[:boolean].should eq('true')
subject.disable(feature, boolean_gate, flipper.boolean(false)).should be_true
result = subject.get(feature)
- result[boolean_gate].should be_nil
+ result[:boolean].should be_nil
end
it "fully disables all enabled things with boolean gate disable" do
@@ -64,11 +64,11 @@
subject.disable(feature, boolean_gate, flipper.boolean).should be_true
subject.get(feature).should eq({
- boolean_gate => nil,
- group_gate => Set.new,
- actor_gate => Set.new,
- actors_gate => nil,
- random_gate => nil,
+ :boolean => nil,
+ :groups => Set.new,
+ :actors => Set.new,
+ :percentage_of_actors => nil,
+ :percentage_of_random => nil,
})
end
@@ -77,15 +77,15 @@
subject.enable(feature, group_gate, flipper.group(:early_access)).should be_true
result = subject.get(feature)
- result[group_gate].should eq(Set['admins', 'early_access'])
+ result[:groups].should eq(Set['admins', 'early_access'])
subject.disable(feature, group_gate, flipper.group(:early_access)).should be_true
result = subject.get(feature)
- result[group_gate].should eq(Set['admins'])
+ result[:groups].should eq(Set['admins'])
subject.disable(feature, group_gate, flipper.group(:admins)).should be_true
result = subject.get(feature)
- result[group_gate].should eq(Set.new)
+ result[:groups].should eq(Set.new)
end
it "can enable, disable and get value for actor gate" do
@@ -96,65 +96,65 @@
subject.enable(feature, actor_gate, flipper.actor(actor_asdf)).should be_true
result = subject.get(feature)
- result[actor_gate].should eq(Set['22', 'asdf'])
+ result[:actors].should eq(Set['22', 'asdf'])
subject.disable(feature, actor_gate, flipper.actor(actor_22)).should be_true
result = subject.get(feature)
- result[actor_gate].should eq(Set['asdf'])
+ result[:actors].should eq(Set['asdf'])
subject.disable(feature, actor_gate, flipper.actor(actor_asdf)).should be_true
result = subject.get(feature)
- result[actor_gate].should eq(Set.new)
+ result[:actors].should eq(Set.new)
end
it "can enable, disable and get value for percentage of actors gate" do
subject.enable(feature, actors_gate, flipper.actors(15)).should be_true
result = subject.get(feature)
- result[actors_gate].should eq('15')
+ result[:percentage_of_actors].should eq('15')
subject.disable(feature, actors_gate, flipper.actors(0)).should be_true
result = subject.get(feature)
- result[actors_gate].should eq('0')
+ result[:percentage_of_actors].should eq('0')
end
it "can enable, disable and get value for percentage of random gate" do
subject.enable(feature, random_gate, flipper.random(10)).should be_true
result = subject.get(feature)
- result[random_gate].should eq('10')
+ result[:percentage_of_random].should eq('10')
subject.disable(feature, random_gate, flipper.random(0)).should be_true
result = subject.get(feature)
- result[random_gate].should eq('0')
+ result[:percentage_of_random].should eq('0')
end
it "converts boolean value to a string" do
subject.enable(feature, boolean_gate, flipper.boolean).should be_true
result = subject.get(feature)
- result[boolean_gate].should eq('true')
+ result[:boolean].should eq('true')
end
it "converts the actor value to a string" do
subject.enable(feature, actor_gate, flipper.actor(actor_class.new(22))).should be_true
result = subject.get(feature)
- result[actor_gate].should eq(Set['22'])
+ result[:actors].should eq(Set['22'])
end
it "converts group value to a string" do
subject.enable(feature, group_gate, flipper.group(:admins)).should be_true
result = subject.get(feature)
- result[group_gate].should eq(Set['admins'])
+ result[:groups].should eq(Set['admins'])
end
it "converts percentage of random integer value to a string" do
subject.enable(feature, random_gate, flipper.random(10)).should be_true
result = subject.get(feature)
- result[random_gate].should eq('10')
+ result[:percentage_of_random].should eq('10')
end
it "converts percentage of actors integer value to a string" do
subject.enable(feature, actors_gate, flipper.actors(10)).should be_true
result = subject.get(feature)
- result[actors_gate].should eq('10')
+ result[:percentage_of_actors].should eq('10')
end
it "can add and list known features" do

0 comments on commit 04e981b

Please sign in to comment.