togls 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
+ SHA1:
3
+ metadata.gz: 29cf1b0568aea63a9f302b01727e2b03e2f6b022
4
+ data.tar.gz: 7b109336122ffd30f15621b8b769d3ad0556bd34
5
+ SHA512:
6
+ metadata.gz: 76ed9cf6f4d3b726902a8332fb16b57a1f4355cd3004cf0eca1f73228a9e4c304a89c967ebf157ebe5b3cc5003809223ed5dfd2577eb78dbc9197d4567bd7f05
7
+ data.tar.gz: 466bb270590c5a5000340ce3585da8f51195ae9016f79b1200d09dcc2f2f620a3809ac4168b1f1b9b51f1dff6ca6f5911b15e4a3e4fd5303d0e35742db4357c9
data/.codeclimate.yml ADDED
@@ -0,0 +1,2 @@
1
+ languages:
2
+ Ruby: true
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/ChangeLog.md ADDED
@@ -0,0 +1,14 @@
1
+ # ChangeLog
2
+
3
+ The following are lists of the notable changes included with each release.
4
+ This is intended to help keep people informed about notable changes between
5
+ versions, as well as provide a rough history.
6
+
7
+ #### Next Release
8
+
9
+ #### v0.1.0
10
+
11
+ * Add concept of Groups as a provided rule
12
+ * Add concept of Rules and Custom Rules, allowing users to have more dynamic
13
+ feature toggles
14
+ * Add basic feature toggles able to be switched on/off
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in togl.gemspec
4
+ gemspec
5
+
6
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Brian Miller
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,96 @@
1
+ [![Build Status](https://travis-ci.org/codebreakdown/togls.svg?branch=master)](https://travis-ci.org/codebreakdown/togls)
2
+ [![Code Climate](https://img.shields.io/codeclimate/github/codebreakdown/togls.svg)](https://codeclimate.com/github/codebreakdown/togls)
3
+ [![Code
4
+ Coverage](https://img.shields.io/codeclimate/coverage/github/codebreakdown/togls.svg)](https://codeclimate.com/github/codebreakdown/togls)
5
+ [![Dependency Status](https://gemnasium.com/codebreakdown/togls.svg)](https://gemnasium.com/codebreakdown/togls)
6
+
7
+ # Togls
8
+
9
+ A lightweight feature toggle library.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'togls'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install togls
26
+
27
+ ## Usage
28
+
29
+ ### Setup
30
+
31
+ The default behaviour for any feature that has not been defined that is accessed is to default to false.
32
+
33
+ ```ruby
34
+ Togls.features do
35
+ # Set this feature to always be on
36
+ feature(:pop_up_login_form).on
37
+ # Set this feature to always be off
38
+ feature(:send_follup_email).off
39
+ # Create a group rule
40
+ rule = Togls::Rules::Group.new(["user@email.com"])
41
+ feature(:new_contact_form).on(rule)
42
+ end
43
+ ```
44
+
45
+ ### Evaluate
46
+
47
+ ```ruby
48
+ if Togls.feature(:new_contact_form).on?("user@email.com")
49
+ # Do my awesome feature
50
+ end
51
+ ```
52
+
53
+ ### Custom Rules
54
+
55
+ A simple rule can be defined by created a rule object and passing a block
56
+
57
+ ```ruby
58
+ # Only allow users with email addresses at gmail.com
59
+ gmail_rule = Togls::Rule.new { |target| target =~ /gmail.com$/ }
60
+
61
+ Togls.features do
62
+ feature(:only_gmail_users).on(gmail_rule)
63
+ end
64
+ ```
65
+
66
+ To implement a more complex rule a new rule object can be defined under Togls::Rules that implements the run method and returns a boolean. When a feature is defined, the rule will be added to the feature object and the run method called with whatever target is passed.
67
+
68
+ ```ruby
69
+ module Togls
70
+ module Rules
71
+ class Group < Rule
72
+ def initialize(list)
73
+ @list = list
74
+ end
75
+
76
+ def run(target)
77
+ @list.include?(target)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ ```
83
+
84
+ ## Development
85
+
86
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
87
+
88
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
89
+
90
+ ## Contributing
91
+
92
+ 1. Fork it ( https://github.com/codebreakdown/togls/fork )
93
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
94
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
95
+ 4. Push to the branch (`git push origin my-new-feature`)
96
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "togls"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ module Togls
2
+ class Feature
3
+ attr_reader :key
4
+
5
+ def initialize(key)
6
+ @key = key
7
+ off
8
+ end
9
+
10
+ def on(rule = nil)
11
+ if rule.nil?
12
+ rule = Rule.new { true }
13
+ end
14
+ @rule = rule
15
+ end
16
+
17
+ def off
18
+ @rule = Rule.new { false }
19
+ end
20
+
21
+ def on?(target = nil)
22
+ @rule.run(target)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module Togls
2
+ class FeatureRegistry
3
+ def initialize
4
+ @registry = {}
5
+ @default_feature = Feature.new(:default).tap {|f| f.on(Rule.new { false }) }
6
+ end
7
+
8
+ def self.create(&features)
9
+ registry = self.new
10
+ registry.instance_eval(&features)
11
+ registry
12
+ end
13
+
14
+ def feature(tag)
15
+ @registry[tag.to_sym] = Feature.new(tag.to_sym)
16
+ end
17
+
18
+ def get(key)
19
+ @registry.fetch(key) do |key|
20
+ Togls.logger.warn("Feature identified by #{key} has not been defined")
21
+ @default_feature
22
+ end
23
+ end
24
+ end
25
+ end
data/lib/togls/rule.rb ADDED
@@ -0,0 +1,11 @@
1
+ module Togls
2
+ class Rule
3
+ def initialize(&rule)
4
+ @definition = rule
5
+ end
6
+
7
+ def run(target = nil)
8
+ @definition.call(target)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Togls
2
+ module Rules
3
+ class Group < Rule
4
+ def initialize(list)
5
+ @list = list
6
+ end
7
+
8
+ def run(target)
9
+ @list.include?(target)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ require 'togls/rules/group'
2
+
3
+ module Togls
4
+ module Rules
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Togls
2
+ VERSION = "0.1.0"
3
+ end
data/lib/togls.rb ADDED
@@ -0,0 +1,20 @@
1
+ require "togls/version"
2
+ require "togls/feature_registry"
3
+ require "togls/feature"
4
+ require "togls/rule"
5
+ require "togls/rules"
6
+ require "logger"
7
+
8
+ module Togls
9
+ def self.features(&features)
10
+ @feature_registry = FeatureRegistry.create(&features)
11
+ end
12
+
13
+ def self.feature(key)
14
+ @feature_registry.get(key)
15
+ end
16
+
17
+ def self.logger
18
+ @logger ||= Logger.new(STDOUT)
19
+ end
20
+ end
data/togls.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'togls/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "togls"
8
+ spec.version = Togls::VERSION
9
+ spec.authors = ["Brian Miller", "Andrew DePonte"]
10
+ spec.email = ["brimil01@gmail.com", "cyphactor@gmail.com"]
11
+
12
+ spec.summary = %q{An ultra light weight yet ridiculously powerful ruby feature toggle gem.}
13
+ spec.description = %q{An ultra light weight yet ridiculously powerful ruby feature toggle gem that supports the concept of release toggles and business toggles.}
14
+ spec.homepage = "http://github.com/codebreakdown/togls"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.2"
25
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: togls
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Miller
8
+ - Andrew DePonte
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-05-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.8'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.8'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.2'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.2'
56
+ description: An ultra light weight yet ridiculously powerful ruby feature toggle gem
57
+ that supports the concept of release toggles and business toggles.
58
+ email:
59
+ - brimil01@gmail.com
60
+ - cyphactor@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".codeclimate.yml"
66
+ - ".gitignore"
67
+ - ".rspec"
68
+ - ".ruby-version"
69
+ - ".travis.yml"
70
+ - CODE_OF_CONDUCT.md
71
+ - ChangeLog.md
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - bin/console
77
+ - bin/setup
78
+ - lib/togls.rb
79
+ - lib/togls/feature.rb
80
+ - lib/togls/feature_registry.rb
81
+ - lib/togls/rule.rb
82
+ - lib/togls/rules.rb
83
+ - lib/togls/rules/group.rb
84
+ - lib/togls/version.rb
85
+ - togls.gemspec
86
+ homepage: http://github.com/codebreakdown/togls
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.5
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: An ultra light weight yet ridiculously powerful ruby feature toggle gem.
110
+ test_files: []