Class: StorageRepository
- Inherits:
-
Repository
- Object
- Closeable
- Repository
- StorageRepository
- Defined in:
- lib/ff/ruby/server/sdk/api/storage_repository.rb
Instance Method Summary collapse
- #close ⇒ Object
- #delete_flag(identifier) ⇒ Object
- #delete_segment(identifier) ⇒ Object
- #find_flags_by_segment(identifier) ⇒ Object
- #get_flag(identifier, cacheable = true) ⇒ Object
- #get_segment(identifier, cacheable = true) ⇒ Object
-
#initialize(cache, callback = nil, store = nil, logger = nil) ⇒ StorageRepository
constructor
A new instance of StorageRepository.
- #set_flag(identifier, feature_config) ⇒ Object
- #set_segment(identifier, segment) ⇒ Object
Constructor Details
#initialize(cache, callback = nil, store = nil, logger = nil) ⇒ StorageRepository
Returns a new instance of StorageRepository.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ff/ruby/server/sdk/api/storage_repository.rb', line 7 def initialize(cache, callback = nil, store = nil, logger = nil) @cache = cache @store = store @callback = callback if logger != nil @logger = logger else @logger = Logger.new(STDOUT) end end |
Instance Method Details
#close ⇒ Object
224 225 226 227 228 229 230 |
# File 'lib/ff/ruby/server/sdk/api/storage_repository.rb', line 224 def close if @store != nil @store.close end end |
#delete_flag(identifier) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/ff/ruby/server/sdk/api/storage_repository.rb', line 172 def delete_flag(identifier) flag_key = format_flag_key(identifier) if @store != nil @store.delete(flag_key) @logger.debug "Flag " + identifier + " successfully deleted from store" end @cache.delete(flag_key) @logger.debug "Flag " + identifier + " successfully deleted from cache" if @callback != nil unless @callback.kind_of?(RepositoryCallback) raise "The 'callback' parameter must be of '" + RepositoryCallback.to_s + "' data type" end @callback.on_flag_deleted(identifier) end end |
#delete_segment(identifier) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/ff/ruby/server/sdk/api/storage_repository.rb', line 198 def delete_segment(identifier) segment_key = format_segment_key(identifier) if @store != nil @store.delete(segment_key) @logger.debug "Segment " + identifier + " successfully deleted from store" end @cache.delete(segment_key) @logger.debug "Segment " + identifier + " successfully deleted from cache" if @callback != nil unless @callback.kind_of?(RepositoryCallback) raise "The 'callback' parameter must be of '" + RepositoryCallback.to_s + "' data type" end @callback.on_segment_deleted(identifier) end end |
#find_flags_by_segment(identifier) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ff/ruby/server/sdk/api/storage_repository.rb', line 70 def find_flags_by_segment(identifier) result = [] keys = @cache.keys if @store != nil keys = @store.keys end keys.each do |key| flag = get_flag(key) if flag != nil && !flag.rules.length > 0 flag.rules.each do |rule| rule.clauses.each do |clause| if clause.op == Operators.SEGMENT_MATCH && clause.values.include(identifier) result.push(flag.feature) end end end end end result end |
#get_flag(identifier, cacheable = true) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ff/ruby/server/sdk/api/storage_repository.rb', line 22 def get_flag(identifier, cacheable = true) flag_key = format_flag_key(identifier) flag = @cache.get(flag_key) if flag != nil return flag end if @store != nil flag = @store.get(flag_key) if flag != nil && cacheable @cache.set(flag_key, flag) end return flag end nil end |
#get_segment(identifier, cacheable = true) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ff/ruby/server/sdk/api/storage_repository.rb', line 46 def get_segment(identifier, cacheable = true) segment_key = format_segment_key(identifier) segment = @cache.get(segment_key) if segment != nil return segment end if @store != nil segment = @store.get(segment_key) if segment != nil && cacheable @cache.set(segment_key, segment) end return segment end nil end |
#set_flag(identifier, feature_config) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/ff/ruby/server/sdk/api/storage_repository.rb', line 102 def set_flag(identifier, feature_config) if is_flag_outdated(identifier, feature_config) @logger.debug "Flag " + identifier + " already exists" return end sort_flag_rules(feature_config) flag_key = format_flag_key(identifier) if @store != nil @store.set(flag_key, feature_config) @cache.delete(flag_key) @logger.debug "Flag " + identifier + " successfully stored and cache invalidated" else @cache.set(flag_key, feature_config) @logger.debug "Flag " + identifier + " successfully cached" end if @callback != nil unless @callback.kind_of?(RepositoryCallback) raise "The 'callback' parameter must be of '" + RepositoryCallback.to_s + "' data type" end @callback.on_flag_stored(identifier) end end |
#set_segment(identifier, segment) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/ff/ruby/server/sdk/api/storage_repository.rb', line 137 def set_segment(identifier, segment) if is_segment_outdated(identifier, segment) @logger.debug "Segment " + identifier + " already exists" return end sort_segment_serving_rules(segment) segment_key = format_segment_key(identifier) if @store != nil @store.set(segment_key, segment) @cache.delete(segment_key) @logger.debug "Segment " + identifier + " successfully stored and cache invalidated" else @cache.set(segment_key, segment) @logger.debug "Segment " + identifier + " successfully cached" end if @callback != nil unless @callback.kind_of?(RepositoryCallback) raise "The 'callback' parameter must be of '" + RepositoryCallback.to_s + "' data type" end @callback.on_segment_stored(identifier) end end |