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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4f76487f261fb67eeddd262b27b04e5597f7008
4
- data.tar.gz: 57389c4ae6e41d977c88d0279f2c5f1388ce12ec
3
+ metadata.gz: 8c0fcd9bb34ba840541ae2ffd182a71b5e93591f
4
+ data.tar.gz: 62c0d69e57343f133edd62392d4518691e2c78b6
5
5
  SHA512:
6
- metadata.gz: 4d7051867b0471a28ee30157c3f907e58629dc45b65c1a7625829aaf0dac64b2adc1320078f748fe579677f3a25b2949a6703ce1909252df3dc53f0032c366f6
7
- data.tar.gz: 0479f06b0375ac5f2b78958c72e4175cb1e9d0f35e50cab912998f63d6d123a2758eb574425a10231440a53c56ae3ab86d4d481388991975ca695313cd366eb0
6
+ metadata.gz: 718feee2d61a37e296c4bcbc741e350f3a5cfda9009b5d3d2b06010587bbd454c0e117a84fda73ec9f14bb28dec1aa0a1d0dd669cb12bf92b711239ecb5f8f07
7
+ data.tar.gz: b8321cb29809d3d2b3ccde9904bb235e2feab33c366097a9e51a5815cb85353d084afea25b0b9ba219ab6a31d0ce7ce2ad9f255e94f2ae732e8f3c16073d7717
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- # FeatureFlag
2
-
1
+ # SimpleToggle
2
+
3
3
  TODO: Write a gem description
4
4
 
5
5
  ## Installation
@@ -1,21 +1,63 @@
1
- require "rails"
2
- require "simple_toggle/version"
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
- toggle = Toggle.where(name: feature, active: true).first
60
+ !!Toggle.where(name: feature, active: true).first
19
61
  end
20
62
  end
21
63
 
@@ -1,3 +1,3 @@
1
1
  module SimpleToggle
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
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.2
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-01-10 00:00:00.000000000 Z
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.2
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: