dipswitch 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/dipswitch.gemspec +1 -0
- data/lib/dipswitch/configuration.rb +11 -2
- data/lib/dipswitch/feature.rb +30 -0
- data/lib/dipswitch/features.rb +32 -6
- data/lib/dipswitch/version.rb +1 -1
- data/lib/dipswitch.rb +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3649d4f78f5379fa6eaaf54d583e980ca97e0b89
|
4
|
+
data.tar.gz: 51e3fa1d064d0eb6c4221529433c0ae32b3a620c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10812d0e7e04594306904e57e7ec802e90290782edb63654c405b57baf4f5fc05393a9544d9a5f3c27ca0f1f65cdeac0443f7bb26913ff008fe16ae0b6a8df9c
|
7
|
+
data.tar.gz: ff3b2bc6d9bf41f93c0aa7c1158f49dacd782c465edf0787b83cd773d89bdcd88d2c66292f10b95b09a0410569f5192ea9a9f9085904ae7fb3967eb55876bc69
|
data/README.md
CHANGED
data/dipswitch.gemspec
CHANGED
@@ -14,6 +14,14 @@ module Dipswitch
|
|
14
14
|
configuration.features.on?(name, *args)
|
15
15
|
end
|
16
16
|
|
17
|
+
def self.with(name, *args, &block)
|
18
|
+
configuration.features.with(name, *args, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.clear!
|
22
|
+
configuration.clear!
|
23
|
+
end
|
24
|
+
|
17
25
|
class Configuration
|
18
26
|
attr_reader :features
|
19
27
|
|
@@ -25,9 +33,10 @@ module Dipswitch
|
|
25
33
|
@features.add(name, &block)
|
26
34
|
end
|
27
35
|
|
28
|
-
def
|
29
|
-
@features.
|
36
|
+
def clear!
|
37
|
+
@features.clear!
|
30
38
|
end
|
39
|
+
|
31
40
|
end
|
32
41
|
|
33
42
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Dipswitch
|
2
|
+
|
3
|
+
class Feature
|
4
|
+
attr_reader :name, :gate
|
5
|
+
|
6
|
+
def initialize(name, gate = nil, &block)
|
7
|
+
@name = name
|
8
|
+
|
9
|
+
if block_given?
|
10
|
+
@gate = block
|
11
|
+
else
|
12
|
+
@gate = gate
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def on?(*args)
|
17
|
+
@gate.call(*args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def ==(o)
|
21
|
+
o.class == self.class && o.name == name && o.gate == gate
|
22
|
+
end
|
23
|
+
alias_method :eql?, :==
|
24
|
+
|
25
|
+
def hash
|
26
|
+
"#{name}_#{gate.hash}".hash
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/lib/dipswitch/features.rb
CHANGED
@@ -1,25 +1,51 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
1
3
|
module Dipswitch
|
4
|
+
|
5
|
+
# A Collection of +Feature+s with some helper methods to make the overall
|
6
|
+
# determination of a feature with multiple gates is enabled or not
|
2
7
|
class Features
|
8
|
+
include Enumerable
|
9
|
+
|
3
10
|
def initialize
|
4
11
|
@features = {}
|
5
12
|
end
|
6
13
|
|
14
|
+
def clear!
|
15
|
+
@features = {}
|
16
|
+
end
|
17
|
+
|
7
18
|
def add(name, &block)
|
8
19
|
@features[name] ||= []
|
9
|
-
@features[name] << block
|
20
|
+
@features[name] << Feature.new(name, block)
|
10
21
|
end
|
11
22
|
|
12
23
|
def on?(name, *args)
|
13
|
-
(@features[name.to_sym]
|
24
|
+
Array(@features[name.to_sym]).any? {|feature| feature.on?(*args) }
|
14
25
|
end
|
15
26
|
|
16
|
-
def
|
17
|
-
|
27
|
+
def with(name, *args, &block)
|
28
|
+
block.call if on?(name, *args)
|
18
29
|
end
|
19
30
|
|
20
|
-
def
|
21
|
-
|
31
|
+
def for(*args)
|
32
|
+
to_a.reduce({}) do |acc, feature|
|
33
|
+
acc[feature.name] = true if feature.on?(*args)
|
34
|
+
acc
|
35
|
+
end
|
22
36
|
end
|
37
|
+
|
38
|
+
|
39
|
+
def to_a
|
40
|
+
@features.values.flatten
|
41
|
+
end
|
42
|
+
|
43
|
+
def each
|
44
|
+
to_a.each do |f|
|
45
|
+
yield f
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
23
49
|
end
|
24
50
|
|
25
51
|
end
|
data/lib/dipswitch/version.rb
CHANGED
data/lib/dipswitch.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dipswitch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rainkinz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: opal
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Super simple feature flag toggler
|
70
84
|
email:
|
71
85
|
- brendan.grainger@gmail.com
|
@@ -85,6 +99,7 @@ files:
|
|
85
99
|
- dipswitch.gemspec
|
86
100
|
- lib/dipswitch.rb
|
87
101
|
- lib/dipswitch/configuration.rb
|
102
|
+
- lib/dipswitch/feature.rb
|
88
103
|
- lib/dipswitch/features.rb
|
89
104
|
- lib/dipswitch/version.rb
|
90
105
|
homepage: http://github.com/rainkinz/dipswitch
|