fflags 0.4.0 → 0.4.1

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: 80793af98a867433e83929b5672b2132aa8cba78
4
- data.tar.gz: 01e50393546f7e80b9cd90485e47d2ce7669e835
3
+ metadata.gz: dcb8c6e2437f6545882deca349f45e3c5dec4869
4
+ data.tar.gz: f1b3341891da9c719adb9252c7cce0ca1d940d82
5
5
  SHA512:
6
- metadata.gz: fdfe4e7d1103bf7b83bd0539e5f430638d18c81b8b4182e3b269cd739f76f70bdd3c07e2d15aebd7e8633993bfc5d3c925ccb276adb451e81be8b31eb38e3f71
7
- data.tar.gz: f7b628615e600a2a6852fdb8eb6c133593671ccc292c02a4d5cc268fb3a6c0b79599803864b0a6b9cba605f753030b29ca87a031709aa5601b91fab3f55d7913
6
+ metadata.gz: 334336c321d12e3c21b7043e3a4843982c0aa7ea8ebc4e86744c71fdfdfc389fadadf0c14515f8a7acf578cca60424dcb0d6f0a4784cd094d80116c960bfaee2
7
+ data.tar.gz: 99f4018c40ea65fdb3fcd26f33099327bae8dbfa09a0f532b8f21e98ae31e73229559a8bd0b963849345156f20ad5845643658fea0ff73bb5fabdd6b79c78951
@@ -26,6 +26,12 @@ jobs:
26
26
  # fallback to using the latest cache if no exact match is found
27
27
  - v1-dependencies-
28
28
 
29
+ # Code Climate test reporter
30
+ - run:
31
+ name: install codeclimate test reporter
32
+ command: |
33
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
34
+ chmod +x ./cc-test-reporter
29
35
 
30
36
  - run:
31
37
  name: install redis
@@ -61,11 +67,12 @@ jobs:
61
67
  command: |
62
68
  mkdir /tmp/test-results
63
69
  TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
64
-
70
+ ./cc-test-reporter before-build
65
71
  bundle exec rspec --format progress \
66
72
  --out /tmp/test-results/rspec.xml \
67
73
  --format progress \
68
74
  "${TEST_FILES}"
75
+ ./cc-test-reporter after-build --exit-code $?
69
76
 
70
77
  # collect reports
71
78
  - store_test_results:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fflags (0.4.0)
4
+ fflags (0.4.1)
5
5
  redis (>= 3.0.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  [![CircleCI](https://circleci.com/gh/faizalzakaria/fflags/tree/master.svg?style=svg)](https://circleci.com/gh/faizalzakaria/fflags/tree/master)
2
2
  [![Maintainability](https://api.codeclimate.com/v1/badges/2c8af5d2a0560570a5b7/maintainability)](https://codeclimate.com/github/faizalzakaria/fflags/maintainability)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/2c8af5d2a0560570a5b7/test_coverage)](https://codeclimate.com/github/faizalzakaria/fflags/test_coverage)
3
4
 
4
5
  # FFlags
5
6
 
@@ -8,31 +8,78 @@ require 'fflags/api'
8
8
  module FFlags
9
9
  module_function
10
10
 
11
+ # Sets FFlags configuration using a block that
12
+ # will be invoked on initialization.
13
+ #
14
+ # Ex.
15
+ # FFlags.config do |config|
16
+ # config.flags = { flag_1: true, flag_2: false }
17
+ # end
11
18
  def config
12
19
  yield configuration
13
20
  api.load_flags
14
21
  end
15
22
 
23
+ # Returns all supported flags.
24
+ #
25
+ # Ex.
26
+ # FFlags.all
16
27
  def all
17
28
  api.flags
18
29
  end
19
30
 
31
+ # Check if the flag is enabled,
32
+ # it returns true | false.
33
+ #
34
+ # Ex.
35
+ # FFlags.enabled?(:new_flag)
20
36
  def enabled?(flag_name)
21
37
  api.enabled?(flag_name)
22
38
  end
23
39
 
40
+ # Sets flag.
41
+ #
42
+ # Ex.
43
+ # FFlags.set(:new_flag, true)
44
+ #
45
+ # (Not thread safe)
46
+ # FFlags.set(:new_flag, true) do
47
+ # puts 'hello'
48
+ # end
24
49
  def set(flag_name, bool)
25
- api.set_flag(flag_name, bool)
50
+ if block_given?
51
+ prev_flag = get(flag_name)
52
+ api.set_flag(flag_name, bool)
53
+ yield
54
+ api.set_flag(flag_name, prev_flag)
55
+ else
56
+ api.set_flag(flag_name, bool)
57
+ end
26
58
  end
27
59
 
60
+ # Gets value (as String) of a given flag.
61
+ #
62
+ # Ex.
63
+ # FFlags.get(:new_flag)
28
64
  def get(flag_name)
29
65
  api.get_flag(flag_name)
30
66
  end
31
67
 
68
+ # Toggle the given flag.
69
+ # If its true, then the flag would be set to false.
70
+ # If its false, then the flag would be set to true.
71
+ #
72
+ # Ex.
73
+ # FFlags.toggle(:new_flag)
32
74
  def toggle(flag_name)
33
75
  api.toggle_flag(flag_name)
34
76
  end
35
77
 
78
+ # Reset all the flags to the default value.
79
+ # The default values are as defined in the config under flags attribute.
80
+ #
81
+ # Ex.
82
+ # FFlags.reset
36
83
  def reset
37
84
  api.reset
38
85
  end
@@ -14,7 +14,8 @@ module FFlags
14
14
  end
15
15
 
16
16
  def set_flag(flag_name, bool)
17
- client.set(key, flag_name, bool)
17
+ supported_flag?(flag_name) &&
18
+ client.set(key, flag_name, bool)
18
19
  end
19
20
 
20
21
  def get_flag(flag_name)
@@ -30,19 +31,24 @@ module FFlags
30
31
  load_flags
31
32
  end
32
33
 
33
- def flag_exist?(flag_name)
34
- !get_flag(flag_name).nil?
35
- end
36
-
37
34
  def load_flags
38
35
  default_flags.each do |flag, bool|
39
- next if flag_exist?(flag)
36
+ next if flag_is_not_nil?(flag)
40
37
  set_flag(flag, bool)
41
38
  end
42
39
  end
43
40
 
44
41
  private
45
42
 
43
+ def supported_flag?(flag_name)
44
+ default_flags.include?(flag_name.to_sym) ||
45
+ default_flags.include?(flag_name.to_s)
46
+ end
47
+
48
+ def flag_is_not_nil?(flag_name)
49
+ !get_flag(flag_name).nil?
50
+ end
51
+
46
52
  def truthy?(value)
47
53
  value == true || value == 'true'
48
54
  end
@@ -1,3 +1,3 @@
1
1
  module FFlags
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.4.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fflags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Faizal Zakaria
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-28 00:00:00.000000000 Z
11
+ date: 2017-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis