beta_feature 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
+ SHA256:
3
+ metadata.gz: 222c8c53af430f408ecfcd55d978ab59b4089af31302190912d0a596a5682bfa
4
+ data.tar.gz: c614987373dd1fd3844a883cb895941574da085d3a0afe83a9f95e1a02ef887e
5
+ SHA512:
6
+ metadata.gz: 116211b838c40f3cbb8d03bbf7ed4d78b2cdf97a3e68dec7f6bdb5623fbaea2fa580c6892009351c22aec65536dbf6322f95cfcf73a89ade22020b01ab932b35
7
+ data.tar.gz: ca31eba01302373a7a5625cda951d1176c917f4d1bc5ecabc1a0d3108cb3ec03224ba5b05cacb222b1a531e99851e014b356f8dd9d754023c471c3a67d882312
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
12
+ *.gem
13
+ *.swp
14
+ .bundle
15
+ .DS_Store
16
+ .rvmrc
17
+ /coverage
18
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubycop.yml ADDED
@@ -0,0 +1,24 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ TargetRubyVersion: 2.3
4
+ Exclude:
5
+ - vendor/bundle/**/*
6
+ - gemfiles/vendor/bundle/**/*
7
+
8
+ Bundler/OrderedGems:
9
+ Enabled: false
10
+
11
+ Gemspec/OrderedDependencies:
12
+ Enabled: false
13
+
14
+ Layout:
15
+ Enabled: false
16
+
17
+ Metrics:
18
+ Enabled: false
19
+
20
+ Naming:
21
+ Enabled: false
22
+
23
+ Style:
24
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,57 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ # - 2.3.7
5
+ # - 2.4.4
6
+ - 2.5.3
7
+ - 2.6.3
8
+ env:
9
+ - DB=POSTGRES
10
+ # - DB=MYSQL
11
+ addons:
12
+ postgresql: "9.4"
13
+ services:
14
+ - mysql
15
+ - postgresql
16
+ before_install:
17
+ - bundle install --jobs=3 --retry=3
18
+ # - mysql -e 'CREATE DATABASE beta_feature_test;'
19
+ # - psql -c 'create database beta_feature_test;' -U postgres
20
+ # https://github.com/travis-ci/travis-ci/issues/8978
21
+ # - "travis_retry gem update --system"
22
+ # # Rails 4.2 has a bundler 1.x requirement
23
+ # - if [ $BUNDLE_GEMFILE = $PWD/gemfiles/rails42.gemfile ]; then
24
+ # rvm @global do gem uninstall bundler -a -x;
25
+ # travis_retry gem install -v '< 2.0.0' bundler;
26
+ # else
27
+ # travis_retry gem install bundler;
28
+ # fi
29
+
30
+ gemfile:
31
+ - gemfiles/rails50.gemfile
32
+ - gemfiles/rails51.gemfile
33
+ - gemfiles/rails52.gemfile
34
+ - gemfiles/rails60.gemfile
35
+ matrix:
36
+ # include:
37
+ # - rvm: 2.6.3
38
+ # script: bundle exec rubocop --parallel
39
+ # env: DB=rubocop # make travis build display nicer
40
+ exclude:
41
+ # - rvm: 2.3.7
42
+ # gemfile: gemfiles/rails60.gemfile
43
+ # - rvm: 2.4.4
44
+ # gemfile: gemfiles/rails60.gemfile
45
+ - rvm: 2.6.3
46
+ gemfile: gemfiles/rails42.gemfile
47
+ - rvm: ruby-head
48
+ gemfile: gemfiles/rails42.gemfile
49
+ allow_failures:
50
+ - rvm: ruby-head
51
+ fast_finish: true
52
+ branches:
53
+ only:
54
+ - master
55
+
56
+ script:
57
+ - rake
data/Appraisals ADDED
@@ -0,0 +1,18 @@
1
+ # Include DB adapters matching the version requirements in
2
+ # rails/activerecord/lib/active_record/connection_adapters/*adapter.rb
3
+
4
+ appraise 'rails50' do
5
+ gem 'rails', '~> 5.0.0'
6
+ end
7
+
8
+ appraise 'rails51' do
9
+ gem 'rails', '~> 5.1.4'
10
+ end
11
+
12
+ appraise 'rails52' do
13
+ gem 'rails', '>= 5.2.0', '< 5.3'
14
+ end
15
+
16
+ appraise 'rails60' do
17
+ gem 'rails', '>= 6.0.0.rc1', '< 6.1'
18
+ end
data/CHANGELOG.md ADDED
File without changes
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at xiaorong.ruby@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
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 beta_feature.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Ryan Lv
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,188 @@
1
+ # beta_feature
2
+
3
+ [![Build Status](https://secure.travis-ci.org/helloworld1812/beta_feature.svg)](http://travis-ci.org/helloworld1812/beta_feature)
4
+
5
+ **beta_feature** is a database-based feature flag tool for Ruby on Rails, which allows you check in incomplete features without affecting users.
6
+
7
+
8
+ ## Supported ORMs
9
+
10
+ beta_feature is currently ActiveRecord only.
11
+
12
+ ## Supported Database
13
+
14
+ - PostgreSQL ✅
15
+ - MySQL ❌(Working in Progress)
16
+ - SQLite ❌(Working in Progress)
17
+
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'beta_feature'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install beta_feature
34
+
35
+
36
+ Then, from your Rails app directory, run the following command to complete the setup.
37
+
38
+
39
+ $ rails generate beta_feature:install
40
+ $ rake db:migrate
41
+
42
+ Then, add your feature sets in `config/beta_features.yml`
43
+
44
+ ```yml
45
+ dark_mode:
46
+ developer: 'ryan@corp.com'
47
+ qa: 'windy@corp.com'
48
+ status: 'in_progress'
49
+ description: 'Building dark mode for my website.'
50
+ ```
51
+
52
+
53
+ ## Usage
54
+
55
+ ### Example: User Level feature toggle
56
+
57
+ Simply call `flagger` on your `User` model:
58
+
59
+ ```ruby
60
+ class User < ActiveRecord::Base
61
+ flagger
62
+
63
+ end
64
+
65
+ ```
66
+
67
+ The instance of User will have the ability to toggle feature flags.
68
+
69
+
70
+ ```ruby
71
+ user = User.find(327199)
72
+
73
+ #enable the feature flag dark_mode for this user.
74
+ user.enable_beta!(:dark_mode)
75
+
76
+ #remove landing_page_ux_improvement from this user's feature flags.
77
+ user.remove_beta!(:landing_page_ux_improvement)
78
+
79
+ # check whether a feature is active for a particular user.
80
+ user.can_access_beta?(:dark_mode) # => true/false
81
+ ```
82
+
83
+
84
+ Controll the logic based on feature flag.
85
+
86
+ ```ruby
87
+
88
+ if current_user.can_access_beta?(:dark_mode)
89
+ render 'home', layout: 'dark'
90
+ else
91
+ render 'home'
92
+ end
93
+ ```
94
+
95
+
96
+ ## Example: Company Level feature toggle
97
+
98
+ For enterprise application, you might want to enable a beta feature for all the employees of specific company. You can do it in this way.
99
+
100
+ Simply call `flagger` on your `Company` model:
101
+
102
+ ```ruby
103
+ class Company < ActiveRecord::Base
104
+ flagger
105
+
106
+ end
107
+ ```
108
+
109
+ The instance of Company will have the ability to toggle feature in company level.
110
+
111
+ ```ruby
112
+ company = Company.find(2)
113
+
114
+ #enable the feature flag dark_mode for this company.
115
+ user.enable_beta!(:dark_mode)
116
+
117
+ #remove the feature flag landing_page_ux_improvement from this company's feature flags.
118
+ user.remove_beta!(:landing_page_ux_improvement)
119
+
120
+ # check whether a feature is active for this company.
121
+ user.can_access_beta?(:dark_mode) # => true/false
122
+ ```
123
+
124
+ Controll the logic based on feature flag.
125
+
126
+ ```ruby
127
+ if company.can_access_beta?(:landing_page_ux_improvement)
128
+ render 'landing_page_v2'
129
+ else
130
+ render 'landing_page'
131
+ end
132
+ ```
133
+
134
+ ## Granularity
135
+
136
+ User level and company level beta toggles could meet most applications. But if you have special requirements, you can enable feature toggle to any models by calling `flagger`.
137
+
138
+
139
+ ```ruby
140
+ class Group < ActiveRecord::Base
141
+ flagger
142
+
143
+ end
144
+
145
+ group = Group.find(397)
146
+
147
+ #enable the feature flag dark_mode for this group.
148
+ group.enable_beta!(:dark_mode)
149
+
150
+ #remove the feature flag landing_page_ux_improvement from this group's feature flags.
151
+ group.remove_beta!(:landing_page_ux_improvement)
152
+
153
+ # check whether a feature is active for this group.
154
+ group.can_access_beta?(:dark_mode) # => true/false
155
+ ```
156
+
157
+
158
+
159
+ ## Alternative
160
+
161
+ - [rollout](https://github.com/fetlife/rollout), a redis based feature flags.
162
+ - [flipper](https://github.com/jnunemaker/flipper)
163
+
164
+
165
+ ## Development
166
+
167
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
168
+
169
+ 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).
170
+
171
+ ## Contributing
172
+
173
+ Bug reports and pull requests are welcome on GitHub at https://github.com/helloworld1812/beta_feature. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
174
+
175
+ ## Brought to you by
176
+
177
+ | pic | @mention | area |
178
+ |:--|:--|:--|
179
+ | ![](https://avatars2.githubusercontent.com/u/1224077?s=64) | @xiaoronglv | most things. |
180
+
181
+
182
+ ## License
183
+
184
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
185
+
186
+ ## Code of Conduct
187
+
188
+ Everyone interacting in the BetaFeature project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/beta_feature/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require 'appraisal'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,52 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "beta_feature/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "beta_feature"
8
+ spec.version = BetaFeature::VERSION
9
+ spec.authors = ["Ryan Lv", "Windy Liu"]
10
+ spec.email = ["tech@workstream.is"]
11
+
12
+ spec.summary = %q{Rails feature toggle for trunk based development.}
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/helloworld1812/beta_feature"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/helloworld1812/beta_feature"
24
+ spec.metadata["changelog_uri"] = "https://github.com/helloworld1812/beta_feature/blob/master/CHANGELOG.md"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+ spec.required_ruby_version = '>= 2.3.0'
39
+
40
+ # spec.add_runtime_dependency 'activerecord', '>= 4.2', '< 6.1'
41
+ # spec.add_runtime_dependency 'activesupport', '>= 4.2', '< 6.1'
42
+ spec.add_runtime_dependency 'rails', '>= 4.2', '< 6.1'
43
+
44
+ spec.add_development_dependency 'appraisal'
45
+ spec.add_development_dependency "rspec", ">= 3.0"
46
+ spec.add_development_dependency 'rspec-rails', '>= 3.5'
47
+ spec.add_development_dependency 'pry'
48
+ spec.add_development_dependency "rake", ">= 12.3.3"
49
+ spec.add_development_dependency 'rubocop', '>= 0.54.0'
50
+ spec.add_development_dependency 'mysql2', '>= 0.3.20'
51
+ spec.add_development_dependency 'pg', '>= 0.18', '< 2.0'
52
+ end