lib/fflags/api.rb in fflags-0.1.1 vs lib/fflags/api.rb in fflags-0.3.0

- old
+ new

@@ -1,12 +1,14 @@ -require './lib/fflags/redis_client' - module FFlags # Api Class class Api + def initialize + load_flags + end + def flags - FFlags.configuration.flags + client.all(key) end def enabled?(flag_name) get_flag(flag_name) == true end @@ -14,33 +16,46 @@ def set_flag(flag_name, bool) client.set(key, flag_name, bool) end def get_flag(flag_name) - value = client.get(key, flag_name) - value = flags.dig(flag_name.to_sym) if value.nil? - truthy?(value) + truthy?(client.get(key, flag_name)) end def toggle_flag(flag_name) set_flag(flag_name, !get_flag(flag_name)) end def reset - client.reset(FFlags.configuration.key) + client.reset(key) + load_flags end + def load_flags + default_flags.each do |flag, bool| + set_flag(flag, bool) + end + end + private + def question_mark_method?(method_name) + method_name[-1] == '?' + end + def truthy?(value) value == true || value == 'true' end def key FFlags.configuration.key end def client RedisClient + end + + def default_flags + FFlags.configuration.flags end end end