dipswitch 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 94b8c0a76241b0407d627065ae164dc89e98c42a
4
+ data.tar.gz: 061dedd58084984535636ecc8e73de3f0b04d016
5
+ SHA512:
6
+ metadata.gz: ea541d75fd6938aeb325705a1ad1178e4a682ca5515c7583fc7cf0c547eaffe1322d95f62e68bebd1b586edc3c26ff89ee389d114947e9fd48c44fd5ef760053
7
+ data.tar.gz: 5ef8b338f35a2531dc5790ca5a92bcc6192d3295a3dc238d74b3ef3f209a87a61592ae1adb02fdefa59d303e006c131ba21a7b2ee00f207be55448ffea4247e3
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/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.5
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dipswitch.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Dipswitch
2
+
3
+ Super simple feature flag switcher.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dipswitch'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dipswitch
20
+
21
+ ## Usage
22
+
23
+ Configure Dipswitch before calling it. In a Rails app you might want to do this
24
+ in an initializer for example.
25
+
26
+ ```ruby
27
+ Dipswitch.configure do |config|
28
+ config.feature(:new_ui) do |user|
29
+ user.admin?
30
+ end
31
+
32
+ config.feature(:beta) do |user|
33
+ ['bella'].include?(user.username)
34
+ end
35
+
36
+ end
37
+ ```
38
+
39
+ In your application code ask Dipswitch if a feature is enabled:
40
+
41
+ ```ruby
42
+ Dipswitch.on?(:new_ui, current_user)
43
+ ```
44
+
45
+ That's it.
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rainkinz/dipswitch.
56
+
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 "dipswitch"
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/rspec ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rspec' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/dipswitch.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dipswitch/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dipswitch"
8
+ spec.version = Dipswitch::VERSION
9
+ spec.authors = ["rainkinz"]
10
+ spec.email = ["brendan.grainger@gmail.com"]
11
+
12
+ spec.summary = %q{Super simple feature flag toggler}
13
+ spec.description = %q{Super simple feature flag toggler}
14
+ spec.homepage = "http://github.com/rainkinz/dipswitch"
15
+
16
+ if spec.respond_to?(:metadata)
17
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
18
+ else
19
+ raise "RubyGems 2.0 or newer is required to protect against " \
20
+ "public gem pushes."
21
+ end
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(test|spec|features)/})
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "pry"
31
+ spec.add_development_dependency "bundler", "~> 1.13"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ end
@@ -0,0 +1,33 @@
1
+ module Dipswitch
2
+
3
+ def self.configure(&block)
4
+ yield configuration
5
+ # configuration.freeze
6
+ end
7
+
8
+ def self.configuration
9
+ @configuration ||= Configuration.new
10
+ end
11
+
12
+ def self.on?(name, *args)
13
+ # TODO: Not loving this so much. Maybe simplify
14
+ configuration.features.on?(name, *args)
15
+ end
16
+
17
+ class Configuration
18
+ attr_reader :features
19
+
20
+ def initialize
21
+ @features = Features.new
22
+ end
23
+
24
+ def feature(name, &block)
25
+ @features.add(name, &block)
26
+ end
27
+
28
+ def freeze
29
+ @features.freeze
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,25 @@
1
+ module Dipswitch
2
+ class Features
3
+ def initialize
4
+ @features = {}
5
+ end
6
+
7
+ def add(name, &block)
8
+ @features[name] ||= []
9
+ @features[name] << block
10
+ end
11
+
12
+ def on?(name, *args)
13
+ (@features[name.to_sym] || []).any? {|feature| feature.call(*args) }
14
+ end
15
+
16
+ def list
17
+ @features.keys
18
+ end
19
+
20
+ def freeze
21
+ @features.freeze
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,3 @@
1
+ module Dipswitch
2
+ VERSION = "0.1.0"
3
+ end
data/lib/dipswitch.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'dipswitch/version'
2
+ require 'dipswitch/configuration'
3
+ require 'dipswitch/features'
4
+
5
+ module Dipswitch
6
+
7
+ def configure(&block)
8
+ yield configuration
9
+ end
10
+
11
+ def configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+
15
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dipswitch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - rainkinz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Super simple feature flag toggler
70
+ email:
71
+ - brendan.grainger@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/rspec
84
+ - bin/setup
85
+ - dipswitch.gemspec
86
+ - lib/dipswitch.rb
87
+ - lib/dipswitch/configuration.rb
88
+ - lib/dipswitch/features.rb
89
+ - lib/dipswitch/version.rb
90
+ homepage: http://github.com/rainkinz/dipswitch
91
+ licenses: []
92
+ metadata:
93
+ allowed_push_host: https://rubygems.org
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.6.6
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Super simple feature flag toggler
114
+ test_files: []