Class: FFlags::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/fflags/api.rb

Overview

Api Class

Instance Method Summary collapse

Constructor Details

#initializeApi

Returns a new instance of Api.



4
5
6
# File 'lib/fflags/api.rb', line 4

def initialize
  load_flags
end

Instance Method Details

#enabled?(flag_name) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/fflags/api.rb', line 12

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

#flagsObject



8
9
10
# File 'lib/fflags/api.rb', line 8

def flags
  client.all(key)
end

#get_flag(flag_name) ⇒ Object



21
22
23
# File 'lib/fflags/api.rb', line 21

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

#load_flagsObject



34
35
36
37
38
39
# 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

#resetObject



29
30
31
32
# File 'lib/fflags/api.rb', line 29

def reset
  client.reset(key)
  load_flags
end

#set_flag(flag_name, bool) ⇒ Object



16
17
18
19
# 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) ⇒ Object



25
26
27
# File 'lib/fflags/api.rb', line 25

def toggle_flag(flag_name)
  set_flag(flag_name, !enabled?(flag_name))
end