fflags 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 761ad83c7a15d759b09cee085312dbaffcb4d36a
4
+ data.tar.gz: 4b06c0f98e93e2376258790e106384d28d21e3c9
5
+ SHA512:
6
+ metadata.gz: a24e7f9cabe15f525c5bb48b50729805b591dadd6074b8ce94e21ef01fcd8cc48a97f37a96780aa347285f5b141ea5be30afd230da61a354daef2b735e1c38b0
7
+ data.tar.gz: '082425d96b4c805f7df4350768ab786506c4bd0a6cc1f5d175b0f3b2b1b4f044543cfbf30f6fd799d8f95ea705784de3a5bb613e05672c46f332bc3225b20241'
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ Metrics/ModuleLength:
2
+ Exclude:
3
+ - "**/*_spec.rb"
4
+
5
+ Metrics/BlockLength:
6
+ Exclude:
7
+ - "**/*_spec.rb"
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in FFlags.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fflags (0.1.0)
5
+ redis (~> 3.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.3.0)
11
+ diff-lcs (1.3)
12
+ parallel (1.12.1)
13
+ parser (2.4.0.2)
14
+ ast (~> 2.3)
15
+ powerpack (0.1.1)
16
+ rainbow (3.0.0)
17
+ rake (10.5.0)
18
+ redis (3.0.7)
19
+ rspec (3.7.0)
20
+ rspec-core (~> 3.7.0)
21
+ rspec-expectations (~> 3.7.0)
22
+ rspec-mocks (~> 3.7.0)
23
+ rspec-core (3.7.0)
24
+ rspec-support (~> 3.7.0)
25
+ rspec-expectations (3.7.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.7.0)
28
+ rspec-mocks (3.7.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-support (3.7.0)
32
+ rubocop (0.52.0)
33
+ parallel (~> 1.10)
34
+ parser (>= 2.4.0.2, < 3.0)
35
+ powerpack (~> 0.1)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (~> 1.0, >= 1.0.1)
39
+ ruby-progressbar (1.9.0)
40
+ unicode-display_width (1.3.0)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ bundler (~> 1.16)
47
+ fflags!
48
+ rake (~> 10.0)
49
+ rspec (~> 3.0)
50
+ rubocop
51
+
52
+ BUNDLED WITH
53
+ 1.16.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Faizal Zakaria
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # FFlags
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'fflags'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fflags
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require 'socket'
23
+
24
+ FFlags.config do |config|
25
+ config.key = Socket.gethostname
26
+ config.flags = { new_view: true }
27
+ end
28
+ ```
29
+
30
+ Then in the code,
31
+
32
+ ```ruby
33
+ # Verify if the flag is enabled
34
+ FFlags.enabled?(:new_view)
35
+
36
+ # Overwrite flag
37
+ FFlags.toggle(:new_view)
38
+ # or
39
+ FFlags.set_flag(:new_view, false)
40
+
41
+ # To reset, and get back to the default settings.
42
+ FFlags.reset
43
+ ```
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rspec` to run the tests.
48
+
49
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/faizalzakaria/fflags.
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/fflags.gemspec ADDED
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fflags/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'fflags'
8
+ spec.version = FFlags::VERSION
9
+ spec.authors = ['Faizal Zakaria']
10
+ spec.email = ['fai@code3.io']
11
+
12
+ spec.summary = 'Feature flags that can be override per instance'
13
+ spec.description = 'Feature flags that can be override per instance'
14
+ spec.homepage = 'https://faizalzakaria.github.com'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_runtime_dependency 'redis', '~> 3.0.0'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.16'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ spec.add_development_dependency 'rubocop'
30
+ end
@@ -0,0 +1,3 @@
1
+ module FFlags
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/lib/fflags.rb ADDED
@@ -0,0 +1,44 @@
1
+ require 'fflags/version'
2
+ require 'fflags/configuration'
3
+ require 'fflags/api'
4
+
5
+ # FFlags module
6
+ module FFlags
7
+ module_function
8
+
9
+ def config
10
+ yield configuration
11
+ end
12
+
13
+ def flags
14
+ api.flags
15
+ end
16
+
17
+ def enabled?(flag_name)
18
+ api.enabled?(flag_name)
19
+ end
20
+
21
+ def set_flag(flag_name, bool)
22
+ api.set_flag(flag_name, bool)
23
+ end
24
+
25
+ def get_flag(flag_name)
26
+ api.get_flag(flag_name)
27
+ end
28
+
29
+ def toggle_flag(flag_name)
30
+ api.toggle_flag(flag_name)
31
+ end
32
+
33
+ def reset
34
+ api.reset
35
+ end
36
+
37
+ def api
38
+ @api ||= Api.new
39
+ end
40
+
41
+ def configuration
42
+ @configuration ||= Configuration.new
43
+ end
44
+ end
data/lib/fflags/api.rb ADDED
@@ -0,0 +1,46 @@
1
+ require './lib/fflags/redis_client'
2
+
3
+ module FFlags
4
+ # Api Class
5
+ class Api
6
+ def flags
7
+ FFlags.configuration.flags
8
+ end
9
+
10
+ def enabled?(flag_name)
11
+ get_flag(flag_name) == true
12
+ end
13
+
14
+ def set_flag(flag_name, bool)
15
+ client.set(key, flag_name, bool)
16
+ end
17
+
18
+ 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)
22
+ end
23
+
24
+ def toggle_flag(flag_name)
25
+ set_flag(flag_name, !get_flag(flag_name))
26
+ end
27
+
28
+ def reset
29
+ client.reset(FFlags.configuration.key)
30
+ end
31
+
32
+ private
33
+
34
+ def truthy?(value)
35
+ value == true || value == 'true'
36
+ end
37
+
38
+ def key
39
+ FFlags.configuration.key
40
+ end
41
+
42
+ def client
43
+ RedisClient
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,19 @@
1
+ module FFlags
2
+ # Configuration Class
3
+ class Configuration
4
+ attr_accessor :key, :redis_url, :debug, :flags
5
+
6
+ def initialize
7
+ set_default_values
8
+ end
9
+
10
+ private
11
+
12
+ def set_default_values
13
+ @key = 'code3.io'
14
+ @redis_url = 'redis://127.0.0.1:6379'
15
+ @debug = false
16
+ @flags = {}
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ require 'redis'
2
+
3
+ module FFlags
4
+ # Redis Client
5
+ class RedisClient
6
+ class << self
7
+ def set(key, field, value)
8
+ client.hmset(key, field, value) == 'OK'
9
+ end
10
+
11
+ def get(key, field)
12
+ client.hget(key, field)
13
+ end
14
+
15
+ def reset(key)
16
+ client.del(key)
17
+ end
18
+
19
+ private
20
+
21
+ def client
22
+ @client ||= Redis.new(url: FFlags.configuration.redis_url)
23
+ end
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fflags
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Faizal Zakaria
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redis
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Feature flags that can be override per instance
84
+ email:
85
+ - fai@code3.io
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - fflags.gemspec
100
+ - lib/FFlags/version.rb
101
+ - lib/fflags.rb
102
+ - lib/fflags/api.rb
103
+ - lib/fflags/configuration.rb
104
+ - lib/fflags/redis_client.rb
105
+ homepage: https://faizalzakaria.github.com
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.6.11
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Feature flags that can be override per instance
129
+ test_files: []