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)
  get_flag(flag_name) == true
end

#flagsObject



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

def flags
  client.all(key)
end

#get_flag(flag_name) ⇒ Object



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

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

#load_flagsObject



33
34
35
36
37
# File 'lib/fflags/api.rb', line 33

def load_flags
  default_flags.each do |flag, bool|
    set_flag(flag, bool)
  end
end

#resetObject



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

def reset
  client.reset(key)
  load_flags
end

#set_flag(flag_name, bool) ⇒ Object



16
17
18
# File 'lib/fflags/api.rb', line 16

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

#toggle_flag(flag_name) ⇒ Object



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

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