fflags 0.1.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cbae7f0175cdbc90189ca18754c0421d6d460d3d
4
- data.tar.gz: d677ac1c00b62c82b93f6c1a4dbcac09a92f0e27
3
+ metadata.gz: 72f65fe5ec5b36c7fff0bc23ea874aa82063ee4a
4
+ data.tar.gz: 64d8caa37df5953669231a67b126668627b9a154
5
5
  SHA512:
6
- metadata.gz: 52e0ff6828daedabea699e34d0effb6a1ea71d63c7a5cffc44b37a273aba53c57b651bba594b5402bdf1bc7b426ac0dbd28ad19fa75249a753135d4c01a3b3ce
7
- data.tar.gz: 80c818a11296cec8a6ec35d2953c2f872795e8d11500b9cdee9ff083fe8c659aabd22d6b12337304262f07b583096b163fddf9e83b0d1b08d3120d52a4db2139
6
+ metadata.gz: 85de7e1a2994de1979f2c66273e01b251b3f5ff0427de0564147f003be17d72297cdf06a661f7967873405d6228d4437f26b736b4ee81547898686480f84943e
7
+ data.tar.gz: cf5404220fb29854eef0fb2c02f2f99748554121aa57aef406f6e342e2fc2bc9841a6219c9f03026da5e719f20edcb649b7e893b6995c334858d5394c8ba764e
data/Gemfile CHANGED
@@ -3,4 +3,5 @@ source 'https://rubygems.org'
3
3
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in FFlags.gemspec
6
+ gem 'pry'
6
7
  gemspec
data/Gemfile.lock CHANGED
@@ -1,18 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fflags (0.1.1)
4
+ fflags (0.3.0)
5
5
  redis (>= 3.0.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  ast (2.3.0)
11
+ coderay (1.1.2)
11
12
  diff-lcs (1.3)
13
+ method_source (0.9.0)
12
14
  parallel (1.12.1)
13
15
  parser (2.4.0.2)
14
16
  ast (~> 2.3)
15
17
  powerpack (0.1.1)
18
+ pry (0.11.3)
19
+ coderay (~> 1.1.0)
20
+ method_source (~> 0.9.0)
16
21
  rainbow (3.0.0)
17
22
  rake (10.5.0)
18
23
  redis (4.0.1)
@@ -45,6 +50,7 @@ PLATFORMS
45
50
  DEPENDENCIES
46
51
  bundler (~> 1.16)
47
52
  fflags!
53
+ pry
48
54
  rake (~> 10.0)
49
55
  rspec (~> 3.0)
50
56
  rubocop
@@ -1,3 +1,3 @@
1
1
  module FFlags
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
data/lib/fflags.rb CHANGED
@@ -1,5 +1,7 @@
1
+ require 'redis'
1
2
  require 'fflags/version'
2
3
  require 'fflags/configuration'
4
+ require 'fflags/redis_client'
3
5
  require 'fflags/api'
4
6
 
5
7
  # FFlags module
@@ -8,6 +10,7 @@ module FFlags
8
10
 
9
11
  def config
10
12
  yield configuration
13
+ api.reset
11
14
  end
12
15
 
13
16
  def flags
@@ -18,15 +21,15 @@ module FFlags
18
21
  api.enabled?(flag_name)
19
22
  end
20
23
 
21
- def set_flag(flag_name, bool)
24
+ def set(flag_name, bool)
22
25
  api.set_flag(flag_name, bool)
23
26
  end
24
27
 
25
- def get_flag(flag_name)
28
+ def get(flag_name)
26
29
  api.get_flag(flag_name)
27
30
  end
28
31
 
29
- def toggle_flag(flag_name)
32
+ def toggle(flag_name)
30
33
  api.toggle_flag(flag_name)
31
34
  end
32
35
 
@@ -34,6 +37,22 @@ module FFlags
34
37
  api.reset
35
38
  end
36
39
 
40
+ def method_missing(method_name, *args)
41
+ flag_name = method_name[0..-2]
42
+
43
+ if !method_name.to_s.end_with?('?') ||
44
+ !flags.include?(flag_name)
45
+ return super
46
+ end
47
+
48
+ api.get_flag(flag_name)
49
+ end
50
+
51
+ def respond_to_missing?(method_name, include_private = false)
52
+ flag_name = method_name[0..-2]
53
+ method_name.to_s.end_with?('?') && flags.include?(flag_name) || super
54
+ end
55
+
37
56
  def api
38
57
  @api ||= Api.new
39
58
  end
data/lib/fflags/api.rb CHANGED
@@ -1,10 +1,12 @@
1
- require './lib/fflags/redis_client'
2
-
3
1
  module FFlags
4
2
  # Api Class
5
3
  class Api
4
+ def initialize
5
+ load_flags
6
+ end
7
+
6
8
  def flags
7
- FFlags.configuration.flags
9
+ client.all(key)
8
10
  end
9
11
 
10
12
  def enabled?(flag_name)
@@ -16,9 +18,7 @@ module FFlags
16
18
  end
17
19
 
18
20
  def get_flag(flag_name)
19
- value = client.get(key, flag_name)
20
- value = flags.dig(flag_name.to_sym) if value.nil?
21
- truthy?(value)
21
+ truthy?(client.get(key, flag_name))
22
22
  end
23
23
 
24
24
  def toggle_flag(flag_name)
@@ -26,11 +26,22 @@ module FFlags
26
26
  end
27
27
 
28
28
  def reset
29
- client.reset(FFlags.configuration.key)
29
+ client.reset(key)
30
+ load_flags
31
+ end
32
+
33
+ def load_flags
34
+ default_flags.each do |flag, bool|
35
+ set_flag(flag, bool)
36
+ end
30
37
  end
31
38
 
32
39
  private
33
40
 
41
+ def question_mark_method?(method_name)
42
+ method_name[-1] == '?'
43
+ end
44
+
34
45
  def truthy?(value)
35
46
  value == true || value == 'true'
36
47
  end
@@ -42,5 +53,9 @@ module FFlags
42
53
  def client
43
54
  RedisClient
44
55
  end
56
+
57
+ def default_flags
58
+ FFlags.configuration.flags
59
+ end
45
60
  end
46
61
  end
@@ -1,5 +1,3 @@
1
- require 'redis'
2
-
3
1
  module FFlags
4
2
  # Redis Client
5
3
  class RedisClient
@@ -8,6 +6,10 @@ module FFlags
8
6
  client.hmset(key, field, value) == 'OK'
9
7
  end
10
8
 
9
+ def all(key)
10
+ client.hgetall(key)
11
+ end
12
+
11
13
  def get(key, field)
12
14
  client.hget(key, field)
13
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fflags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Faizal Zakaria