simple_toggle 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/simple_toggle.rb +46 -4
- data/lib/simple_toggle/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c0fcd9bb34ba840541ae2ffd182a71b5e93591f
|
4
|
+
data.tar.gz: 62c0d69e57343f133edd62392d4518691e2c78b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 718feee2d61a37e296c4bcbc741e350f3a5cfda9009b5d3d2b06010587bbd454c0e117a84fda73ec9f14bb28dec1aa0a1d0dd669cb12bf92b711239ecb5f8f07
|
7
|
+
data.tar.gz: b8321cb29809d3d2b3ccde9904bb235e2feab33c366097a9e51a5815cb85353d084afea25b0b9ba219ab6a31d0ce7ce2ad9f255e94f2ae732e8f3c16073d7717
|
data/README.md
CHANGED
data/lib/simple_toggle.rb
CHANGED
@@ -1,21 +1,63 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'rails'
|
2
|
+
require 'simple_toggle/version'
|
3
3
|
require 'active_record'
|
4
4
|
|
5
5
|
module SimpleToggle
|
6
|
+
|
7
|
+
# SimpleToggle raises +SimpleToggleError+
|
8
|
+
class SimpleToggleError < StandardError; end
|
9
|
+
|
10
|
+
# SimpleToggle - A simple framework for feature toggles.
|
11
|
+
#
|
12
|
+
# SimpleToggle provides feature toggle function that allow a developer to enable or disable
|
13
|
+
# code in an environment without deploying code. This decouples the deployment of the code
|
14
|
+
# from the delivery of the feature.
|
15
|
+
#
|
16
|
+
# A toggle is a simple ActiveRecord model that can be created, modified, or destroyed
|
17
|
+
# like any other. The toggle will grant access to blocks of code if the given record
|
18
|
+
# exists and is active.
|
19
|
+
#
|
20
|
+
# ==== Create a toggle
|
21
|
+
#
|
22
|
+
# SimpleToggle::Toggle.create name: :active_feature, active: true
|
23
|
+
#
|
6
24
|
class Toggle < ActiveRecord::Base
|
7
25
|
self.table_name = 'simple_toggle_toggles'
|
8
26
|
|
27
|
+
# Execute the given block if the given +feature+ exists and #active? returns true.
|
28
|
+
#
|
29
|
+
# SimpleToggle::Toggle.when_active(:active_feature) { puts 'feature is active' }
|
30
|
+
# # feature is active
|
31
|
+
# # => nil
|
32
|
+
# SimpleToggle::Toggle.when_active(:inactive_feature) { puts 'feature is active' }
|
33
|
+
# # => nil
|
34
|
+
# SimpleToggle::Toggle.when_active(:missing_feature) { puts 'feature is active' }
|
35
|
+
# # => nil
|
36
|
+
#
|
9
37
|
def self.when_active(feature)
|
10
38
|
yield if Toggle.active?(feature)
|
11
39
|
end
|
12
40
|
|
41
|
+
# Raises an exception if +feature+ does not exist.
|
42
|
+
#
|
43
|
+
# SimpleToggle::Toggle.require(:missing_feature)
|
44
|
+
# # raises SimpleToggle::SimpleToggleError
|
13
45
|
def self.require(feature)
|
14
|
-
raise unless Toggle.active?(feature)
|
46
|
+
raise SimpleToggle::ToggleError.new('Feature does not exist') unless Toggle.active?(feature)
|
15
47
|
end
|
16
48
|
|
49
|
+
# Checks whether a given `feature` is active. To be considered active, a
|
50
|
+
# toggle must be both present and active.
|
51
|
+
#
|
52
|
+
#
|
53
|
+
# SimpleToggle::Toggle.active?(:active_feature)
|
54
|
+
# # => true
|
55
|
+
# SimpleToggle::Toggle.active?(:inactive_feature)
|
56
|
+
# # => false
|
57
|
+
# SimpleToggle::Toggle.active?(:missing_feature)
|
58
|
+
# # => false
|
17
59
|
def self.active?(feature)
|
18
|
-
|
60
|
+
!!Toggle.where(name: feature, active: true).first
|
19
61
|
end
|
20
62
|
end
|
21
63
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_toggle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trevor Oke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -113,11 +113,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
115
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.4.
|
116
|
+
rubygems_version: 2.4.5
|
117
117
|
signing_key:
|
118
118
|
specification_version: 4
|
119
119
|
summary: A simple ActivceRecord based feature toggle for ruby/rails.
|
120
120
|
test_files:
|
121
121
|
- spec/lib/simple_toggle_spec.rb
|
122
122
|
- spec/spec_helper.rb
|
123
|
-
has_rdoc:
|