simple_switch 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -1
- data/README.md +175 -58
- data/Rakefile +21 -1
- data/app/assets/javascripts/simple_switch/application.js +1 -0
- data/app/assets/stylesheets/simple_switch/application.css +4 -0
- data/app/controllers/simple_switch/application_controller.rb +4 -0
- data/app/helpers/simple_switch/application_helper.rb +4 -0
- data/app/models/simple_switch/environment.rb +8 -0
- data/app/models/simple_switch/feature.rb +8 -0
- data/app/models/simple_switch/state.rb +15 -0
- data/app/views/layouts/simple_switch/application.html.erb +14 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20151216180633_create_simple_switch_tables.simple_switch.rb +24 -0
- data/lib/generators/simple_switch/initialize_generator.rb +17 -0
- data/lib/generators/simple_switch/install_generator.rb +13 -3
- data/lib/generators/templates/feature_config_sample.yml +16 -12
- data/lib/generators/templates/migration.rb +24 -0
- data/lib/generators/templates/simple_switch.rb +9 -2
- data/lib/simple_switch.rb +10 -6
- data/lib/simple_switch/engine.rb +10 -0
- data/lib/simple_switch/feature_manager.rb +15 -0
- data/lib/simple_switch/feature_manager_db.rb +88 -0
- data/lib/simple_switch/feature_manager_yaml.rb +68 -0
- data/lib/simple_switch/manager_shared_methods.rb +52 -0
- data/lib/simple_switch/railtie.rb +12 -0
- data/lib/simple_switch/shared_controller_methods.rb +2 -2
- data/lib/simple_switch/version.rb +1 -1
- data/lib/tasks/simple_switch.rake +106 -0
- data/spec/config/feature_config.yml +10 -6
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +26 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/simple_switch.rb +17 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +44 -0
- data/spec/dummy/db/seeds.rb +17 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +54 -0
- data/spec/dummy/log/test.log +7280 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/simple_switch_environments.rb +5 -0
- data/spec/factories/simple_switch_features.rb +5 -0
- data/spec/factories/simple_switch_states.rb +5 -0
- data/spec/models/simple_switch/environment_spec.rb +11 -0
- data/spec/models/simple_switch/feature_spec.rb +11 -0
- data/spec/models/simple_switch/state_spec.rb +11 -0
- data/spec/route_helper.rb +5 -0
- data/spec/simple_switch_feature_managers_spec.rb +282 -0
- data/spec/spec_helper.rb +22 -27
- metadata +203 -17
- data/.gitignore +0 -3
- data/.rspec +0 -2
- data/.travis.yml +0 -7
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -22
- data/codeclimate.yml +0 -3
- data/lib/generators/simple_switch/install_yaml_generator.rb +0 -18
- data/lib/simple_switch/switch.rb +0 -77
- data/simple_switch.gemspec +0 -26
- data/spec/simple_switch_spec.rb +0 -91
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2015 Sen Zhang
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/codeclimate.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rails/generators/base'
|
2
|
-
|
3
|
-
module SimpleSwitch
|
4
|
-
module Generators
|
5
|
-
|
6
|
-
class InstallYamlGenerator < Rails::Generators::Base
|
7
|
-
source_root File.expand_path('../../templates', __FILE__)
|
8
|
-
|
9
|
-
desc 'Copy feature configuration sample file feature_config_sample.yml to your application.'
|
10
|
-
|
11
|
-
def copy_initializer
|
12
|
-
copy_file 'feature_config_sample.yml',
|
13
|
-
"#{SimpleSwitch::feature_config_file_dir}/#{SimpleSwitch::feature_config_file_name}"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
data/lib/simple_switch/switch.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
module SimpleSwitch
|
2
|
-
class Switch
|
3
|
-
def initialize
|
4
|
-
@feature_config = load_config
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.instance
|
8
|
-
return @@instance ||= send(:new)
|
9
|
-
end
|
10
|
-
|
11
|
-
private_class_method :new
|
12
|
-
|
13
|
-
def on?(feature, env=Rails.env)
|
14
|
-
@feature_config[feature][env] if valid_feature_name_for_env?(feature, env)
|
15
|
-
end
|
16
|
-
|
17
|
-
def off?(feature, env=Rails.env)
|
18
|
-
!on?(feature, env)
|
19
|
-
end
|
20
|
-
|
21
|
-
def update(feature, env, value)
|
22
|
-
@feature_config[feature][env] = value if valid_feature_name_for_env?(feature, env)
|
23
|
-
|
24
|
-
save_to_yaml
|
25
|
-
end
|
26
|
-
|
27
|
-
def delete(feature)
|
28
|
-
@feature_config.delete(feature) if valid_feature_name?(feature)
|
29
|
-
|
30
|
-
save_to_yaml
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def file_path
|
36
|
-
Rails.root.join(SimpleSwitch::feature_config_file_dir, SimpleSwitch::feature_config_file_name)
|
37
|
-
end
|
38
|
-
|
39
|
-
def load_config
|
40
|
-
HashWithIndifferentAccess.new(YAML::load(File.open(file_path)))
|
41
|
-
end
|
42
|
-
|
43
|
-
def reload_config!
|
44
|
-
@feature_config = load_config
|
45
|
-
end
|
46
|
-
|
47
|
-
def save_to_yaml
|
48
|
-
begin
|
49
|
-
File.open(file_path, 'w') do |f|
|
50
|
-
f.puts @feature_config.to_hash.to_yaml
|
51
|
-
end
|
52
|
-
|
53
|
-
true
|
54
|
-
rescue
|
55
|
-
false
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def valid_feature_name?(feature)
|
60
|
-
reload_config! unless @feature_config.has_key?(feature)
|
61
|
-
|
62
|
-
return true if @feature_config.has_key?(feature)
|
63
|
-
|
64
|
-
raise "Cannot find feature '#{feature}', check out your "\
|
65
|
-
"#{SimpleSwitch::feature_config_file_name} file."
|
66
|
-
end
|
67
|
-
|
68
|
-
def valid_feature_name_for_env?(feature, env=Rails.env)
|
69
|
-
valid_feature_name?(feature)
|
70
|
-
|
71
|
-
return true if @feature_config[feature].has_key?(env)
|
72
|
-
|
73
|
-
raise "Cannot find environment '#{env}' for feature '#{feature}', "\
|
74
|
-
"check out your #{SimpleSwitch::feature_config_file_name} file."
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
data/simple_switch.gemspec
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
lib = File.expand_path('../lib', __FILE__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
|
4
|
-
require 'simple_switch/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = 'simple_switch'
|
8
|
-
spec.version = SimpleSwitch::VERSION
|
9
|
-
spec.authors = ['Sen Zhang']
|
10
|
-
spec.email = ['solowolf21@gmail.com']
|
11
|
-
spec.summary = %q{Simple Feature Switch Engine}
|
12
|
-
spec.description = %q{Simple Feature Switch Engine}
|
13
|
-
spec.homepage = 'https://github.com/Sen-Zhang/simple_switch'
|
14
|
-
spec.license = 'MIT'
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ['lib']
|
20
|
-
spec.required_ruby_version = '>= 2.0.0'
|
21
|
-
|
22
|
-
spec.add_development_dependency 'bundler', '~> 1.10'
|
23
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
-
spec.add_development_dependency 'rails', '~> 4.2.0'
|
25
|
-
spec.add_development_dependency 'rspec', '~> 3.3.0'
|
26
|
-
end
|
data/spec/simple_switch_spec.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'SimpleSwitch' do
|
4
|
-
describe 'Switch' do
|
5
|
-
it 'on? works fine' do
|
6
|
-
allow(Rails).to receive(:env).and_return('development')
|
7
|
-
|
8
|
-
expect(SimpleSwitch.feature_manager.on?(:foo)).to be_truthy
|
9
|
-
expect(SimpleSwitch.feature_manager.on?(:bar)).to be_truthy
|
10
|
-
|
11
|
-
allow(Rails).to receive(:env).and_return('test')
|
12
|
-
|
13
|
-
expect(SimpleSwitch.feature_manager.on?(:foo)).to be_truthy
|
14
|
-
expect(SimpleSwitch.feature_manager.on?(:bar)).to be_falsey
|
15
|
-
|
16
|
-
allow(Rails).to receive(:env).and_return('production')
|
17
|
-
|
18
|
-
expect(SimpleSwitch.feature_manager.on?(:foo)).to be_falsey
|
19
|
-
expect(SimpleSwitch.feature_manager.on?(:bar)).to be_truthy
|
20
|
-
|
21
|
-
expect(SimpleSwitch.feature_manager.on?(:foo, :development)).to be_truthy
|
22
|
-
expect(SimpleSwitch.feature_manager.on?(:bar, :development)).to be_truthy
|
23
|
-
|
24
|
-
expect(SimpleSwitch.feature_manager.on?(:foo, :test)).to be_truthy
|
25
|
-
expect(SimpleSwitch.feature_manager.on?(:bar, :test)).to be_falsey
|
26
|
-
|
27
|
-
expect(SimpleSwitch.feature_manager.on?(:foo, :production)).to be_falsey
|
28
|
-
expect(SimpleSwitch.feature_manager.on?(:bar, :production)).to be_truthy
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'off? works fine' do
|
32
|
-
allow(Rails).to receive(:env).and_return('development')
|
33
|
-
|
34
|
-
expect(SimpleSwitch.feature_manager.off?(:foo)).to be_falsey
|
35
|
-
expect(SimpleSwitch.feature_manager.off?(:bar)).to be_falsey
|
36
|
-
|
37
|
-
allow(Rails).to receive(:env).and_return('test')
|
38
|
-
|
39
|
-
expect(SimpleSwitch.feature_manager.off?(:foo)).to be_falsey
|
40
|
-
expect(SimpleSwitch.feature_manager.off?(:bar)).to be_truthy
|
41
|
-
|
42
|
-
allow(Rails).to receive(:env).and_return('production')
|
43
|
-
|
44
|
-
expect(SimpleSwitch.feature_manager.off?(:foo)).to be_truthy
|
45
|
-
expect(SimpleSwitch.feature_manager.off?(:bar)).to be_falsey
|
46
|
-
|
47
|
-
expect(SimpleSwitch.feature_manager.off?(:foo, :development)).to be_falsey
|
48
|
-
expect(SimpleSwitch.feature_manager.off?(:bar, :development)).to be_falsey
|
49
|
-
|
50
|
-
expect(SimpleSwitch.feature_manager.off?(:foo, :test)).to be_falsey
|
51
|
-
expect(SimpleSwitch.feature_manager.off?(:bar, :test)).to be_truthy
|
52
|
-
|
53
|
-
expect(SimpleSwitch.feature_manager.off?(:foo, :production)).to be_truthy
|
54
|
-
expect(SimpleSwitch.feature_manager.off?(:bar, :production)).to be_falsey
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'update works fine' do
|
58
|
-
expect(SimpleSwitch.feature_manager.on?(:foo, :development)).to be_truthy
|
59
|
-
|
60
|
-
SimpleSwitch.feature_manager.update(:foo, :development, false)
|
61
|
-
|
62
|
-
expect(SimpleSwitch.feature_manager.off?(:foo, :development)).to be_truthy
|
63
|
-
|
64
|
-
expect(SimpleSwitch.feature_manager.off?(:bar, :test)).to be_truthy
|
65
|
-
|
66
|
-
SimpleSwitch.feature_manager.update(:bar, :test, true)
|
67
|
-
|
68
|
-
expect(SimpleSwitch.feature_manager.on?(:bar, :test)).to be_truthy
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'delete works fine' do
|
72
|
-
expect(SimpleSwitch.feature_manager.on?(:foo, :development)).to be_truthy
|
73
|
-
|
74
|
-
SimpleSwitch.feature_manager.delete(:foo)
|
75
|
-
|
76
|
-
expect {
|
77
|
-
SimpleSwitch.feature_manager.on?(:foo, :development)
|
78
|
-
}.to raise_error(RuntimeError, "Cannot find feature 'foo', check out your feature_config.yml file.")
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'raise errors correctly' do
|
82
|
-
expect {
|
83
|
-
SimpleSwitch.feature_manager.update(:foobar, :development, false)
|
84
|
-
}.to raise_error(RuntimeError, "Cannot find feature 'foobar', check out your feature_config.yml file.")
|
85
|
-
|
86
|
-
expect {
|
87
|
-
SimpleSwitch.feature_manager.update(:foo, :dev, false)
|
88
|
-
}.to raise_error(RuntimeError, "Cannot find environment 'dev' for feature 'foo', check out your feature_config.yml file.")
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|