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.
@@ -19,6 +19,8 @@
19
19
  feature_set
20
20
  }.each { |name| require "flip/#{name}" }
21
21
 
22
+ require "flip/engine" if defined?(Rails)
23
+
22
24
  module Flip
23
25
  extend Facade
24
26
  end
@@ -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).on?
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, on
26
- @klass.find_or_initialize_by_key(key).update_attributes! on: on
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
@@ -1,6 +1,10 @@
1
1
  module Flip
2
2
  module Declarable
3
3
 
4
+ def self.extended(base)
5
+ FeatureSet.reset
6
+ end
7
+
4
8
  # Adds a new feature definition, creates predicate method.
5
9
  def feature(key, options = {})
6
10
  FeatureSet.instance << Flip::Definition.new(key, options)
@@ -0,0 +1,4 @@
1
+ module Flip
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -6,7 +6,7 @@ module Flip
6
6
  end
7
7
 
8
8
  def self.reset
9
- remove_instance_variable :@instance
9
+ @instance = nil
10
10
  end
11
11
 
12
12
  # Sets the default for definitions which fall through the strategies.
@@ -1,3 +1,3 @@
1
1
  module Flip
2
- VERSION = "0.0.1.alpha"
2
+ VERSION = "0.0.1.alpha2"
3
3
  end
@@ -0,0 +1,5 @@
1
+ Description:
2
+ Generates migration to create the features table for the Feature model.
3
+
4
+ Example:
5
+ rails generate flip:migration
@@ -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,10 @@
1
+ class CreateFeatures < ActiveRecord::Migration
2
+ def change
3
+ create_table :features do |t|
4
+ t.string :key, null: false
5
+ t.boolean :enabled, null: false, default: false
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates the Feature database model class for Flip.
3
+
4
+ Example:
5
+ rails generate flip:model
6
+
7
+ This will create:
8
+ app/models/feature.rb (class Feature < ActiveRecord::Base)
@@ -0,0 +1,8 @@
1
+ class Flip::ModelGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def copy_feature_model_file
5
+ copy_file "feature.rb", "app/models/feature.rb"
6
+ end
7
+
8
+ 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
@@ -0,0 +1,7 @@
1
+ Description:
2
+ Add routes for the Flip control page.
3
+
4
+ Example:
5
+ rails generate flip:routes
6
+
7
+ This will add routes to app/routes.rb
@@ -0,0 +1,7 @@
1
+ class Flip::RoutesGenerator < Rails::Generators::Base
2
+
3
+ def add_route
4
+ route %{mount Flip::Engine => "/flip"}
5
+ end
6
+
7
+ 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(:on?) { true } } }
16
- let(:disabled_record) { model_klass.new.tap { |m| m.stub(:on?) { false } } }
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(on: true)
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(on: false)
53
+ enabled_record.should_receive(:update_attributes!).with(enabled: false)
54
54
  strategy.switch! :one, false
55
55
  end
56
56
  end
@@ -1,19 +1,20 @@
1
1
  require "spec_helper"
2
2
 
3
- class TestableFlipModel
4
- extend Flip::Declarable
3
+ describe Flip::Declarable do
5
4
 
6
- strategy Flip::DeclarationStrategy
7
- default false
5
+ let!(:model_class) do
6
+ Class.new do
7
+ extend Flip::Declarable
8
8
 
9
- feature :one
10
- feature :two, description: "Second one."
11
- feature :three, default: true
12
- end
9
+ strategy Flip::DeclarationStrategy
10
+ default false
13
11
 
14
- describe Flip::Declarable do
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
@@ -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.alpha
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-24 00:00:00.000000000 +10:00
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: &2153418240 !ruby/object:Gem::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: *2153418240
25
+ version_requirements: *2153453820
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: i18n
28
- requirement: &2153417820 !ruby/object:Gem::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: *2153417820
36
+ version_requirements: *2153451180
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &2153417280 !ruby/object:Gem::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: *2153417280
47
+ version_requirements: *2153445440
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rake
50
- requirement: &2153416860 !ruby/object:Gem::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: *2153416860
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