flip 0.0.1.alpha → 0.0.1.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/flip.rb +2 -0
- data/lib/flip/database_strategy.rb +4 -4
- data/lib/flip/declarable.rb +4 -0
- data/lib/flip/engine.rb +4 -0
- data/lib/flip/feature_set.rb +1 -1
- data/lib/flip/version.rb +1 -1
- data/lib/generators/flip/migration/USAGE +5 -0
- data/lib/generators/flip/migration/migration_generator.rb +22 -0
- data/lib/generators/flip/migration/templates/create_features.rb +10 -0
- data/lib/generators/flip/model/USAGE +8 -0
- data/lib/generators/flip/model/model_generator.rb +8 -0
- data/lib/generators/flip/model/templates/feature.rb +15 -0
- data/lib/generators/flip/routes/USAGE +7 -0
- data/lib/generators/flip/routes/routes_generator.rb +7 -0
- data/spec/database_strategy_spec.rb +4 -4
- data/spec/declarable_spec.rb +11 -10
- data/spec/feature_set_spec.rb +3 -0
- metadata +19 -10
data/lib/flip.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
module Flip
|
3
3
|
class DatabaseStrategy < AbstractStrategy
|
4
4
|
|
5
|
-
def initialize(model_klass)
|
5
|
+
def initialize(model_klass = Feature)
|
6
6
|
@klass = model_klass
|
7
7
|
end
|
8
8
|
|
@@ -15,15 +15,15 @@ module Flip
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def on? definition
|
18
|
-
feature(definition).
|
18
|
+
feature(definition).enabled?
|
19
19
|
end
|
20
20
|
|
21
21
|
def switchable?
|
22
22
|
true
|
23
23
|
end
|
24
24
|
|
25
|
-
def switch! key,
|
26
|
-
@klass.find_or_initialize_by_key(key).update_attributes!
|
25
|
+
def switch! key, enable
|
26
|
+
@klass.find_or_initialize_by_key(key).update_attributes! enabled: enable
|
27
27
|
end
|
28
28
|
|
29
29
|
def delete! key
|
data/lib/flip/declarable.rb
CHANGED
data/lib/flip/engine.rb
ADDED
data/lib/flip/feature_set.rb
CHANGED
data/lib/flip/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "rails/generators/active_record/migration"
|
2
|
+
|
3
|
+
class Flip::MigrationGenerator < Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
def create_migration_file
|
9
|
+
migration_template "create_features.rb", "db/migrate/create_features.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
# Stubbed in railties/lib/rails/generators/migration.rb
|
13
|
+
#
|
14
|
+
# This implementation a simplified version of:
|
15
|
+
# activerecord/lib/rails/generators/active_record/migration.rb
|
16
|
+
#
|
17
|
+
# See: http://www.ruby-forum.com/topic/203205
|
18
|
+
def self.next_migration_number(dirname)
|
19
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Feature
|
2
|
+
extend Flip::Declarable
|
3
|
+
|
4
|
+
strategy Flip::CookieStrategy
|
5
|
+
strategy Flip::DatabaseStrategy
|
6
|
+
strategy Flip::DeclarationStrategy
|
7
|
+
default false
|
8
|
+
|
9
|
+
# Declare your features here, e.g:
|
10
|
+
#
|
11
|
+
# feature :world_domination,
|
12
|
+
# default: true,
|
13
|
+
# description: "Take over the world."
|
14
|
+
|
15
|
+
end
|
@@ -12,8 +12,8 @@ describe Flip::DatabaseStrategy do
|
|
12
12
|
feature :three, default: true
|
13
13
|
end
|
14
14
|
end
|
15
|
-
let(:enabled_record) { model_klass.new.tap { |m| m.stub(:
|
16
|
-
let(:disabled_record) { model_klass.new.tap { |m| m.stub(:
|
15
|
+
let(:enabled_record) { model_klass.new.tap { |m| m.stub(:enabled?) { true } } }
|
16
|
+
let(:disabled_record) { model_klass.new.tap { |m| m.stub(:enabled?) { false } } }
|
17
17
|
|
18
18
|
subject { strategy }
|
19
19
|
|
@@ -45,12 +45,12 @@ describe Flip::DatabaseStrategy do
|
|
45
45
|
describe "#switch!" do
|
46
46
|
it "can switch a feature on" do
|
47
47
|
model_klass.should_receive(:find_or_initialize_by_key).with(:one).and_return(disabled_record)
|
48
|
-
disabled_record.should_receive(:update_attributes!).with(
|
48
|
+
disabled_record.should_receive(:update_attributes!).with(enabled: true)
|
49
49
|
strategy.switch! :one, true
|
50
50
|
end
|
51
51
|
it "can switch a feature off" do
|
52
52
|
model_klass.should_receive(:find_or_initialize_by_key).with(:one).and_return(enabled_record)
|
53
|
-
enabled_record.should_receive(:update_attributes!).with(
|
53
|
+
enabled_record.should_receive(:update_attributes!).with(enabled: false)
|
54
54
|
strategy.switch! :one, false
|
55
55
|
end
|
56
56
|
end
|
data/spec/declarable_spec.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
extend Flip::Declarable
|
3
|
+
describe Flip::Declarable do
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
let!(:model_class) do
|
6
|
+
Class.new do
|
7
|
+
extend Flip::Declarable
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
feature :three, default: true
|
12
|
-
end
|
9
|
+
strategy Flip::DeclarationStrategy
|
10
|
+
default false
|
13
11
|
|
14
|
-
|
12
|
+
feature :one
|
13
|
+
feature :two, description: "Second one."
|
14
|
+
feature :three, default: true
|
15
|
+
end
|
16
|
+
end
|
15
17
|
|
16
|
-
let(:model_class) { TestableFlipModel }
|
17
18
|
subject { Flip::FeatureSet.instance }
|
18
19
|
|
19
20
|
describe "the .on? class method" do
|
data/spec/feature_set_spec.rb
CHANGED
@@ -33,6 +33,9 @@ describe Flip::FeatureSet do
|
|
33
33
|
Flip::FeatureSet.reset
|
34
34
|
Flip::FeatureSet.instance.should_not equal(instance_before_reset)
|
35
35
|
end
|
36
|
+
it "can be reset multiple times without error" do
|
37
|
+
2.times { Flip::FeatureSet.reset }
|
38
|
+
end
|
36
39
|
end
|
37
40
|
|
38
41
|
describe "#default= and #on? with null strategy" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.alpha2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-05-
|
12
|
+
date: 2011-05-29 00:00:00.000000000 +10:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
17
|
-
requirement: &
|
17
|
+
requirement: &2153453820 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '3.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2153453820
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: i18n
|
28
|
-
requirement: &
|
28
|
+
requirement: &2153451180 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2153451180
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &2153445440 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '2.5'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2153445440
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rake
|
50
|
-
requirement: &
|
50
|
+
requirement: &2153437540 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2153437540
|
59
59
|
description: Declarative API for specifying features, switchable in declaration, database
|
60
60
|
and cookies.
|
61
61
|
email:
|
@@ -77,9 +77,18 @@ files:
|
|
77
77
|
- lib/flip/declarable.rb
|
78
78
|
- lib/flip/declaration_strategy.rb
|
79
79
|
- lib/flip/definition.rb
|
80
|
+
- lib/flip/engine.rb
|
80
81
|
- lib/flip/facade.rb
|
81
82
|
- lib/flip/feature_set.rb
|
82
83
|
- lib/flip/version.rb
|
84
|
+
- lib/generators/flip/migration/USAGE
|
85
|
+
- lib/generators/flip/migration/migration_generator.rb
|
86
|
+
- lib/generators/flip/migration/templates/create_features.rb
|
87
|
+
- lib/generators/flip/model/USAGE
|
88
|
+
- lib/generators/flip/model/model_generator.rb
|
89
|
+
- lib/generators/flip/model/templates/feature.rb
|
90
|
+
- lib/generators/flip/routes/USAGE
|
91
|
+
- lib/generators/flip/routes/routes_generator.rb
|
83
92
|
- spec/abstract_strategy_spec.rb
|
84
93
|
- spec/controller_filters_spec.rb
|
85
94
|
- spec/cookie_strategy_spec.rb
|