experiment_light 0.1.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 +7 -0
- data/.gitignore +16 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +2 -0
- data/experiment_light.gemspec +23 -0
- data/lib/experiment_light/experiment.rb +37 -0
- data/lib/experiment_light/version.rb +3 -0
- data/lib/experiment_light.rb +5 -0
- data/lib/generators/experiment_light/install_generator.rb +15 -0
- data/lib/generators/templates/experiment_sample.yml +17 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a2a9dd106ddd9ad492edc39ae8cbdf46d5feec78
|
4
|
+
data.tar.gz: 339337336df9e307094cf0f1283f1f6a662a285d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1f9ab1e2562b9b6095f65cd76f67c23df965b7795360f46017bf688a7680e38337c1a7b359b6a7a8da91f117600cae3e08aa818185af423d8874fff67cc9c962
|
7
|
+
data.tar.gz: 1345ebff04f930025158e9f093104bb85ef86badddb027617e5bc92eee5e50189ebd615b959a6cd7592e110ecb3c76173fe911e154e3266327fe382d8b97a8dd
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
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/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Experiment::Light
|
2
|
+
|
3
|
+
Turn features on or off in various rails environments
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'experiment_light'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install experiment_light
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Run install generator:
|
24
|
+
|
25
|
+
$ rails generate experiment_light:install
|
26
|
+
|
27
|
+
A yaml file named `experiment.yml` will be added into `config/` after running install generator, now your can define your experimental features:
|
28
|
+
|
29
|
+
foo:
|
30
|
+
development: true
|
31
|
+
test: true
|
32
|
+
production: false
|
33
|
+
|
34
|
+
bar:
|
35
|
+
development: false
|
36
|
+
test: true
|
37
|
+
production: false
|
38
|
+
|
39
|
+
Now you can use it in your views like this:
|
40
|
+
|
41
|
+
<% if ExperimentLight::Experiment.on?(:foo) %>
|
42
|
+
<p>Experiment foo is on</p>
|
43
|
+
<% end %>
|
44
|
+
|
45
|
+
<% if ExperimentLight::Experiment.off?(:bar) %>
|
46
|
+
<p>Experiment bar is off</p>
|
47
|
+
<% end %>
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( https://github.com/[my-github-username]/experiment_light/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'experiment_light/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "experiment_light"
|
8
|
+
spec.version = ExperimentLight::VERSION
|
9
|
+
spec.authors = ["Sen-Zhang"]
|
10
|
+
spec.email = ["solowolf21@gmail.com"]
|
11
|
+
spec.summary = %q{Feature Toggles for Rails}
|
12
|
+
spec.description = %q{Turn features on or off in various rails environments}
|
13
|
+
spec.homepage = "https://github.com/Sen-Zhang/experiment_light.git"
|
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
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class ExperimentLight::Experiment
|
2
|
+
class << self
|
3
|
+
def on?(experiment_name)
|
4
|
+
experiment_feature_data
|
5
|
+
|
6
|
+
reload! unless @experiment_data.has_key?(experiment_name)
|
7
|
+
|
8
|
+
unless @experiment_data.has_key?(experiment_name)
|
9
|
+
raise "Cannot find experiment '#{experiment_name}', check out your experiment.yml file"
|
10
|
+
end
|
11
|
+
|
12
|
+
@experiment_data[experiment_name][Rails.env]
|
13
|
+
end
|
14
|
+
|
15
|
+
def off?(experiment_name)
|
16
|
+
!on?(experiment_name)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def default_experiment_file_name
|
21
|
+
'experiment.yml'
|
22
|
+
end
|
23
|
+
|
24
|
+
def load(file_name)
|
25
|
+
file_path = Rails.root.join('config', file_name)
|
26
|
+
HashWithIndifferentAccess.new(YAML::load(File.open(file_path)))
|
27
|
+
end
|
28
|
+
|
29
|
+
def reload!
|
30
|
+
@experiment_data = load(default_experiment_file_name)
|
31
|
+
end
|
32
|
+
|
33
|
+
def experiment_feature_data
|
34
|
+
@experiment_data ||= load(default_experiment_file_name)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module ExperimentLight
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('../../templates', __FILE__)
|
7
|
+
|
8
|
+
desc 'Copy experiment_sample.yml files to your application.'
|
9
|
+
|
10
|
+
def copy_initializer
|
11
|
+
template 'experiment_sample.yml', 'config/experiment.yml'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Example:
|
2
|
+
#
|
3
|
+
# experiment_feature_a:
|
4
|
+
# development: true
|
5
|
+
# test: true
|
6
|
+
# dev: true
|
7
|
+
# qa: true
|
8
|
+
# prodstage: true
|
9
|
+
# production: false
|
10
|
+
#
|
11
|
+
# experiment_feature_b:
|
12
|
+
# development: true
|
13
|
+
# test: true
|
14
|
+
# dev: true
|
15
|
+
# qa: true
|
16
|
+
# prodstage: true
|
17
|
+
# production: true
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: experiment_light
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sen-Zhang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Turn features on or off in various rails environments
|
42
|
+
email:
|
43
|
+
- solowolf21@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- experiment_light.gemspec
|
54
|
+
- lib/experiment_light.rb
|
55
|
+
- lib/experiment_light/experiment.rb
|
56
|
+
- lib/experiment_light/version.rb
|
57
|
+
- lib/generators/experiment_light/install_generator.rb
|
58
|
+
- lib/generators/templates/experiment_sample.yml
|
59
|
+
homepage: https://github.com/Sen-Zhang/experiment_light.git
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.4.4
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Feature Toggles for Rails
|
83
|
+
test_files: []
|