simple_toggle 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 869a6ade85707be2b0d5fbb1b052e49719a5aadb
4
+ data.tar.gz: 05fd00d8dc8461fdf3aced5a720a07fde5d0da96
5
+ SHA512:
6
+ metadata.gz: c094e6a24649714407402f8c68c3cd4e1f850d783296db4115f161dd672c15fa4c977b3b7dfe5d15add057ce7c91983aea48218fd2f104eca919fd97e0597725
7
+ data.tar.gz: a6407a408e287e8c8879d6b15cce78683caef239fc884e3bd46ada32f2e8711ef492cff767b9b01c292061344171d9a9940d6436dc04f3e2839b1c5a45ceaf67
@@ -0,0 +1,19 @@
1
+ *.swp
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ db.sqlite3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in feature_flag.gemspec
4
+ gemspec
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec, cmd: 'bundle exec rspec -f d --no-profile' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Trevor Oke
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 trevor-oke
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # FeatureFlag
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'feature_flag'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install feature_flag
18
+
19
+ ## Migration
20
+
21
+ $ rails generate feature_flag:install
22
+ $ rake db:migrate
23
+
24
+ ## Usage
25
+
26
+ ### Executing code based on feature
27
+
28
+ FeatureFlag::Toggle.when_active(:featurename) do
29
+ # feature code here
30
+ end
31
+
32
+ ### Testing if a feature is active
33
+
34
+ FeatureFlag::Toggle.active?(:featurename)
35
+
36
+ ### Ensuring a feature is active
37
+
38
+ FeatureFlag::Toggle.require(:featurename)
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
8
+
@@ -0,0 +1,30 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/named_base'
3
+
4
+ module SimpleToggle
5
+ module Generators
6
+ class InstallGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+
9
+ desc "generates a migration for simpe toggles"
10
+ source_root File.expand_path('../../templates', __FILE__)
11
+
12
+ def copy_migrations
13
+ copy_migration "create_simple_toggles.rb"
14
+ end
15
+
16
+ def self.next_migration_number(dirname)
17
+ Time.now.strftime("%Y%m%d%H%M%S")
18
+ end
19
+
20
+ protected
21
+ def copy_migration(migration_name)
22
+ if self.class.migration_exists?("db/migrate", migration_name)
23
+ say_status("skipped", "Migration #{migration_name} already exists")
24
+ else
25
+ migration_template "migrations/#{migration_name}", "db/migrate/#{migration_name}"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,15 @@
1
+ class CreateSimpleToggleToggles < ActiveRecord::Migration
2
+ def change
3
+ create_table :simple_toggle_toggles do |t|
4
+ t.string :name
5
+ t.boolean :active
6
+
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :simple_toggle_toggles, :name
11
+ add_index :simple_toggle_toggles, [:name, :active]
12
+ end
13
+ end
14
+
15
+
@@ -0,0 +1,22 @@
1
+ require "rails"
2
+ require "simple_toggle/version"
3
+ require 'active_record'
4
+
5
+ module SimpleToggle
6
+ class Toggle < ActiveRecord::Base
7
+ self.table_name = 'simple_toggle_toggles'
8
+
9
+ def self.when_active(feature)
10
+ yield if Toggle.active?(feature)
11
+ end
12
+
13
+ def self.require(feature)
14
+ raise unless Toggle.active?(feature)
15
+ end
16
+
17
+ def self.active?(feature)
18
+ toggle = Toggle.where(name: feature, active: true).first
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleToggle
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_toggle/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "simple_toggle"
8
+ gem.version = SimpleToggle::VERSION
9
+ gem.licenses = ['MIT']
10
+ gem.authors = ["Trevor Oke"]
11
+ gem.email = ["trevor@trevoroke.com"]
12
+ gem.description = %q{Simple feature toggle for ruby/rails}
13
+ gem.summary = %q{A simple ActivceRecord based feature toggle for ruby/rails.}
14
+ gem.homepage = "https://github.com/thefury/simple_toggle"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency 'rspec', '~> 3.1', '>= 3.1.0'
22
+ gem.add_development_dependency 'sqlite3', '~> 1.0'
23
+
24
+ gem.add_runtime_dependency 'activerecord', '~> 4.2'
25
+ gem.add_runtime_dependency 'rails', '~> 4.0'
26
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleToggle::Toggle do
4
+ ACTIVE_PARAM = { name: "active", active: true }
5
+ INACTIVE_PARAM = { name: "inactive", active: false }
6
+
7
+ before(:each) do
8
+ SimpleToggle::Toggle.create!(ACTIVE_PARAM)
9
+ SimpleToggle::Toggle.create!(INACTIVE_PARAM)
10
+ end
11
+
12
+ describe ".active?" do
13
+ specify { expect(SimpleToggle::Toggle.active?(:unknown)).to be_falsey }
14
+ specify { expect(SimpleToggle::Toggle.active?(:active)).to be_truthy }
15
+ specify { expect(SimpleToggle::Toggle.active?(:inactive)).to be_falsey }
16
+ end
17
+
18
+ describe ".when_active" do
19
+ before(:each) do
20
+ @value = 0
21
+ end
22
+
23
+ it "does not execute the block for unknown toggles" do
24
+ SimpleToggle::Toggle.when_active(:unknown) { @value = 1 }
25
+ expect(@value).to eq 0
26
+ end
27
+
28
+ it "does not execute the block for inactive toggles" do
29
+ SimpleToggle::Toggle.when_active(:inactive) { @value = 1 }
30
+ expect(@value).to eq 0
31
+ end
32
+
33
+ it "executes the block for active toggles" do
34
+ SimpleToggle::Toggle.when_active(:active) { @value = 1 }
35
+ expect(@value).to eq 1
36
+ end
37
+ end
38
+
39
+ describe ".require" do
40
+ specify { expect{ SimpleToggle::Toggle.require(:unknown) }.to raise_exception }
41
+ specify { expect{ SimpleToggle::Toggle.require(:inactive) }.to raise_exception }
42
+ specify { expect{ SimpleToggle::Toggle.require(:active) }.to_not raise_exception }
43
+ end
44
+ end
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'simple_toggle'
3
+ require 'active_record'
4
+ require 'sqlite3'
5
+
6
+ ActiveRecord::Base.establish_connection(
7
+ adapter: 'sqlite3',
8
+ database: ':memory:')
9
+
10
+ ActiveRecord::Schema.define do
11
+ self.verbose = false
12
+
13
+ create_table 'simple_toggle_toggles', force: true do |t|
14
+ t.string :name
15
+ t.boolean :active
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_toggle
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Trevor Oke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.1.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.1.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: sqlite3
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: activerecord
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '4.2'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '4.2'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rails
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '4.0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '4.0'
75
+ description: Simple feature toggle for ruby/rails
76
+ email:
77
+ - trevor@trevoroke.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - Gemfile
84
+ - Guardfile
85
+ - LICENSE
86
+ - LICENSE.txt
87
+ - README.md
88
+ - Rakefile
89
+ - lib/generators/simple_toggle/install_generator.rb
90
+ - lib/generators/templates/migrations/create_simple_toggles.rb
91
+ - lib/simple_toggle.rb
92
+ - lib/simple_toggle/version.rb
93
+ - simple_toggle.gemspec
94
+ - spec/lib/simple_toggle_spec.rb
95
+ - spec/spec_helper.rb
96
+ homepage: https://github.com/thefury/simple_toggle
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.4.2
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: A simple ActivceRecord based feature toggle for ruby/rails.
120
+ test_files:
121
+ - spec/lib/simple_toggle_spec.rb
122
+ - spec/spec_helper.rb
123
+ has_rdoc: