sifttter-redux 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48c3ee25e5aa975dfb797960ac5f442d174ff665
4
- data.tar.gz: 86542233200617d91dea2ee56b34723a7a8e0901
3
+ metadata.gz: 3775e070fe18f1cf9c290b81ea98344482fb877e
4
+ data.tar.gz: b99739072ee074da6f951a48c257bf634e6ea347
5
5
  SHA512:
6
- metadata.gz: e4e630389cb349d81d20f3f6ee0dc9042f74260b30fbb0642658f26e61afe08c9bb64b28c4363099e48c53d8162883b493bf7f8a4de2b3fdd6c6eab0371224a0
7
- data.tar.gz: 5ef3c0388f1730d1f4633dcd3e4aac3c8e183a83de4a942431f2bc7849dd7a41fa296843aec4d7b65b53e5c530435b5961b9a4b26ddbaab33ce45b503c754bc7
6
+ metadata.gz: d9b75d13ddd3e3794930b21cba62a02be62398e3830d2e5abb72407eb155b31889b277b238ada6223ad37cad503d99b6e2a9f55ba34ca66d0624102d611cd34e
7
+ data.tar.gz: 132d7265b89e72dd7722b754cd65a4d6714352f4c3b7fe19bc1e380088ee9e242397c39aa5aface0b6e70c9649b5d3b91966d779211aac73948ee44167315d6a
data/.travis.yml CHANGED
@@ -3,8 +3,4 @@ rvm:
3
3
  - 2.1.0
4
4
  - 2.0.0
5
5
  - 1.9.3
6
- - 1.9.2
7
- - 1.8.7
8
- - jruby-19mode
9
- - jruby-18mode
10
- - rbx-19mode
6
+ - jruby-19mode
data/HISTORY.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.4.1 (2014-02-26)
2
+
3
+ * Added `-s` flag to `init` command for initialization from scratch
4
+ * Added gem version to config file (for reference going forward)
5
+ * Added message to prompt users to re-init on upgrade
6
+
1
7
  # 0.4.0 (2014-02-26)
2
8
 
3
9
  * Removed some hardcoded values
data/README.md CHANGED
@@ -47,7 +47,7 @@ SYNOPSIS
47
47
  srd [global options] command [command options] [arguments...]
48
48
 
49
49
  VERSION
50
- 0.3.9
50
+ 0.4.1
51
51
 
52
52
  GLOBAL OPTIONS
53
53
  --help - Show this message
@@ -60,6 +60,27 @@ COMMANDS
60
60
  init - Install and initialize dependencies
61
61
  ```
62
62
 
63
+ Note that each command's options can be revealed by adding the `--help` switch after the command. For example:
64
+
65
+ ```
66
+ $ srd exec --help
67
+ NAME
68
+ exec - Execute the script
69
+
70
+ SYNOPSIS
71
+ srd [global options] exec [command options]
72
+
73
+ COMMAND OPTIONS
74
+ -c - Run catch-up mode from the beginning of the week to yesterday
75
+ -f arg - Run catch-up mode with this start date (default: none)
76
+ -i - Include today's date in catch-up
77
+ -n arg - Run catch-up mode for the last N days (default: none)
78
+ -t arg - Run catch-up mode with this end date (must also have -f) (default: none)
79
+ --[no-]verbose - Turns on verbose output
80
+ -w arg - Run catch-up mode for the last N weeks (default: none)
81
+ -y - Run catch-up mode for yesterday
82
+ ```
83
+
63
84
  ## Initialization
64
85
 
65
86
  ```
data/bin/srd CHANGED
@@ -64,20 +64,33 @@ switch(
64
64
  # ======================================================
65
65
 
66
66
  pre do |global, command, options, args|
67
+
67
68
  # Load SifttterRedux configuration module.
68
- Configuration.load(SRD_CONFIG_FILEPATH)
69
+ Configuration::load(SRD_CONFIG_FILEPATH)
69
70
 
70
71
  # Load Methadone CLILogging module.
71
- Methadone::CLILogging.change_logger(Methadone::CLILogger.new(SRD_LOG_FILEPATH, SRD_LOG_FILEPATH))
72
+ Methadone::CLILogging::change_logger(Methadone::CLILogger.new(SRD_LOG_FILEPATH, SRD_LOG_FILEPATH))
73
+
74
+ if File.exists?(SRD_CONFIG_FILEPATH)
75
+ # If the config file needs updating, force the user to do that first.
76
+ if Configuration['sifttter_redux']['version'].nil? || Gem::Version.new(Configuration['sifttter_redux']['version']) < Gem::Version.new(NEWEST_CONFIG_VERSION)
77
+ CLIMessage::info('This version needs to make some config changes.')
78
+ CLIMessage::info("Don't worry; when prompted, original values to existing config options will be presented.")
79
+ CLIMessage::prompt("Press enter to continue")
80
+
81
+ SifttterRedux::init
82
+ exit!
83
+ end
84
+ else
85
+ # Force the user to initialize if they try to execute first.
86
+ CLIMessage::info('You need to initialize Sifttter Redux first...') unless command.name_for_help[0] == 'init'
72
87
 
73
- # Force the user to initialize if they try to execute first.
74
- if command.name_for_help[0] == 'exec' && !File.exists?(SRD_CONFIG_FILEPATH)
75
- CLIMessage.info('You need to initialize Sifttter Redux first...')
76
- SifttterRedux.init
88
+ SifttterRedux::init
89
+ exit!
77
90
  end
78
91
 
79
92
  # Load Dropbox Uploader module.
80
- DBU.load(File.join(Configuration['db_uploader']['local_filepath'], 'dropbox_uploader.sh')) if File.exists?(SRD_CONFIG_FILEPATH)
93
+ DBU.load(Configuration['db_uploader']['exe_filepath']) if File.exists?(SRD_CONFIG_FILEPATH)
81
94
 
82
95
  true
83
96
  end
@@ -139,7 +152,7 @@ command :exec do |c|
139
152
 
140
153
  SifttterRedux.verbose = global_options[:verbose] || options[:verbose]
141
154
 
142
- CLIMessage.section_block('EXECUTING...') do
155
+ CLIMessage::section_block('EXECUTING...') do
143
156
  if options[:c] || options[:n] || options[:w] || options[:y] || options[:f] || options[:t]
144
157
 
145
158
  command_complete = false
@@ -174,11 +187,11 @@ command :exec do |c|
174
187
  dates = DateRangeMaker.range(options[:f], options[:t], options[:i])
175
188
 
176
189
  if dates.last > Date.today
177
- CLIMessage.warning("Ignoring overextended end date and using today's date (#{ Date.today })")
190
+ CLIMessage::warning("Ignoring overextended end date and using today's date (#{ Date.today })")
178
191
  dates = (dates.first..Date.today)
179
192
  end
180
193
  rescue ArgumentError => e
181
- CLIMessage.error(e)
194
+ CLIMessage::error(e)
182
195
  end
183
196
  end
184
197
  else
@@ -191,10 +204,10 @@ command :exec do |c|
191
204
 
192
205
  if first_date == second_date
193
206
  date_string = first_date.strftime('%B %d, %Y')
194
- CLIMessage.info("Creating entry for #{ date_string }...")
207
+ CLIMessage::info("Creating entry for #{ date_string }...")
195
208
  else
196
209
  date_string = "#{ first_date.strftime('%B %d, %Y') } to #{ second_date.strftime('%B %d, %Y') }"
197
- CLIMessage.info("Creating entries for dates from #{ date_string }...")
210
+ CLIMessage::info("Creating entries for dates from #{ date_string }...")
198
211
  end
199
212
 
200
213
  DBU.local_target = Configuration['sifttter_redux']['sifttter_local_filepath']
@@ -208,7 +221,7 @@ command :exec do |c|
208
221
 
209
222
  # Upload any Day One entries to Dropbox (if there are any).
210
223
  unless Dir[Configuration['sifttter_redux']['dayone_local_filepath'] + '/*'].empty?
211
- DBU.local_target = "#{Configuration['sifttter_redux']['dayone_local_filepath']}/*"
224
+ DBU.local_target = "#{ Configuration['sifttter_redux']['dayone_local_filepath'] }/*"
212
225
  DBU.remote_target = Configuration['sifttter_redux']['dayone_remote_filepath']
213
226
  DBU.message = 'Uploading Day One entries to Dropbox...'
214
227
  DBU.upload
@@ -220,7 +233,7 @@ command :exec do |c|
220
233
  Configuration['sifttter_redux']['sifttter_local_filepath']
221
234
  ]
222
235
 
223
- CLIMessage.info_block('Removing temporary local files...') { dirs.each { |d| FileUtils.rm_rf(d) } }
236
+ CLIMessage::info_block('Removing temporary local files...') { dirs.each { |d| FileUtils.rm_rf(d) } }
224
237
  end
225
238
  end
226
239
  end
@@ -234,12 +247,18 @@ end
234
247
  # ------------------------------------------------------
235
248
  desc 'Install and initialize dependencies'
236
249
  command :init do |c|
250
+
251
+ c.switch(
252
+ [:s],
253
+ desc: 'Run init from scratch (i.e., clear out all values from configuration)'
254
+ )
255
+
237
256
  c.action do |global_options, options, args|
238
- CLIMessage.section_block('INITIALIZING...') do
239
- if File.exists?(Configuration.config_path)
240
- SifttterRedux.init if CLIMessage.prompt("It looks like you've already initialized Sifttter Redux. Do you want to re-initialize?", 'N').downcase == 'y'
257
+ CLIMessage::section_block('INITIALIZING...') do
258
+ if File.exists?(Configuration::config_path) && !options[:s]
259
+ SifttterRedux::init(true) if CLIMessage::prompt("It looks like you've already initialized Sifttter Redux. Do you want to re-initialize?", 'N').downcase == 'y'
241
260
  else
242
- SifttterRedux.init
261
+ SifttterRedux::init
243
262
  end
244
263
  end
245
264
  end
@@ -70,14 +70,17 @@ module SifttterRedux
70
70
  # @param default The default option
71
71
  # @return String
72
72
  # ----------------------------------------------------
73
- def self.prompt(prompt, default)
74
- print "#{ prompt } [default: #{ default }]: "
73
+ def self.prompt(prompt, default = nil, log = true)
74
+ print "#{ prompt } #{ default.nil? ? '' : "[default: #{ default }]:" } ".blue
75
75
  choice = $stdin.gets.chomp
76
76
  if choice.empty?
77
- return default
77
+ r = default
78
78
  else
79
- return choice
79
+ r = choice
80
80
  end
81
+
82
+ Methadone::CLILogging.info("Answer to '#{ prompt }': #{r}") if log
83
+ r
81
84
  end
82
85
 
83
86
  # ----------------------------------------------------
@@ -19,7 +19,7 @@ module SifttterRedux
19
19
  if section_exists?(section_name)
20
20
  @data[section_name]
21
21
  else
22
- error = "Section does not exist: #{section_name}"
22
+ error = "Section does not exist: #{ section_name }"
23
23
  Methadone::CLILogging.error(error)
24
24
  fail ArgumentError, error
25
25
  end
@@ -39,7 +39,7 @@ module SifttterRedux
39
39
  @data[section_name] = {}
40
40
  @data[section_name].merge!(hash)
41
41
  else
42
- error = "Parameter is not a Hash: #{hash}"
42
+ error = "Parameter is not a Hash: #{ hash }"
43
43
  Methadone::CLILogging.error(error)
44
44
  fail ArgumentError, error
45
45
  end
@@ -56,7 +56,7 @@ module SifttterRedux
56
56
  if !self.section_exists?(section_name)
57
57
  @data[section_name] = {}
58
58
  else
59
- CLIMessage.warning("Can't create already-existing section: #{section_name}")
59
+ CLIMessage::warning("Can't create already-existing section: #{ section_name }")
60
60
  end
61
61
  end
62
62
 
@@ -81,7 +81,7 @@ module SifttterRedux
81
81
  if self.section_exists?(section_name)
82
82
  @data.delete(section_name)
83
83
  else
84
- CLIMessage.warning("Can't delete non-existing section: #{section_name}")
84
+ CLIMessage::warning("Can't delete non-existing section: #{ section_name }")
85
85
  end
86
86
  end
87
87
 
@@ -17,7 +17,7 @@ module SifttterRedux
17
17
  # ----------------------------------------------------
18
18
  def self.download
19
19
  if !@local_path.nil? && !@remote_path.nil?
20
- CLIMessage.info_block(@message ||= DEFAULT_MESSAGE, 'Done.', SifttterRedux.verbose) do
20
+ CLIMessage::info_block(@message ||= DEFAULT_MESSAGE, 'Done.', SifttterRedux.verbose) do
21
21
  if SifttterRedux.verbose
22
22
  system "#{ @dbu } download #{ @remote_path } #{ @local_path }"
23
23
  else
@@ -38,37 +38,32 @@ module SifttterRedux
38
38
  # local filesystem.
39
39
  # @return Void
40
40
  # ----------------------------------------------------
41
- def self.install_wizard
42
- valid_directory_chosen = false
41
+ def self.install_wizard(already_initialized = false)
42
+ CLIMessage::section_block('CONFIGURING DROPBOX UPLOADER...') do
43
+ # Prompt the user for a location to save Dropbox Uploader. '
44
+ path = CLIMessage::prompt('Location for Dropbox-Uploader', already_initialized ? Configuration['db_uploader']['base_filepath'] : DBU_LOCAL_FILEPATH)
45
+ path.chop! if path.end_with?('/')
43
46
 
44
- CLIMessage.section_block('CONFIGURING DROPBOX UPLOADER...') do
45
- until valid_directory_chosen
46
- # Prompt the user for a location to save Dropbox Uploader. '
47
- path = CLIMessage.prompt('Location for Dropbox-Uploader', DBU_LOCAL_FILEPATH)
48
- path.chop! if path.end_with?('/')
49
- path = '/usr/local/opt' if path.empty?
47
+ # If the entered directory exists, clone the repository.
48
+ if File.directory?(path)
49
+ dbu_path = File.join(path, 'Dropbox-Uploader')
50
+ executable_path = File.join(dbu_path, 'dropbox_uploader.sh')
50
51
 
51
- # If the entered directory exists, clone the repository.
52
- if File.directory?(path)
53
- valid_directory_chosen = true
54
- path << '/Dropbox-Uploader'
55
-
56
- if File.directory?(path)
57
- CLIMessage.warning("Using pre-existing Dropbox Uploader at #{ path }...")
58
- else
59
- CLIMessage.info_block("Downloading Dropbox Uploader to #{ path }...", 'Done.', true) do
60
- system "git clone https://github.com/andreafabrizi/Dropbox-Uploader.git #{ path }"
61
- end
52
+ if File.directory?(dbu_path)
53
+ CLIMessage::warning("Using pre-existing Dropbox Uploader at #{ dbu_path }...")
54
+ else
55
+ CLIMessage::info_block("Downloading Dropbox Uploader to #{ dbu_path }...", 'Done.', true) do
56
+ system "git clone https://github.com/andreafabrizi/Dropbox-Uploader.git #{ dbu_path }"
62
57
  end
58
+ end
63
59
 
64
- # If the user has never configured Dropbox Uploader, have them do it here.
65
- CLIMessage.info_block('Initializing Dropbox Uploader...') { system "#{ File.join(path, 'dropbox_uploader.sh') }" } unless File.exists?(CONFIG_FILEPATH)
60
+ # If the user has never configured Dropbox Uploader, have them do it here.
61
+ CLIMessage::info_block('Initializing Dropbox Uploader...') { system "#{ executable_path }" } unless File.exists?(CONFIG_FILEPATH)
66
62
 
67
- Configuration.add_section('db_uploader')
68
- Configuration['db_uploader'].merge!('local_filepath' => path)
69
- else
70
- puts "Sorry, but #{ path } isn't a valid directory."
71
- end
63
+ Configuration::add_section('db_uploader') unless Configuration::section_exists?('db_uploader')
64
+ Configuration['db_uploader'].merge!('base_filepath' => path, 'dbu_filepath' => dbu_path, 'exe_filepath' => executable_path)
65
+ else
66
+ CLIMessage::error("Sorry, but #{ path } isn't a valid directory.")
72
67
  end
73
68
  end
74
69
  end
@@ -129,7 +124,7 @@ module SifttterRedux
129
124
  # ----------------------------------------------------
130
125
  def self.upload
131
126
  if !@local_path.nil? && !@remote_path.nil?
132
- CLIMessage.info_block(@message ||= DEFAULT_MESSAGE, 'Done.', SifttterRedux.verbose) do
127
+ CLIMessage::info_block(@message ||= DEFAULT_MESSAGE, 'Done.', SifttterRedux.verbose) do
133
128
  if SifttterRedux.verbose
134
129
  system "#{ @dbu } upload #{ @local_path } #{ @remote_path }"
135
130
  else
@@ -77,7 +77,7 @@ module SifttterRedux
77
77
  end
78
78
 
79
79
  if projects.length <=0
80
- CLIMessage.warning('No entries found...')
80
+ CLIMessage::warning('No entries found...')
81
81
  end
82
82
 
83
83
  if projects.length > 0
@@ -91,7 +91,7 @@ module SifttterRedux
91
91
  fh = File.new(File.expand_path(Configuration['sifttter_redux']['dayone_local_filepath'] + '/' + uuid + '.doentry'), 'w+')
92
92
  fh.puts template.result(binding)
93
93
  fh.close
94
- CLIMessage.success("Entry logged for #{ date_for_title }...")
94
+ CLIMessage::success("Entry logged for #{ date_for_title }...")
95
95
  end
96
96
  end
97
97
  end
@@ -10,7 +10,7 @@ class String
10
10
  # @return Void
11
11
  # ----------------------------------------------------
12
12
  def colorize(color_code)
13
- "\e[#{color_code}m#{self}\e[0m"
13
+ "\e[#{ color_code }m#{ self }\e[0m"
14
14
  end
15
15
 
16
16
  # ----------------------------------------------------
@@ -1,3 +1,4 @@
1
1
  module SifttterRedux
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
+ NEWEST_CONFIG_VERSION = '0.4.1'
3
4
  end
@@ -34,53 +34,52 @@ module SifttterRedux
34
34
  # collecting all necessary items and info.
35
35
  # @return Void
36
36
  # ----------------------------------------------------
37
- def self.init
37
+ def self.init(already_initialized = false)
38
38
  # Re-initialize the configuration data.
39
- Configuration.reset
40
- Configuration.add_section('sifttter_redux')
41
- Configuration['sifttter_redux'].merge!('config_location' => Configuration.config_path)
39
+ Configuration::add_section('sifttter_redux') unless Configuration::section_exists?('sifttter_redux')
40
+ Configuration['sifttter_redux'].merge!('version' => VERSION, 'config_location' => Configuration::config_path)
42
41
 
43
42
  # Run the wizard to download Dropbox Uploader.
44
- DBU::install_wizard
43
+ DBU::install_wizard(already_initialized = already_initialized)
45
44
 
46
45
  # Collect other misc. preferences.
47
- CLIMessage.section_block('COLLECTING PREFERENCES...') do
46
+ CLIMessage::section_block('COLLECTING PREFERENCES...') do
48
47
  pref_prompts = [
49
48
  {
50
49
  prompt: 'Location for downloaded Sifttter files from Dropbox',
51
- default: SFT_LOCAL_FILEPATH,
50
+ default: already_initialized ? Configuration['sifttter_redux']['sifttter_local_filepath'] : SFT_LOCAL_FILEPATH,
52
51
  key: 'sifttter_local_filepath',
53
52
  section: 'sifttter_redux'
54
53
  },
55
54
  {
56
55
  prompt: 'Location of Sifttter files in Dropbox',
57
- default: SFT_REMOTE_FILEPATH,
56
+ default: already_initialized ? Configuration['sifttter_redux']['sifttter_remote_filepath'] : SFT_REMOTE_FILEPATH,
58
57
  key: 'sifttter_remote_filepath',
59
58
  section: 'sifttter_redux'
60
59
  },
61
60
  {
62
61
  prompt: 'Location for downloaded Day One files from Dropbox',
63
- default: DO_LOCAL_FILEPATH,
62
+ default: already_initialized ? Configuration['sifttter_redux']['dayone_local_filepath'] : DO_LOCAL_FILEPATH,
64
63
  key: 'dayone_local_filepath',
65
64
  section: 'sifttter_redux'
66
65
  },
67
66
  {
68
67
  prompt: 'Location of Day One files in Dropbox',
69
- default: DO_REMOTE_FILEPATH,
68
+ default: already_initialized ? Configuration['sifttter_redux']['dayone_remote_filepath'] : DO_REMOTE_FILEPATH,
70
69
  key: 'dayone_remote_filepath',
71
70
  section: 'sifttter_redux'
72
71
  }
73
72
  ]
74
73
 
75
74
  pref_prompts.each do |prompt|
76
- pref = CLIMessage.prompt(prompt[:prompt], prompt[:default])
75
+ pref = CLIMessage::prompt(prompt[:prompt], prompt[:default])
77
76
  Configuration[prompt[:section]].merge!(prompt[:key] => pref)
78
77
  end
79
78
  end
80
79
 
81
- Methadone::CLILogging.info("Configuration values: #{ Configuration.dump }")
80
+ Methadone::CLILogging.info("Configuration values: #{ Configuration::dump }")
82
81
 
83
- Configuration.save
82
+ Configuration::save
84
83
  end
85
84
 
86
85
  # ----------------------------------------------------
@@ -6,50 +6,62 @@ include Methadone::CLILogging
6
6
 
7
7
  class CLIMessageTest < Test::Unit::TestCase
8
8
  def test_error_message
9
- assert_output('---> ERROR: test'.red + "\n") { SifttterRedux::CLIMessage.error('test', false) }
9
+ assert_output('---> ERROR: test'.red + "\n") { SifttterRedux::CLIMessage::error('test', false) }
10
10
  end
11
11
 
12
12
  def test_info_message
13
- assert_output('---> INFO: test'.blue + "\n") { SifttterRedux::CLIMessage.info('test', false) }
13
+ assert_output('---> INFO: test'.blue + "\n") { SifttterRedux::CLIMessage::info('test', false) }
14
14
  end
15
15
 
16
16
  def test_info_block_single_line
17
17
  assert_output("---> INFO: start".blue + "body\n" + 'end'.blue + "\n") do
18
- SifttterRedux::CLIMessage.info_block('start', 'end', false, false) { puts 'body' }
18
+ SifttterRedux::CLIMessage::info_block('start', 'end', false, false) { puts 'body' }
19
19
  end
20
20
  end
21
21
 
22
22
  def test_info_block_multiline
23
23
  assert_output("---> INFO: start".blue + "\nbody\n" + '---> INFO: end'.blue + "\n") do
24
- SifttterRedux::CLIMessage.info_block('start', 'end', true, false) { puts 'body' }
24
+ SifttterRedux::CLIMessage::info_block('start', 'end', true, false) { puts 'body' }
25
25
  end
26
26
  end
27
27
 
28
28
  def test_info_block_no_block
29
29
  assert_raise ArgumentError do
30
- SifttterRedux::CLIMessage.info_block('start', 'end', true, false)
30
+ SifttterRedux::CLIMessage::info_block('start', 'end', true, false)
31
31
  end
32
32
  end
33
33
 
34
- # def test_prompt
35
- # assert_equal(SifttterRedux::CLIMessage.prompt('Pick the default option', 'default'), 'default')
36
- # end
37
-
38
34
  def test_section_message
39
- assert_output('#### test'.purple + "\n") { SifttterRedux::CLIMessage.section('test', false) }
35
+ assert_output('#### test'.purple + "\n") { SifttterRedux::CLIMessage::section('test', false) }
40
36
  end
41
37
 
42
38
  def test_section_block_single_line
43
39
  assert_output("#### section".purple + "\nbody\n") do
44
- SifttterRedux::CLIMessage.section_block('section', true, false) { puts 'body' }
40
+ SifttterRedux::CLIMessage::section_block('section', true, false) { puts 'body' }
45
41
  end
46
42
  end
47
43
 
48
44
  def test_success_message
49
- assert_output('---> SUCCESS: test'.green + "\n") { SifttterRedux::CLIMessage.success('test', false) }
45
+ assert_output('---> SUCCESS: test'.green + "\n") { SifttterRedux::CLIMessage::success('test', false) }
50
46
  end
51
47
 
52
48
  def test_warning_message
53
- assert_output('---> WARNING: test'.yellow + "\n") { SifttterRedux::CLIMessage.warning('test', false) }
49
+ assert_output('---> WARNING: test'.yellow + "\n") { SifttterRedux::CLIMessage::warning('test', false) }
50
+ end
51
+
52
+ def test_prompt
53
+ with_stdin do |answer|
54
+ answer.puts 'default'
55
+ assert_equal(SifttterRedux::CLIMessage::prompt('Hit enter to give the default response', 'default'), 'default')
56
+ end
57
+ end
58
+
59
+ def with_stdin
60
+ stdin = $stdin # remember $stdin
61
+ $stdin, write = IO.pipe # create pipe assigning its "read end" to $stdin
62
+ yield write # pass pipe's "write end" to block
63
+ ensure
64
+ write.close # close pipe
65
+ $stdin = stdin # restore $stdin
54
66
  end
55
67
  end
@@ -4,7 +4,7 @@ require File.join(File.dirname(__FILE__), '..', 'lib/sifttter_redux/configuratio
4
4
  class ConfigurationTest < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
- SifttterRedux::Configuration.load('/tmp/srd_config')
7
+ SifttterRedux::Configuration::load('/tmp/srd_config')
8
8
  end
9
9
 
10
10
  def teardown
@@ -12,57 +12,57 @@ class ConfigurationTest < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_add_data
15
- SifttterRedux::Configuration.add_section('section1')
15
+ SifttterRedux::Configuration::add_section('section1')
16
16
  SifttterRedux::Configuration['section1'] = { 'a' => 'test', 'b' => 'test' }
17
- assert_equal(SifttterRedux::Configuration.dump, { 'section1' => { 'a' => 'test', 'b' => 'test' } })
17
+ assert_equal(SifttterRedux::Configuration::dump, { 'section1' => { 'a' => 'test', 'b' => 'test' } })
18
18
 
19
19
  SifttterRedux::Configuration['section1']['a'] = 'bigger test'
20
20
  SifttterRedux::Configuration['section1']['c'] = 'little test'
21
- assert_equal(SifttterRedux::Configuration.dump, { 'section1' => { 'a' => 'bigger test', 'b' => 'test', 'c' => 'little test' } })
21
+ assert_equal(SifttterRedux::Configuration::dump, { 'section1' => { 'a' => 'bigger test', 'b' => 'test', 'c' => 'little test' } })
22
22
  end
23
23
 
24
24
  def test_add_section
25
- SifttterRedux::Configuration.add_section('section1')
26
- SifttterRedux::Configuration.add_section('section2')
27
- assert_equal(SifttterRedux::Configuration.dump, { 'section1' => {}, 'section2' => {} })
25
+ SifttterRedux::Configuration::add_section('section1')
26
+ SifttterRedux::Configuration::add_section('section2')
27
+ assert_equal(SifttterRedux::Configuration::dump, { 'section1' => {}, 'section2' => {} })
28
28
  end
29
29
 
30
30
  def test_add_section_duplicate
31
- SifttterRedux::Configuration.add_section('section1')
32
- SifttterRedux::Configuration.add_section('section2')
33
- SifttterRedux::Configuration.add_section('section2')
34
- assert_equal(SifttterRedux::Configuration.dump, { 'section1' => {}, 'section2' => {} })
31
+ SifttterRedux::Configuration::add_section('section1')
32
+ SifttterRedux::Configuration::add_section('section2')
33
+ SifttterRedux::Configuration::add_section('section2')
34
+ assert_equal(SifttterRedux::Configuration::dump, { 'section1' => {}, 'section2' => {} })
35
35
  end
36
36
 
37
37
  def test_config_path
38
- assert_equal(SifttterRedux::Configuration.config_path, '/tmp/srd_config')
38
+ assert_equal(SifttterRedux::Configuration::config_path, '/tmp/srd_config')
39
39
  end
40
40
 
41
41
  def test_delete_section
42
- SifttterRedux::Configuration.add_section('section1')
43
- SifttterRedux::Configuration.add_section('section2')
44
- SifttterRedux::Configuration.delete_section('section2')
45
- assert_equal(SifttterRedux::Configuration.dump, { 'section1' => {} })
42
+ SifttterRedux::Configuration::add_section('section1')
43
+ SifttterRedux::Configuration::add_section('section2')
44
+ SifttterRedux::Configuration::delete_section('section2')
45
+ assert_equal(SifttterRedux::Configuration::dump, { 'section1' => {} })
46
46
  end
47
47
 
48
48
  def test_delete_section_nonexistant
49
- SifttterRedux::Configuration.add_section('section1')
50
- SifttterRedux::Configuration.delete_section('section12723762323')
51
- assert_equal(SifttterRedux::Configuration.dump, { 'section1' => {} })
49
+ SifttterRedux::Configuration::add_section('section1')
50
+ SifttterRedux::Configuration::delete_section('section12723762323')
51
+ assert_equal(SifttterRedux::Configuration::dump, { 'section1' => {} })
52
52
  end
53
53
 
54
54
  def test_reset
55
- SifttterRedux::Configuration.add_section('section1')
56
- SifttterRedux::Configuration.add_section('section2')
57
- SifttterRedux::Configuration.add_section('section3')
58
- SifttterRedux::Configuration.reset
59
- assert_equal(SifttterRedux::Configuration.dump, {})
55
+ SifttterRedux::Configuration::add_section('section1')
56
+ SifttterRedux::Configuration::add_section('section2')
57
+ SifttterRedux::Configuration::add_section('section3')
58
+ SifttterRedux::Configuration::reset
59
+ assert_equal(SifttterRedux::Configuration::dump, {})
60
60
  end
61
61
 
62
62
  def test_save
63
- SifttterRedux::Configuration.add_section('section1')
63
+ SifttterRedux::Configuration::add_section('section1')
64
64
  SifttterRedux::Configuration['section1'] = { 'a' => 'test', 'b' => 'test' }
65
- SifttterRedux::Configuration.save
65
+ SifttterRedux::Configuration::save
66
66
 
67
67
  File.open('/tmp/srd_config', 'r') do |f|
68
68
  assert_output("---\nsection1:\n a: test\n b: test\n") { puts f.read }
@@ -70,7 +70,7 @@ class ConfigurationTest < Test::Unit::TestCase
70
70
  end
71
71
 
72
72
  def test_section_exists
73
- SifttterRedux::Configuration.add_section('section1')
74
- assert_equal(SifttterRedux::Configuration.section_exists?('section1'), true)
73
+ SifttterRedux::Configuration::add_section('section1')
74
+ assert_equal(SifttterRedux::Configuration::section_exists?('section1'), true)
75
75
  end
76
76
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sifttter-redux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Bach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-26 00:00:00.000000000 Z
11
+ date: 2014-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake