class FFlags::Api
Api
Class
Public Class Methods
new()
click to toggle source
# File lib/fflags/api.rb, line 4 def initialize load_flags end
Public Instance Methods
enabled?(flag_name)
click to toggle source
# File lib/fflags/api.rb, line 12 def enabled?(flag_name) truthy?(get_flag(flag_name)) end
flags()
click to toggle source
# File lib/fflags/api.rb, line 8 def flags client.all(key) end
get_flag(flag_name)
click to toggle source
# File lib/fflags/api.rb, line 21 def get_flag(flag_name) client.get(key, flag_name) end
load_flags()
click to toggle source
# File lib/fflags/api.rb, line 34 def load_flags default_flags.each do |flag, bool| next if flag_is_not_nil?(flag) set_flag(flag, bool) end end
reset()
click to toggle source
# File lib/fflags/api.rb, line 29 def reset client.reset(key) load_flags end
set_flag(flag_name, bool)
click to toggle source
# File lib/fflags/api.rb, line 16 def set_flag(flag_name, bool) supported_flag?(flag_name) && client.set(key, flag_name, bool) end
toggle_flag(flag_name)
click to toggle source
# File lib/fflags/api.rb, line 25 def toggle_flag(flag_name) set_flag(flag_name, !enabled?(flag_name)) end
Private Instance Methods
client()
click to toggle source
# File lib/fflags/api.rb, line 60 def client RedisClient end
default_flags()
click to toggle source
# File lib/fflags/api.rb, line 64 def default_flags FFlags.configuration.flags end
flag_is_not_nil?(flag_name)
click to toggle source
# File lib/fflags/api.rb, line 48 def flag_is_not_nil?(flag_name) !get_flag(flag_name).nil? end
key()
click to toggle source
# File lib/fflags/api.rb, line 56 def key FFlags.configuration.key end
supported_flag?(flag_name)
click to toggle source
# File lib/fflags/api.rb, line 43 def supported_flag?(flag_name) default_flags.include?(flag_name.to_sym) || default_flags.include?(flag_name.to_s) end
truthy?(value)
click to toggle source
# File lib/fflags/api.rb, line 52 def truthy?(value) value == true || value == 'true' end