feature_release 0.0.1
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.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +6 -0
- data/feature_release.gemspec +24 -0
- data/lib/feature_release.rb +32 -0
- data/lib/feature_release/feature.rb +22 -0
- data/lib/feature_release/version.rb +3 -0
- data/spec/feature_release_spec.rb +60 -0
- data/spec/feature_spec.rb +27 -0
- data/spec/spec_helper.rb +15 -0
- metadata +116 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Kavinder Dhaliwal
|
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,29 @@
|
|
1
|
+
# FeatureRelease
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'feature_release'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install feature_release
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/feature_release/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'feature_release/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "feature_release"
|
8
|
+
spec.version = FeatureRelease::VERSION
|
9
|
+
spec.authors = ["Kavinder Dhaliwal"]
|
10
|
+
spec.email = ["kavinderd@gmail.com"]
|
11
|
+
spec.summary = %q{Rollout features to some users (Rollout gem clone)}
|
12
|
+
spec.description = %q{Allows you to restrict access of portions of an app to certain users}
|
13
|
+
spec.homepage = ""
|
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.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "feature_release/version"
|
2
|
+
require "feature_release/feature"
|
3
|
+
|
4
|
+
class FeatureRelease
|
5
|
+
|
6
|
+
attr_reader :groups, :features
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@groups = {:all => lambda{|obj| true}}
|
10
|
+
@features = Hash.new do |hash, missing_key|
|
11
|
+
hash[missing_key] = Feature.new(missing_key)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def define_group(name, &block)
|
16
|
+
@groups[name] = block
|
17
|
+
end
|
18
|
+
|
19
|
+
def activate_feature(feature, group)
|
20
|
+
@features[feature.to_sym].add_group(group)
|
21
|
+
end
|
22
|
+
|
23
|
+
def deactivate_feature(feature, group)
|
24
|
+
@features[feature.to_sym].remove_group(group)
|
25
|
+
end
|
26
|
+
|
27
|
+
def active?(feature, user)
|
28
|
+
return false if @features[feature.to_sym].groups.empty?
|
29
|
+
@features[feature.to_sym].groups.all? {|group| groups[group].call(user)}
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class FeatureRelease
|
2
|
+
|
3
|
+
class Feature
|
4
|
+
|
5
|
+
attr_accessor :groups
|
6
|
+
|
7
|
+
def initialize(name)
|
8
|
+
@name = name
|
9
|
+
@groups = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_group(group)
|
13
|
+
@groups << group.to_sym
|
14
|
+
end
|
15
|
+
|
16
|
+
def remove_group(group)
|
17
|
+
@groups.delete(group.to_sym)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FeatureRelease do
|
4
|
+
|
5
|
+
context '#new' do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@fr = FeatureRelease.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "initializes with a default group proc" do
|
12
|
+
@fr.groups[:all].should be_kind_of(Proc)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "initializes with a features variable" do
|
16
|
+
@fr.features.should_not be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'groups' do
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
@fr = FeatureRelease.new
|
25
|
+
end
|
26
|
+
|
27
|
+
it "defines a group with a block" do
|
28
|
+
@fr.define_group(:testers) do |user|
|
29
|
+
user.new?
|
30
|
+
end
|
31
|
+
@fr.groups.should include(:testers)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'activate & deactivating features' do
|
37
|
+
let(:tester) {double("user", :new? => true)}
|
38
|
+
let(:non_tester) {double("user", :new? => false)}
|
39
|
+
|
40
|
+
before(:each) do
|
41
|
+
@fr = FeatureRelease.new
|
42
|
+
@fr.define_group(:testers) do |user|
|
43
|
+
user.new?
|
44
|
+
end
|
45
|
+
@fr.activate_feature(:test_feature, :testers)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "activates a feature for a defined group" do
|
49
|
+
@fr.active?(:test_feature, tester).should be_true
|
50
|
+
@fr.active?(:test_feature, non_tester).should be_false
|
51
|
+
end
|
52
|
+
|
53
|
+
it "deactivates a feature for a defined group" do
|
54
|
+
@fr.deactivate_feature(:test_feature, :testers)
|
55
|
+
@fr.active?(:test_feature, tester).should be_false
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FeatureRelease::Feature do
|
4
|
+
|
5
|
+
|
6
|
+
it "initializes with a name" do
|
7
|
+
expect{f = FeatureRelease::Feature.new(:test_feature)}.to_not raise_error
|
8
|
+
end
|
9
|
+
|
10
|
+
it "sets a default array to groups" do
|
11
|
+
f = FeatureRelease::Feature.new(:test_feature)
|
12
|
+
f.groups.should eq([])
|
13
|
+
end
|
14
|
+
|
15
|
+
it "allows groups to be added to @groups" do
|
16
|
+
f = FeatureRelease::Feature.new(:test_feature)
|
17
|
+
f.add_group(:testers)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "allows groups to be removed from @groups" do
|
21
|
+
f = FeatureRelease::Feature.new(:test_feature)
|
22
|
+
f.add_group(:testers)
|
23
|
+
f.remove_group(:testers)
|
24
|
+
f.groups.should_not include(:testers)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'feature_release.rb'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
7
|
+
config.run_all_when_everything_filtered = true
|
8
|
+
config.filter_run :focus
|
9
|
+
|
10
|
+
# Run specs in random order to surface order dependencies. If you find an
|
11
|
+
# order dependency and want to debug it, you can fix the order by providing
|
12
|
+
# the seed, which is printed after each run.
|
13
|
+
# --seed 1234
|
14
|
+
config.order = 'random'
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: feature_release
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kavinder Dhaliwal
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-05-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.5'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.5'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Allows you to restrict access of portions of an app to certain users
|
63
|
+
email:
|
64
|
+
- kavinderd@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- feature_release.gemspec
|
76
|
+
- lib/feature_release.rb
|
77
|
+
- lib/feature_release/feature.rb
|
78
|
+
- lib/feature_release/version.rb
|
79
|
+
- spec/feature_release_spec.rb
|
80
|
+
- spec/feature_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
homepage: ''
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
hash: 4375904973404869369
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
hash: 4375904973404869369
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 1.8.25
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: Rollout features to some users (Rollout gem clone)
|
113
|
+
test_files:
|
114
|
+
- spec/feature_release_spec.rb
|
115
|
+
- spec/feature_spec.rb
|
116
|
+
- spec/spec_helper.rb
|