Module: FFlags

Defined in:
lib/fflags.rb,
lib/fflags/api.rb,
lib/FFlags/version.rb,
lib/fflags/redis_client.rb,
lib/fflags/configuration.rb

Overview

FFlags module

Defined Under Namespace

Classes: Api, Configuration, RedisClient

Constant Summary collapse

VERSION =
'0.3.0'.freeze

Class Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object (private)



40
41
42
43
44
45
46
47
48
49
# File 'lib/fflags.rb', line 40

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

Class Method Details

.apiObject



56
57
58
# File 'lib/fflags.rb', line 56

def api
  @api ||= Api.new
end

.config {|configuration| ... } ⇒ Object

Yields:



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

def config
  yield configuration
  api.reset
end

.configurationObject



60
61
62
# File 'lib/fflags.rb', line 60

def configuration
  @configuration ||= Configuration.new
end

.enabled?(flag_name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.flagsObject



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

def flags
  api.flags
end

.get(flag_name) ⇒ Object



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

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

.method_missing(method_name, *args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/fflags.rb', line 40

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

.resetObject



36
37
38
# File 'lib/fflags.rb', line 36

def reset
  api.reset
end

.respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
# File 'lib/fflags.rb', line 51

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

.set(flag_name, bool) ⇒ Object



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

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

.toggle(flag_name) ⇒ Object



32
33
34
# File 'lib/fflags.rb', line 32

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