switches 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/README.rdoc +1 -1
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/lib/switches.rb +67 -49
  5. data/switches.gemspec +6 -6
  6. metadata +29 -14
@@ -2,7 +2,7 @@
2
2
 
3
3
  Switches lets you turn on and off sections of your code with <tt>Switches.foobar?</tt> booleans.
4
4
 
5
- It's an extraction from [http://brighterplanet.com](http://brighterplanet.com), where we use it as an emergency button to turn on/off API integration with Facebook, Campaign Monitor, etc.
5
+ It's an extraction from http://brighterplanet.com, where we use it as an emergency button to turn on/off API integration with Facebook, Campaign Monitor, etc.
6
6
 
7
7
  == Quick start
8
8
 
data/Rakefile CHANGED
@@ -35,7 +35,7 @@ It's inspired by ActiveSupport's StringInquirer (e.g. Rails.development?) and tr
35
35
  gem.authors = ["Seamus Abshere"]
36
36
  gem.rubyforge_project = "switches"
37
37
  gem.add_development_dependency "rspec", ">= 1.2.9"
38
- gem.add_dependency "activesupport"
38
+ gem.add_dependency 'activesupport', '>=2.3.4'
39
39
  end
40
40
  Jeweler::GemcutterTasks.new
41
41
  Jeweler::RubyforgeTasks.new do |rubyforge|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
@@ -2,21 +2,39 @@ require 'yaml'
2
2
  require 'pp'
3
3
  require 'fileutils'
4
4
  require 'active_support'
5
-
6
- # TODO not agnostic, expects RAILS_ROOT
5
+ require 'active_support/core_ext/module/attribute_accessors'
7
6
 
8
7
  module Switches
9
- CONFIG_DIR = File.join RAILS_ROOT, 'config', 'switches'
10
- RAKE_PATH = File.join RAILS_ROOT, 'lib', 'tasks', 'switches.rake'
11
- CAPISTRANO_PATH = File.join CONFIG_DIR, 'capistrano_tasks.rb'
12
- CAPISTRANO_LOAD_PATH = CAPISTRANO_PATH.gsub "#{RAILS_ROOT}/", '' # => 'config/switches/capistrano_tasks.rb'
13
- CAPFILE_PATH = File.join RAILS_ROOT, 'Capfile'
14
- CURRENT_PATH = File.join CONFIG_DIR, 'current.yml'
15
- DEFAULT_PATH = File.join CONFIG_DIR, 'default.yml'
16
- BACKUP_PATH = File.join CONFIG_DIR, 'backup.yml'
17
- TRANSACTION_PID_PATH = File.join CONFIG_DIR, 'transaction.pid'
18
-
8
+ mattr_accessor :root_path
19
9
  class << self
10
+ def config_dir
11
+ @_config_dir ||= File.join root_path, 'config', 'switches'
12
+ end
13
+ def rake_path
14
+ @_rake_path ||= File.join root_path, 'lib', 'tasks', 'switches.rake'
15
+ end
16
+ def capistrano_path
17
+ @_capistrano_path ||= File.join config_dir, 'capistrano_tasks.rb'
18
+ end
19
+ def capistrano_load_path
20
+ @_capistrano_load_path ||= capistrano_path.gsub "#{root_path}/", '' # => 'config/switches/capistrano_tasks.rb'
21
+ end
22
+ def capfile_path
23
+ @_capfile_path ||= File.join root_path, 'Capfile'
24
+ end
25
+ def current_path
26
+ @_current_path ||= File.join config_dir, 'current.yml'
27
+ end
28
+ def default_path
29
+ @_default_path ||= File.join config_dir, 'default.yml'
30
+ end
31
+ def backup_path
32
+ @_backup_path ||= File.join config_dir, 'backup.yml'
33
+ end
34
+ def transaction_pid_path
35
+ @_transaction_pid_path ||= File.join config_dir, 'transaction.pid'
36
+ end
37
+
20
38
  def dump(method)
21
39
  if ENV['SWITCHES_XML'] == 'true'
22
40
  puts send(method).to_xml
@@ -26,48 +44,48 @@ module Switches
26
44
  end
27
45
 
28
46
  def say(str)
29
- $stderr.puts "[SWITCHES GEM] #{str.gsub "#{RAILS_ROOT}/", ''}"
47
+ $stderr.puts "[SWITCHES GEM] #{str.gsub "#{root_path}/", ''}"
30
48
  end
31
49
 
32
50
  def setup
33
- say "Making #{CONFIG_DIR}."
34
- FileUtils.mkdir_p CONFIG_DIR
51
+ say "Making #{config_dir}."
52
+ FileUtils.mkdir_p config_dir
35
53
 
36
- if File.exists? DEFAULT_PATH
37
- say "Not putting an example default.yml into #{DEFAULT_PATH} because you already have one."
54
+ if File.exists? default_path
55
+ say "Not putting an example default.yml into #{default_path} because you already have one."
38
56
  else
39
- say "Putting an example default.yml into #{DEFAULT_PATH}."
40
- File.open(DEFAULT_PATH, 'w') { |f| f.write({ 'quick_brown' => true, 'fox_jumps' => false }.to_yaml) }
57
+ say "Putting an example default.yml into #{default_path}."
58
+ File.open(default_path, 'w') { |f| f.write({ 'quick_brown' => true, 'fox_jumps' => false }.to_yaml) }
41
59
  end
42
60
 
43
- say "Refreshing gem-related Rake tasks at #{RAKE_PATH}."
44
- FileUtils.cp File.join(File.dirname(__FILE__), 'tasks', 'switches.rake'), RAKE_PATH
61
+ say "Refreshing gem-related Rake tasks at #{rake_path}."
62
+ FileUtils.cp File.join(File.dirname(__FILE__), 'tasks', 'switches.rake'), rake_path
45
63
 
46
- say "Refreshing gem-related Capistrano tasks at #{CAPISTRANO_PATH}."
47
- FileUtils.cp File.join(File.dirname(__FILE__), 'tasks', 'capistrano_tasks.rb'), CAPISTRANO_PATH
64
+ say "Refreshing gem-related Capistrano tasks at #{capistrano_path}."
65
+ FileUtils.cp File.join(File.dirname(__FILE__), 'tasks', 'capistrano_tasks.rb'), capistrano_path
48
66
 
49
67
  needs_append = false
50
- if not File.exists?(CAPFILE_PATH)
68
+ if not File.exists?(capfile_path)
51
69
  say "Creating a Capfile and including our tasks in it."
52
70
  needs_append = true
53
- FileUtils.touch CAPFILE_PATH
54
- elsif old_capfile = IO.read(CAPFILE_PATH) and old_capfile.include?(CAPISTRANO_LOAD_PATH)
71
+ FileUtils.touch capfile_path
72
+ elsif old_capfile = IO.read(capfile_path) and old_capfile.include?(capistrano_load_path)
55
73
  say "Found a Capfile that already includes our tasks. Great!"
56
74
  else
57
75
  say "I'm going to add a line to your existing Capfile. Sorry if I break anything!"
58
76
  needs_append = true
59
77
  end
60
78
 
61
- File.open(CAPFILE_PATH, 'a') do |f|
79
+ File.open(capfile_path, 'a') do |f|
62
80
  say "Appending a line that loads our Capistrano tasks to your Capfile."
63
- f.write "\n# Added by switches gem #{Time.now}\nload '#{CAPISTRANO_LOAD_PATH}'\n"
81
+ f.write "\n# Added by switches gem #{Time.now}\nload '#{capistrano_load_path}'\n"
64
82
  end if needs_append
65
83
 
66
84
  say "Don't forget to:"
67
- say "* git add #{DEFAULT_PATH}"
68
- say "* git add #{RAKE_PATH}"
69
- say "* git ignore #{CAPISTRANO_PATH}"
70
- say "* git ignore #{CURRENT_PATH}"
85
+ say "* git add #{default_path}"
86
+ say "* git add #{rake_path}"
87
+ say "* git ignore #{capistrano_path}"
88
+ say "* git ignore #{current_path}"
71
89
  say "You can refresh the gem tasks with Switches.setup. It won't touch anything else."
72
90
  end
73
91
 
@@ -92,12 +110,12 @@ module Switches
92
110
 
93
111
  def default
94
112
  return @_default unless @_default.nil?
95
- # say "file system activity #{DEFAULT_PATH}"
113
+ # say "file system activity #{default_path}"
96
114
  resolve_transaction!
97
- @_default = YAML.load(IO.read(DEFAULT_PATH))
115
+ @_default = YAML.load(IO.read(default_path))
98
116
  @_default.stringify_keys!
99
117
  rescue Errno::ENOENT
100
- say "Couldn't read defaults from #{DEFAULT_PATH}."
118
+ say "Couldn't read defaults from #{default_path}."
101
119
  say "You probably want to run \"./script/runner 'Switches.setup'\"."
102
120
  raise $!
103
121
  end
@@ -105,9 +123,9 @@ module Switches
105
123
  def current
106
124
  return @_current unless @_current.nil?
107
125
  resolve_transaction!
108
- if File.exist?(CURRENT_PATH)
109
- # say "file system activity #{CURRENT_PATH}"
110
- @_current = YAML.load(IO.read(CURRENT_PATH))
126
+ if File.exist?(current_path)
127
+ # say "file system activity #{current_path}"
128
+ @_current = YAML.load(IO.read(current_path))
111
129
  @_current.stringify_keys!
112
130
  else
113
131
  @_current = default.dup
@@ -151,22 +169,22 @@ module Switches
151
169
  end
152
170
 
153
171
  def reset
154
- FileUtils.rm_f CURRENT_PATH
172
+ FileUtils.rm_f current_path
155
173
  @_current = nil
156
174
  end
157
175
 
158
176
  def backup
159
177
  write_current
160
178
  start_transaction!
161
- # say "file system activity #{BACKUP_PATH}"
162
- FileUtils.cp CURRENT_PATH, BACKUP_PATH
179
+ # say "file system activity #{backup_path}"
180
+ FileUtils.cp current_path, backup_path
163
181
  end
164
182
 
165
183
  def restore
166
- if File.exist?(BACKUP_PATH)
167
- FileUtils.mv BACKUP_PATH, CURRENT_PATH
184
+ if File.exist?(backup_path)
185
+ FileUtils.mv backup_path, current_path
168
186
  else
169
- raise ArgumentError, "#{BACKUP_PATH} doesn't exist."
187
+ raise ArgumentError, "#{backup_path} doesn't exist."
170
188
  end
171
189
  end_transaction!
172
190
  @_current = nil
@@ -174,12 +192,12 @@ module Switches
174
192
 
175
193
  def write_current
176
194
  current # load it first!
177
- File.open(CURRENT_PATH, 'w') { |f| f.write current.stringify_keys.to_yaml }
195
+ File.open(current_path, 'w') { |f| f.write current.stringify_keys.to_yaml }
178
196
  end
179
197
 
180
198
  def transaction_pid
181
- # say "file system activity #{TRANSACTION_PID_PATH}"
182
- IO.readlines(TRANSACTION_PID_PATH).first.chomp.to_i if File.exists?(TRANSACTION_PID_PATH)
199
+ # say "file system activity #{transaction_pid_path}"
200
+ IO.readlines(transaction_pid_path).first.chomp.to_i if File.exists?(transaction_pid_path)
183
201
  end
184
202
 
185
203
  def resolve_transaction!
@@ -192,12 +210,12 @@ module Switches
192
210
  def start_transaction!
193
211
  resolve_transaction!
194
212
  say "Starting transaction"
195
- File.open(TRANSACTION_PID_PATH, 'w') { |f| f.write Process.pid }
213
+ File.open(transaction_pid_path, 'w') { |f| f.write Process.pid }
196
214
  end
197
215
 
198
216
  def end_transaction!
199
217
  say "Finishing transaction"
200
- FileUtils.rm_f TRANSACTION_PID_PATH
218
+ FileUtils.rm_f transaction_pid_path
201
219
  end
202
220
  end
203
221
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{switches}
8
- s.version = "0.1.6"
8
+ s.version = "0.1.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Seamus Abshere"]
12
- s.date = %q{2009-11-19}
12
+ s.date = %q{2010-03-30}
13
13
  s.description = %q{
14
14
  Switches lets you turn on and off parts of your code from the commandline. There's a defaults.yml and a current.yml in the background.
15
15
 
@@ -58,7 +58,7 @@ It's inspired by ActiveSupport's StringInquirer (e.g. Rails.development?) and tr
58
58
  s.rdoc_options = ["--charset=UTF-8"]
59
59
  s.require_paths = ["lib"]
60
60
  s.rubyforge_project = %q{switches}
61
- s.rubygems_version = %q{1.3.5}
61
+ s.rubygems_version = %q{1.3.6}
62
62
  s.summary = %q{Turn on and off parts of your code based on yaml files.}
63
63
  s.test_files = [
64
64
  "spec/spec_helper.rb",
@@ -71,14 +71,14 @@ It's inspired by ActiveSupport's StringInquirer (e.g. Rails.development?) and tr
71
71
 
72
72
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
73
73
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
74
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
74
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
75
75
  else
76
76
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
77
- s.add_dependency(%q<activesupport>, [">= 0"])
77
+ s.add_dependency(%q<activesupport>, [">= 2.3.4"])
78
78
  end
79
79
  else
80
80
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
81
- s.add_dependency(%q<activesupport>, [">= 0"])
81
+ s.add_dependency(%q<activesupport>, [">= 2.3.4"])
82
82
  end
83
83
  end
84
84
 
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switches
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 7
9
+ version: 0.1.7
5
10
  platform: ruby
6
11
  authors:
7
12
  - Seamus Abshere
@@ -9,29 +14,37 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-11-19 00:00:00 -05:00
17
+ date: 2010-03-30 00:00:00 -04:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rspec
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
23
31
  version: 1.2.9
24
- version:
32
+ type: :development
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: activesupport
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
33
- version: "0"
34
- version:
41
+ segments:
42
+ - 2
43
+ - 3
44
+ - 4
45
+ version: 2.3.4
46
+ type: :runtime
47
+ version_requirements: *id002
35
48
  description: "\n\
36
49
  Switches lets you turn on and off parts of your code from the commandline. There's a defaults.yml and a current.yml in the background.\n\n\
37
50
  For example:\n\
@@ -83,18 +96,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
96
  requirements:
84
97
  - - ">="
85
98
  - !ruby/object:Gem::Version
99
+ segments:
100
+ - 0
86
101
  version: "0"
87
- version:
88
102
  required_rubygems_version: !ruby/object:Gem::Requirement
89
103
  requirements:
90
104
  - - ">="
91
105
  - !ruby/object:Gem::Version
106
+ segments:
107
+ - 0
92
108
  version: "0"
93
- version:
94
109
  requirements: []
95
110
 
96
111
  rubyforge_project: switches
97
- rubygems_version: 1.3.5
112
+ rubygems_version: 1.3.6
98
113
  signing_key:
99
114
  specification_version: 3
100
115
  summary: Turn on and off parts of your code based on yaml files.