module FFlags
FFlags
module
Constants
- VERSION
Public Instance Methods
all()
click to toggle source
Returns all supported flags.
Ex.
FFlags.all
# File lib/fflags.rb, line 36 def all api.flags end
api()
click to toggle source
# File lib/fflags.rb, line 136 def api @api ||= Api.new end
config() { |configuration| ... }
click to toggle source
Sets FFlags
configuration using a block that will be invoked on initialization.
Ex.
FFlags.config do |config| config.flags = { flag_1: true, flag_2: false } end
# File lib/fflags.rb, line 18 def config yield configuration api.load_flags end
configuration()
click to toggle source
# File lib/fflags.rb, line 140 def configuration @configuration ||= Configuration.new end
enabled?(flag_name)
click to toggle source
Check if the flag is enabled, it returns true | false.
Ex.
FFlags.enabled?(:new_flag)
# File lib/fflags.rb, line 71 def enabled?(flag_name) api.enabled?(flag_name) end
get(flag_name)
click to toggle source
Gets value (as String) of a given flag.
Ex.
FFlags.get(:new_flag)
# File lib/fflags.rb, line 99 def get(flag_name) api.get_flag(flag_name) end
method_missing(method_name, *args)
click to toggle source
NOTE: This method will be deprecated soon.
Calls superclass method
# File lib/fflags.rb, line 123 def method_missing(method_name, *args) flag_name = method_name[0..-2] return super if !method_name.to_s.end_with?('?') api.enabled?(flag_name) end
reset()
click to toggle source
Reset all the flags to the default value. The default values are as defined in the config under flags attribute.
Ex.
FFlags.reset
# File lib/fflags.rb, line 118 def reset api.reset end
reset_config()
click to toggle source
Reset the whole config to the default values
Ex.
FFlags.reset_config
# File lib/fflags.rb, line 27 def reset_config @configuration = nil reset end
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
# File lib/fflags.rb, line 131 def respond_to_missing?(method_name, include_private = false) flag_name = method_name[0..-2] method_name.to_s.end_with?('?') && all.include?(flag_name) || super end
set(flag_name, bool) { || ... }
click to toggle source
Sets flag.
Ex.
FFlags.set(:new_flag, true) (Not thread safe) FFlags.set(:new_flag, true) do puts 'hello' end
# File lib/fflags.rb, line 84 def set(flag_name, bool) if block_given? prev_flag = get(flag_name) api.set_flag(flag_name, bool) yield api.set_flag(flag_name, prev_flag) else api.set_flag(flag_name, bool) end end
set_as_template(template)
click to toggle source
Sets as given template. It will returns false if the template doesn't exists
Ex.
FFlags.set_as_template(:template_name)
# File lib/fflags.rb, line 53 def set_as_template(template) template = templates[template.to_sym] || templates[template.to_s] return false unless template status = true template.each_pair do |key, value| status &&= set(key, value) end status end
templates()
click to toggle source
Returns all templates.
Ex.
FFlags.templates
# File lib/fflags.rb, line 44 def templates configuration.templates end
toggle(flag_name)
click to toggle source
Toggle the given flag. If its true, then the flag would be set to false. If its false, then the flag would be set to true.
Ex.
FFlags.toggle(:new_flag)
# File lib/fflags.rb, line 109 def toggle(flag_name) api.toggle_flag(flag_name) end