Class: Flipper::Adapters::PStore
- Inherits:
-
Object
- Object
- Flipper::Adapters::PStore
- Includes:
- Flipper::Adapter
- Defined in:
- lib/flipper/adapters/pstore.rb
Overview
Public: Adapter based on Ruby’s pstore database. Perfect for when a local file is good enough for storing features.
Constant Summary collapse
- FeaturesKey =
:flipper_features
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Public: The name of the adapter.
-
#path ⇒ Object
readonly
Public: The path to where the file is stored.
Instance Method Summary collapse
-
#add(feature) ⇒ Object
Public: Adds a feature to the set of known features.
-
#clear(feature) ⇒ Object
Public: Clears all the gate values for a feature.
-
#disable(feature, gate, thing) ⇒ Object
Public.
-
#enable(feature, gate, thing) ⇒ Object
Public.
-
#features ⇒ Object
Public: The set of known features.
-
#get(feature) ⇒ Object
Public.
-
#initialize(path = "flipper.pstore") ⇒ PStore
constructor
Public.
-
#inspect ⇒ Object
Public.
-
#remove(feature) ⇒ Object
Public: Removes a feature from the set of known features and clears all the values for the feature.
Constructor Details
#initialize(path = "flipper.pstore") ⇒ PStore
Public
20 21 22 23 24 |
# File 'lib/flipper/adapters/pstore.rb', line 20 def initialize(path = "flipper.pstore") @path = path @store = ::PStore.new(path) @name = :pstore end |
Instance Attribute Details
#name ⇒ Object (readonly)
Public: The name of the adapter.
14 15 16 |
# File 'lib/flipper/adapters/pstore.rb', line 14 def name @name end |
#path ⇒ Object (readonly)
Public: The path to where the file is stored.
17 18 19 |
# File 'lib/flipper/adapters/pstore.rb', line 17 def path @path end |
Instance Method Details
#add(feature) ⇒ Object
Public: Adds a feature to the set of known features.
32 33 34 35 |
# File 'lib/flipper/adapters/pstore.rb', line 32 def add(feature) set_add FeaturesKey, feature.key true end |
#clear(feature) ⇒ Object
Public: Clears all the gate values for a feature.
46 47 48 49 50 51 |
# File 'lib/flipper/adapters/pstore.rb', line 46 def clear(feature) feature.gates.each do |gate| delete key(feature, gate) end true end |
#disable(feature, gate, thing) ⇒ Object
Public
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/flipper/adapters/pstore.rb', line 86 def disable(feature, gate, thing) case gate.data_type when :boolean clear(feature) when :integer write key(feature, gate), thing.value.to_s when :set set_delete key(feature, gate), thing.value.to_s else raise "#{gate} is not supported by this adapter yet" end true end |
#enable(feature, gate, thing) ⇒ Object
Public
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/flipper/adapters/pstore.rb', line 72 def enable(feature, gate, thing) case gate.data_type when :boolean, :integer write key(feature, gate), thing.value.to_s when :set set_add key(feature, gate), thing.value.to_s else raise "#{gate} is not supported by this adapter yet" end true end |
#features ⇒ Object
Public: The set of known features.
27 28 29 |
# File 'lib/flipper/adapters/pstore.rb', line 27 def features set_members FeaturesKey end |
#get(feature) ⇒ Object
Public
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/flipper/adapters/pstore.rb', line 54 def get(feature) result = {} feature.gates.each do |gate| result[gate.key] = case gate.data_type when :boolean, :integer read key(feature, gate) when :set set_members key(feature, gate) else raise "#{gate} is not supported by this adapter yet" end end result end |
#inspect ⇒ Object
Public
102 103 104 105 106 107 108 109 |
# File 'lib/flipper/adapters/pstore.rb', line 102 def inspect attributes = [ "name=#{@name.inspect}", "path=#{@path.inspect}", "store=#{@store}", ] "#<#{self.class.name}:#{object_id} #{attributes.join(', ')}>" end |
#remove(feature) ⇒ Object
Public: Removes a feature from the set of known features and clears all the values for the feature.
39 40 41 42 43 |
# File 'lib/flipper/adapters/pstore.rb', line 39 def remove(feature) set_delete FeaturesKey, feature.key clear(feature) true end |