flip-flop 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 527196b717129538ce2edf0ab15e95afd641ef35
4
- data.tar.gz: e264c2af251f924114c26dc433f4a62c7093a2d0
3
+ metadata.gz: 876ae4f24582ebe07ddc6635c925eacd44bfd4de
4
+ data.tar.gz: 1009ffb11e5896c310896fde803211ec6f63fea5
5
5
  SHA512:
6
- metadata.gz: 3c3c0b6f202b99d9f16e9643f4aff91e6c2a20cb5e25e82a2a09f6ff8e4beeeb845cd79dc092c907e4fc14c2e1868a176a6e41b2cbec139ca2c49b79eea90c51
7
- data.tar.gz: 0634f5b6c9079721004902381cd1510ff80e056a9205a767976f32b94d5e5f513a11315a112bf917d01db9d6fdc6a745f11603cb2a13a50ec0a7ce3bc9610cc1
6
+ metadata.gz: f2d7d4bbac7019588892afb82c06ce1bbaabc2b0548f32c347c59668682e27e1717ca72b6d2ef2069614fe6ffd7f5eb6675a2b938620deef4e808c239116a1de
7
+ data.tar.gz: f4a91ff2fa037b1e824f94f4b4f17b63171d700a0973a006997a288a12d18294e716b05413f596672197034e551b770faf99b22a89c0485a20a07bc56fc9793d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- flip-flop (0.0.1)
4
+ flip-flop (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  FlipFlop
2
2
  ========
3
3
 
4
+ [![Build Status](https://travis-ci.org/bkulyk/flip-flop.svg?branch=master)](https://travis-ci.org/bkulyk/flip-flop)
5
+ [![Code Climate](https://codeclimate.com/github/bkulyk/flip-flop/badges/gpa.svg)](https://codeclimate.com/github/bkulyk/flip-flop)
6
+
4
7
  Provide an easy mechanism for turning features on or off, either with dates or just
5
8
  a boolean value.
6
9
 
@@ -99,6 +102,9 @@ Gates
99
102
  * `after_date` — enable a feature after the date has passed
100
103
  * `until_date` — enable a feature until the date has passed
101
104
  * `date_range` — enable a feature for the duration of the date range
105
+ * `after_time` — enable a feature after a time has passed
106
+ * `until_time` — enable a feature until a time has passed
107
+ * `time_range` — enable a feature for the duration of a time range
102
108
  * `percentage_of_time` — enable a feature for a given percentage of checks
103
109
 
104
110
  Adapters
data/flip-flop.gemspec CHANGED
@@ -1,11 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require File.expand_path('../lib/flip-flop/version', __FILE__)
3
3
 
4
- plugin_files = []
5
- plugin_test_files = []
6
-
7
- ignored_files = plugin_files
8
- ignored_files << ".gitignore"
4
+ ignored_files = []
5
+ ignored_files << '.gitignore'
6
+ ignored_files << '.travis.yml'
9
7
  ignored_files.uniq!
10
8
 
11
9
  Gem::Specification.new do |gem|
@@ -1,4 +1,4 @@
1
- require 'date'
1
+ require 'yaml'
2
2
 
3
3
  module FlipFlop
4
4
  module Adapters
@@ -7,7 +7,7 @@ module FlipFlop
7
7
  end
8
8
 
9
9
  def date_range(value)
10
- value.include? Date.today
10
+ value.begin < Date.today && value.end > Date.today
11
11
  end
12
12
 
13
13
  def until_date(value)
@@ -18,6 +18,18 @@ module FlipFlop
18
18
  Date.today > value
19
19
  end
20
20
 
21
+ def time_range(value)
22
+ value.begin < Time.now.utc && value.end > Time.now.utc
23
+ end
24
+
25
+ def until_time(value)
26
+ Time.now < value
27
+ end
28
+
29
+ def after_time(value)
30
+ Time.now > value
31
+ end
32
+
21
33
  def percentage_of_time(value)
22
34
  rand < (value / 100.0)
23
35
  end
@@ -1,3 +1,3 @@
1
1
  module FlipFlop
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -7,12 +7,12 @@ module FlipFlop
7
7
  # >> FlipFlop::get_instance.feature_enabled? :some_feature
8
8
  #
9
9
  # Arguments:
10
- # configuration block: (:symbol)
10
+ # feature_name (String/Symbol)
11
11
  #
12
12
  # Returns:
13
13
  # boolean
14
14
  def feature_enabled?(feature_name)
15
- ::FlipFlop::get_instance.feature_enabled? feature_name.to_sym
15
+ ::FlipFlop::feature_enabled? feature_name
16
16
  end
17
17
  end
18
18
  end
data/lib/flip-flop.rb CHANGED
@@ -23,6 +23,17 @@ module FlipFlop
23
23
  def self.configure(&block)
24
24
  get_instance.configure(&block)
25
25
  end
26
+
27
+ # Check if a feature is enabled or not
28
+ #
29
+ # Example:
30
+ # >> puts "hello" if FlipFlop::feature_enabled? :say_hello
31
+ #
32
+ # Arguments:
33
+ # feature_name (String/Symbol)
34
+ def self.feature_enabled?(feature_name)
35
+ get_instance.feature_enabled? feature_name.to_sym
36
+ end
26
37
 
27
38
  class FlipFlop
28
39
  attr_reader :config
@@ -47,12 +58,12 @@ module FlipFlop
47
58
  # >> FlipFlop::get_instance.feature_enabled? :some_feature
48
59
  #
49
60
  # Arguments:
50
- # configuration block: (:symbol)
61
+ # feature_name (Symbol)
51
62
  #
52
63
  # Returns:
53
64
  # boolean
54
- def feature_enabled?(name)
55
- public_send feature_type(name), feature_value(name)
65
+ def feature_enabled?(feature_name)
66
+ public_send feature_type(feature_name), feature_value(feature_name)
56
67
  rescue
57
68
  false
58
69
  end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'flip-flop/adapters/yaml'
3
+
4
+ describe FlipFlop do
5
+ context 'yaml' do
6
+
7
+ before :each do
8
+ FlipFlop::configure do |config|
9
+ config[:adapter] = FlipFlop::Adapters::YAML
10
+ config[:yaml_path] = 'spec/test-config.yml'
11
+ end
12
+ end
13
+
14
+ it 'should load from yaml file' do
15
+ expect(FlipFlop::feature_enabled? :on).to be_truthy
16
+ expect(FlipFlop::feature_enabled? :off).to be_falsey
17
+ end
18
+
19
+ end
20
+ end
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
  require 'flip-flop/view_helpers'
3
3
 
4
+ ONE_DAY = 86400
5
+
4
6
  class DummyController
5
7
  include FlipFlop::ViewHelpers
6
8
  end
@@ -67,6 +69,47 @@ describe DummyController do
67
69
  expect(subject.feature_enabled? :ranged).to be_falsey
68
70
  end
69
71
  end
72
+
73
+ context 'until time gate' do
74
+ it 'should return true if the feature has been set to expire in the future' do
75
+ ::FlipFlop::get_instance.set_feature(:something, :until_time, Time.now.utc + 60)
76
+ expect(subject.feature_enabled? :something).to be_truthy
77
+ end
78
+
79
+ it 'should return false if the feature has been set to expire in the past' do
80
+ FlipFlop::get_instance.set_feature(:something, :until_time, Time.now.utc - 60)
81
+ expect(subject.feature_enabled? :something).to be_falsey
82
+ end
83
+ end
84
+
85
+ context 'after time gate' do
86
+ it 'should return true if the feature has been set to expire after a time in the past' do
87
+ FlipFlop::get_instance.set_feature(:blah, :after_time, Time.now.utc - 10)
88
+ expect(subject.feature_enabled? :blah).to be_truthy
89
+ end
90
+
91
+ it 'should return false if the feature has been set to enable after a time in the future' do
92
+ FlipFlop::get_instance.set_feature(:blah, :after_time, Time.now.utc + 10)
93
+ expect(subject.feature_enabled? :blah).to be_falsey
94
+ end
95
+ end
96
+
97
+ context 'time range gate' do
98
+ it 'feature should be enabled if current date is in the time range' do
99
+ FlipFlop::get_instance.set_feature(:ranged, :time_range, (Time.now.utc - ONE_DAY)..(Time.now.utc + ONE_DAY))
100
+ expect(subject.feature_enabled? :ranged).to be_truthy
101
+ end
102
+
103
+ it 'feature should be disabled if range not started yet' do
104
+ ::FlipFlop::get_instance.set_feature(:ranged, :date_range, (Time.now.utc + 60)..(Time.now.utc + ONE_DAY))
105
+ expect(subject.feature_enabled? :ranged).to be_falsey
106
+ end
107
+
108
+ it 'feature should be disabled if range is past' do
109
+ ::FlipFlop::get_instance.set_feature(:ranged, :date_range, (Time.now.utc - ONE_DAY)..(Time.now.utc - 60))
110
+ expect(subject.feature_enabled? :ranged).to be_falsey
111
+ end
112
+ end
70
113
  end
71
114
 
72
115
  end
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,5 @@ Bundler.setup(:default)
11
11
  require 'flip-flop'
12
12
 
13
13
  RSpec.configure do |config|
14
- FlipFlop.configure do
15
- end
14
+ FlipFlop.configure {}
16
15
  end
@@ -0,0 +1,7 @@
1
+ ---
2
+ :on:
3
+ :type: :boolean
4
+ :value: true
5
+ :off:
6
+ :type: :boolean
7
+ :value: false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flip-flop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Kulyk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-21 00:00:00.000000000 Z
11
+ date: 2016-04-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Enable or disable features easily
14
14
  email:
@@ -29,8 +29,10 @@ files:
29
29
  - lib/flip-flop/railtie.rb
30
30
  - lib/flip-flop/version.rb
31
31
  - lib/flip-flop/view_helpers.rb
32
+ - spec/lib/adapters/yaml_spec.rb
32
33
  - spec/lib/view_helpers_spec.rb
33
34
  - spec/spec_helper.rb
35
+ - spec/test-config.yml
34
36
  homepage: https://github.com/bkulyk/flip-flop
35
37
  licenses:
36
38
  - MIT
@@ -56,5 +58,7 @@ signing_key:
56
58
  specification_version: 4
57
59
  summary: Feature flipper
58
60
  test_files:
61
+ - spec/lib/adapters/yaml_spec.rb
59
62
  - spec/lib/view_helpers_spec.rb
60
63
  - spec/spec_helper.rb
64
+ - spec/test-config.yml