Sha256: 8116074f9f62be3e4dd433e631eb25e5b97b5e6ca4638ae4138c3a4a6ca17c1a

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 KB

Contents

require 'redis'
require 'fflags/version'
require 'fflags/configuration'
require 'fflags/redis_client'
require 'fflags/api'

# FFlags module
module FFlags
  module_function

  def config
    yield configuration
    api.reset
  end

  def flags
    api.flags
  end

  def enabled?(flag_name)
    api.enabled?(flag_name)
  end

  def set(flag_name, bool)
    api.set_flag(flag_name, bool)
  end

  def get(flag_name)
    api.get_flag(flag_name)
  end

  def toggle(flag_name)
    api.toggle_flag(flag_name)
  end

  def reset
    api.reset
  end

  def method_missing(method_name, *args)
    flag_name = method_name[0..-2]

    if !method_name.to_s.end_with?('?') ||
       !flags.include?(flag_name)
      return super
    end

    api.enabled?(flag_name)
  end

  def respond_to_missing?(method_name, include_private = false)
    flag_name = method_name[0..-2]
    method_name.to_s.end_with?('?') && flags.include?(flag_name) || super
  end

  def api
    @api ||= Api.new
  end

  def configuration
    @configuration ||= Configuration.new
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fflags-0.3.4 lib/fflags.rb
fflags-0.3.3 lib/fflags.rb
fflags-0.3.2 lib/fflags.rb
fflags-0.3.1 lib/fflags.rb