Sha256: c0ff6c3888d95303abdde699bb479a853ad37083365aa39561ceed5962e0e0c6

Contents?: true

Size: 971 Bytes

Versions: 3

Compression:

Stored size: 971 Bytes

Contents

module FFlags
  # Api Class
  class Api
    def initialize
      load_flags
    end

    def flags
      client.all(key)
    end

    def enabled?(flag_name)
      truthy?(get_flag(flag_name))
    end

    def set_flag(flag_name, bool)
      client.set(key, flag_name, bool)
    end

    def get_flag(flag_name)
      client.get(key, flag_name)
    end

    def toggle_flag(flag_name)
      set_flag(flag_name, !get_flag(flag_name))
    end

    def reset
      client.reset(key)
      load_flags
    end

    def flag_exist?(flag_name)
      !get_flag(flag_name).nil?
    end

    def load_flags
      default_flags.each do |flag, bool|
        next if flag_exist?(flag)
        set_flag(flag, bool)
      end
    end

    private

    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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fflags-0.4.0 lib/fflags/api.rb
fflags-0.3.5 lib/fflags/api.rb
fflags-0.3.4 lib/fflags/api.rb