togglify 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Guardfile +3 -1
- data/README.md +18 -2
- data/VERSION +1 -1
- data/lib/togglify.rb +11 -0
- data/spec/lib/togglify/storage_spec.rb +0 -1
- data/spec/lib/togglify_spec.rb +30 -0
- data/spec/support/.togglify +0 -0
- data/togglify.gemspec +2 -2
- metadata +3 -3
data/Guardfile
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# A sample Guardfile
|
2
2
|
# More info at https://github.com/guard/guard#readme
|
3
|
+
notification :emacs
|
4
|
+
ignore %r{^spec/dummy/}, /public/
|
3
5
|
|
4
|
-
guard 'rspec' do
|
6
|
+
guard 'rspec', spec_paths: ['spec/lib'] do
|
5
7
|
watch(%r{^spec/.+_spec\.rb$})
|
6
8
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
9
|
watch('spec/spec_helper.rb') { "spec" }
|
data/README.md
CHANGED
@@ -24,7 +24,9 @@ Anywhere in your code you can add a togglify block giving it a name. Like this o
|
|
24
24
|
|
25
25
|
By default all toggles are enabled, meaning that any code put in those blocks will be executed. So when this block of code gets ran it will output the puts statement. Now to disable this block of code and any block of cade with the tag :sample_name you can run the following rake command.
|
26
26
|
|
27
|
-
|
27
|
+
# In ZSH you will have to escape the square brackets with a \ or prepend the rake command
|
28
|
+
# with noglob
|
29
|
+
$ rake togglify:disable[sample_name]
|
28
30
|
|
29
31
|
Any Togglify block with the name :sample_name is now disabled in the `development` environment. To disable it in other environments append the command with `RAILS_ENV=environment` for example to disable these blocks in the `test` environment you can run
|
30
32
|
|
@@ -32,7 +34,21 @@ Any Togglify block with the name :sample_name is now disabled in the `developmen
|
|
32
34
|
|
33
35
|
Then to re-enable all the code blocks with the sample_name tag you can run
|
34
36
|
|
35
|
-
|
37
|
+
# Again, this defaults to development environment. append RAILS_ENV= for different environments
|
38
|
+
$ rake togglify:enable[sample_name]
|
39
|
+
|
40
|
+
You can programatically enable and disable toggles with the following code
|
41
|
+
|
42
|
+
Togglify.enable(:sample_name)
|
43
|
+
Togglify.disable(:sample_name)
|
44
|
+
|
45
|
+
Then to check the status of a toggle you can call
|
46
|
+
|
47
|
+
Togglify.enabled?(:sample_name) # Returns true or false
|
48
|
+
Togglify.enabled?(:sample_name) # Returns true or false
|
49
|
+
Togglify.status(:sample_name) # Returns hash with status { :id => :sample_name, :development => :enabled}
|
50
|
+
|
51
|
+
|
36
52
|
|
37
53
|
## Contributing to togglify
|
38
54
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/togglify.rb
CHANGED
@@ -24,6 +24,17 @@ module Togglify
|
|
24
24
|
false
|
25
25
|
end
|
26
26
|
|
27
|
+
def disabled?(toggle)
|
28
|
+
stored_toggle = storage.read(toggle)
|
29
|
+
return false if stored_toggle.nil?
|
30
|
+
return false if stored_toggle[storage.env] == :enabled
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
def status(toggle)
|
35
|
+
storage.read(toggle)
|
36
|
+
end
|
37
|
+
|
27
38
|
def enable(toggle)
|
28
39
|
storage.write_on toggle
|
29
40
|
end
|
data/spec/lib/togglify_spec.rb
CHANGED
@@ -53,6 +53,36 @@ describe Togglify do
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
context "#disabled?" do
|
57
|
+
it "should return false by default" do
|
58
|
+
FileUtils.rm path
|
59
|
+
Togglify.disabled?(:forum).should be_false
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return true if its disabled" do
|
63
|
+
Togglify.send(:storage).write_off :forum
|
64
|
+
Togglify.disabled?(:forum).should be_true
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return false if it is enabled" do
|
68
|
+
Togglify.send(:storage).write_on :forum
|
69
|
+
Togglify.disabled?(:forum).should be_false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "#status" do
|
74
|
+
it "should return the hash of the toggle" do
|
75
|
+
Togglify.enable :forum
|
76
|
+
Rails.env = "development"
|
77
|
+
Togglify.disable :forum
|
78
|
+
Togglify.status(:forum).should eq({
|
79
|
+
id: :forum,
|
80
|
+
test: :enabled,
|
81
|
+
development: :disabled
|
82
|
+
})
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
56
86
|
context "#storage" do
|
57
87
|
it "should have a storage object" do
|
58
88
|
Togglify.send(:storage).class.should eq Togglify::Storage
|
data/spec/support/.togglify
CHANGED
Binary file
|
data/togglify.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "togglify"
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brady Love"]
|
12
|
-
s.date = "2012-10-
|
12
|
+
s.date = "2012-10-24"
|
13
13
|
s.description = "A Rubygem that allows you to easily enable/disable parts of your ruby code."
|
14
14
|
s.email = "love.brady@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: togglify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -274,7 +274,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
274
274
|
version: '0'
|
275
275
|
segments:
|
276
276
|
- 0
|
277
|
-
hash: -
|
277
|
+
hash: -2682481195966168762
|
278
278
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
279
279
|
none: false
|
280
280
|
requirements:
|