mgsnova / feature Goto Github PK
View Code? Open in Web Editor NEWA feature toggle library written in ruby
License: MIT License
A feature toggle library written in ruby
License: MIT License
Howdy,
Given a feature.yml
file with the following snippet:
test:
features:
feature_name: false
Using Feature.run_with_activated
within a RSpec example like so:
it 'does something' do
Feature.run_with_activated(:feature_name) do
# The test, `feature_name` here is disabled. Expected it to be enabled even if `feature.yml` has it as `false` for the test environment.
Feature.active? 'feature_name' # false
end
end
does not actually run the code with feature_name
active.
Any ideas?
Add possibility to enable auto refresh of feature list. When enabled, before checking whether the feature is enabled or not, the list of features will be refreshed (e.g. from database, yamlconfig, ...).
Default should be current status, where you have to use refresh! explicitly.
An uninitialized constant ActiveRecord::Generators::Migration
error is raised when loading Rails 4 with the Feature gem.
The offending line appears to originate from lib/feature/generators/install_generator.rb#8
Hey @mgsnova, any chance you could push a new version of this to rubygems? Would love to get access to active_features
via a direct gem download.
Thanks!
In a Rails app, when I do an asset:precompile, my initializers are loaded. When I'm setting the RedisRepository, the lib/feature.rb
will call a refresh!
when set_repository
is called:
https://github.com/mgsnova/feature/blob/master/lib/feature.rb#L41
The problem here is that it will try to access Redis on initialization, but when we're doing asset:precompile, we don't have REDIS environment variables set.
I can work around this in our app doing something like this in my initializer:
begin
Redis.current.ping
Feature.set_repository(Feature::Repository::RedisRepository.new("feature_toggles"))
rescue Redis::CannotConnectError
STDERR.puts "WARN: Could not connect to redis. This is OK in asset:precompile, but not in the live environment"
end
But... I think the better solution would be to not do a forced refresh when the repository is set, but rather do it lazily when any of the Feature methods are called for the first time. Thoughts?
Currently there is no support to test Rails. CI also breaks when Rails is defined.
It would be very helpful in my application if I could get a list of all of the current features and their respective values for debugging purposes.
It looks like it might just be a matter of exposing @active_features
but was curious if there might be a reason to not do this?
Maybe something as simple as: Feature.active_features
that returns the hash of feature to value.
Will submit a pull request if this sounds reasonable. love this library.
On Rails 4, app/models/feature_toggle.rb
generated by rails g feature:install
result in NoMethodError for attr_accessible
.
Though you can avoid the error by adding protected_attributes
gem which make attr_accessible
available on Rails 4, IMO the generator should not add the attr_accessible :name, :active
line when unavailable.
Please see a build result of my fork with additional integration tests against Rails 3 and 4.
With RAILS_VERSION=4
, generated app/models/feature_toggle.rb
result in NoMethodError for attr_accessible
which is not provided in Rails 4 by default.
For more details about attr_accessible
support in Rails 4, please see protected_attributes gem.
๐ folks! is this a good or bad idea?
class MyClass
Feature.without(:feature_name) do
def my_method
# implementation A
end
end
Feature.with(:feature_name) do
def my_method
# implementation B
end
end
end
I thought about using the feature switcher inside the my_method
method, but there may be other methods that only pertain to one or the other implementation such as:
class MyClass
Feature.without(:feature_name) do
def my_method
# implementation A
helper_method
end
def helper_method
# some stuffs here. I only make sense in implementation A
end
end
Feature.with(:feature_name) do
def my_method
# implementation B
end
end
end
Thoughts? And thanks!
Hi, I just found your feature gem and it looks like exactly what I need! I would like to have a different config for each environment though, like this:
development:
features:
feature_foo: true
test:
features:
feature_foo: true
production:
features:
feature_foo: false
This way I could have feature_foo on for development and my tests, but default it false in case we forget to disable it on deploy. We could easily do this if YamlRepository.new() accepted a hash:
config_for_env = YAML.load_file("#{Rails.root}/config/feature.yml")[Rails.env]
repo = Feature::Repository::YamlRepository.new(config_for_env)
What do you think? The code in YamlRepository#read_and_parse_file_data()
should be able to refactor and support this easily, I'd be happy to send a pull request if this sounds like a good idea.
I have forked this gem
and included this line in my gemfile:
gem 'feature', :git => "https://github.com/<my-git-account>/feature.git"
if I run this command locally: bundle install --path vendor/bundle
, I get this error:
#!/bin/bash -eo pipefail
bundle install --path vendor/bundle
Fetching gem metadata from http://rubygems.org/..........
Fetching https://github.com/<my-git-account>/feature.git
[!] There was an error while loading `feature.gemspec`: cannot load such file -- rake/packagetask
Does it try to require a relative path? That's been removed in Ruby 1.9. Bundler cannot continue.
# from /home/circleci/ocm/vendor/bundle/ruby/2.3.0/bundler/gems/feature-15536c16af54/feature.gemspec:1
# -------------------------------------------
> require 'rubygems/package_task'
#
# -------------------------------------------
Exited with code 14
Hi there! We're currently enjoying this gem, and I was looking to contribute. I wanted to see if what I was thinking makes sense.
In our YAML files, most of our lines look like this: stripe: <%= ENV['STRIPE_ENABLED'] == "true" %>
. I was wondering if there would be any interest/objection in having an EnvRepository that uses environment variables as the source of feature flagging. If so, I'll create a PR with that functionality.
Thanks for your contributions!
Hi,
Thanks for sharing this great gem :)
FYI, I'm getting the error next_migration_number': NotImplementedError
whenever I run rails g feature:install
.
Does it work for anyone?
Here is the log when ran on Rails 3.
$ bundle exec rails g feature:install
Faraday::Builder is now Faraday::RackBuilder.
identical config/initializers/feature.rb
identical app/models/feature_toggle.rb
PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/railties-3.2.17/lib/rails/generators/migration.rb:30:in `next_migration_number': NotImplementedError (NotImplementedError)
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/railties-3.2.17/lib/rails/generators/migration.rb:49:in `migration_template'
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/feature-1.0.0/lib/feature/generators/install_generator.rb:16:in `create_model_file'
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/railties-3.2.17/lib/rails/generators.rb:171:in `invoke'
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/railties-3.2.17/lib/rails/commands/generate.rb:12:in `<top (required)>'
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `block in require'
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:236:in `load_dependency'
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
from PATH_TO_MY_PROJECT/vendor/bundle/ruby/2.1.0/gems/railties-3.2.17/lib/rails/commands.rb:29:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Hi,
I'm getting the error with ActiveRecord, I don't use ActiveRecord in my application.
Is there any way to disable ActiveRecord in features gem?
Failure/Error: Unable to find matching line from backtrace
ActiveRecord::ConnectionNotEstablished:
ActiveRecord::ConnectionNotEstablished
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.