sprout 1.1.3.pre → 1.1.4.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sprout might be problematic. Click here for more details.

data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.3.pre
1
+ 1.1.4.pre
data/lib/sprout/daemon.rb CHANGED
@@ -193,6 +193,7 @@ module Sprout
193
193
 
194
194
  def wait
195
195
  Process.wait process_runner.pid
196
+ rescue Errno::ECHILD
196
197
  end
197
198
 
198
199
  ##
@@ -58,11 +58,16 @@ module Sprout
58
58
  @hidden_value = true
59
59
  end
60
60
 
61
+ def default_option_parser_declaration
62
+ return [prefix, '[no-]', option_parser_name] if default == true
63
+ super
64
+ end
65
+
61
66
  ##
62
- # Convert string representations of truthiness
63
- # to something more Booley.
67
+ # Convert string representations of falsiness
68
+ # to something more Booleaney.
64
69
  def value=(value)
65
- value = (value == "true" || value === true) ? true : false
70
+ value = (value == "false" || value == false) ? false : true
66
71
  super value
67
72
  end
68
73
 
@@ -318,7 +318,7 @@ module Sprout
318
318
  # How this parameter is provided to the
319
319
  # Ruby OptionParser when being exposed as a Ruby Executable.
320
320
  def option_parser_declaration
321
- declaration = [ prefix, option_parser_name ]
321
+ declaration = default_option_parser_declaration
322
322
  # TODO: Need to figure out how to support hidden name inputs...
323
323
  #if(hidden_name?)
324
324
  #declaration = [option_parser_type_output]
@@ -329,6 +329,10 @@ module Sprout
329
329
  declaration.join('')
330
330
  end
331
331
 
332
+ def default_option_parser_declaration
333
+ [ prefix, option_parser_name ]
334
+ end
335
+
332
336
  ##
333
337
  # The Ruby OptionParser short name with prefix.
334
338
  def option_parser_short_name
@@ -34,7 +34,7 @@ module Sprout::Generator
34
34
  end
35
35
 
36
36
  def file path, template=nil
37
- raise sprout::errors::generatorerror.new "Cannot create file with nil path" if path.nil?
37
+ raise Sprout::Errors::GeneratorError.new "Cannot create file with nil path" if path.nil?
38
38
  manifest = FileManifest.new
39
39
  manifest.generator = @generator
40
40
  manifest.path = File.join( working_dir.path, path )
@@ -44,7 +44,7 @@ module Sprout::Generator
44
44
  end
45
45
 
46
46
  def generator name, options={}
47
- raise sprout::errors::generatorerror.new "Cannot call another generator with nil name" if name.nil?
47
+ raise Sprout::Errors::GeneratorError.new "Cannot call another generator with nil name" if name.nil?
48
48
  instance = Sprout::Generator.create_instance name, options
49
49
  instance.logger = logger
50
50
  instance.path = working_dir.path
@@ -12,9 +12,9 @@ module Sprout::Generator
12
12
  def create
13
13
  if !File.directory?(path)
14
14
  FileUtils.mkdir_p path
15
- say "Created directory: #{path}"
15
+ say "Created directory: #{path}"
16
16
  else
17
- say "Skipped existing: #{path}" unless(path == Dir.pwd)
17
+ say "Skipped directory: #{path}" unless(path == Dir.pwd)
18
18
  end
19
19
  create_children
20
20
  execute_generators
@@ -26,10 +26,10 @@ module Sprout::Generator
26
26
 
27
27
  if success && can_remove?
28
28
  FileUtils.rmdir path
29
- say "Removed directory: #{path}"
29
+ say "Removed directory: #{path}"
30
30
  true
31
31
  else
32
- say "Skipped remove directory: #{path}"
32
+ say "Skipped remove directory: #{path}"
33
33
  false
34
34
  end
35
35
  end
@@ -6,12 +6,21 @@ module Sprout::Generator
6
6
 
7
7
  def create
8
8
  content = resolve_template
9
-
10
- File.open path, 'w+' do |file|
11
- file.write content
9
+
10
+ if File.exists?(path)
11
+ if generator.force
12
+ write_file path, content
13
+ say "Replaced file: #{path}"
14
+ true
15
+ else
16
+ say "Skipped file: #{path}"
17
+ false
18
+ end
19
+ else
20
+ write_file path, content
21
+ say "Created file: #{path}"
22
+ true
12
23
  end
13
- say "Created file: #{path}"
14
- true
15
24
  end
16
25
 
17
26
  def destroy
@@ -23,16 +32,22 @@ module Sprout::Generator
23
32
  actual_content = File.read path
24
33
  if generator.force || actual_content == expected_content
25
34
  FileUtils.rm path
26
- say "Removed file: #{path}"
35
+ say "Removed file: #{path}"
27
36
  true
28
37
  else
29
- say "Skipped remove file: #{path}"
38
+ say "Skipped remove file: #{path}"
30
39
  false
31
40
  end
32
41
  end
33
42
 
34
43
  protected
35
44
 
45
+ def write_file path, content
46
+ File.open path, 'w+' do |file|
47
+ file.write content
48
+ end
49
+ end
50
+
36
51
  def resolve_template
37
52
  read_source
38
53
  end
@@ -5,8 +5,7 @@ module Sprout::Generator
5
5
  protected
6
6
 
7
7
  def resolve_template
8
- template_content = read_source
9
- generator.resolve_template template_content
8
+ generator.resolve_template read_source
10
9
  end
11
10
  end
12
11
  end
@@ -14,6 +14,10 @@ class EchoInputs < Sprout::Executable::Base
14
14
  #
15
15
  add_param :truthy, Boolean
16
16
 
17
+ add_param :long_truthy, Boolean
18
+
19
+ add_param :default_truthy, Boolean, { :default => true }
20
+
17
21
  ##
18
22
  # A boolean parameter that defaults to true, and must be
19
23
  # explicitly set to false in order to turn it off.
@@ -0,0 +1,4 @@
1
+
2
+ @echo off
3
+ ruby test\fixtures\executable\flex3sdk_gem\fdb
4
+
@@ -30,7 +30,12 @@ class BooleanParamTest < Test::Unit::TestCase
30
30
  @param.show_on_false = true
31
31
  @param.default = true
32
32
  @param.hidden_value = false
33
- assert_equal "--foo [BOOL]", @param.option_parser_declaration
33
+ assert_equal "--[no-]foo [BOOL]", @param.option_parser_declaration
34
+ end
35
+
36
+ should "not insert [no] param modifier unless default true" do
37
+ @param.name = 'something_off'
38
+ assert_equal "--something-off", @param.option_parser_declaration
34
39
  end
35
40
  end
36
41
  end
@@ -61,7 +61,7 @@ class DaemonTest < Test::Unit::TestCase
61
61
  @fdb.quit
62
62
  @fdb.wait # wait for actions to finish.
63
63
 
64
- assert_equal "This is an error!\nThis is more details about the error!\nHere are even more details!\n", Sprout.stderr.read
64
+ assert_matches /This is an error!/, Sprout.stderr.read
65
65
  end
66
66
 
67
67
  should "execute from rake task" do
@@ -28,6 +28,18 @@ class ExecutableOptionParserTest < Test::Unit::TestCase
28
28
  @exe.parse! [ '--truthy', @default_input ]
29
29
  assert @exe.truthy
30
30
  end
31
+
32
+ should "accept long boolean with hidden_value" do
33
+ assert !@exe.long_truthy
34
+ @exe.parse! [ '--long-truthy', @default_input ]
35
+ assert @exe.long_truthy
36
+ end
37
+
38
+ should "accept negative truthy" do
39
+ assert @exe.default_truthy, "Should default true"
40
+ @exe.parse! [ '--no-default-truthy', @default_input ]
41
+ assert !@exe.default_truthy, "Should accept no- prefix"
42
+ end
31
43
 
32
44
  should "always accept help option" do
33
45
  @exe.expects :puts
@@ -58,6 +58,29 @@ class GeneratorTest < Test::Unit::TestCase
58
58
  end
59
59
  end
60
60
 
61
+ should "not clobber existing files" do
62
+ dir = File.join(@fixture, 'some_project', 'src')
63
+ FileUtils.mkdir_p dir
64
+ File.open File.join(dir, 'SomeProject.as'), 'w+' do |f|
65
+ f.write "Hello World"
66
+ end
67
+ @generator.input = 'some_project'
68
+ @generator.execute
69
+ assert_matches /Hello World/, File.read(File.join(dir, 'SomeProject.as'))
70
+ end
71
+
72
+ should "clobber existing files if --force" do
73
+ dir = File.join(@fixture, 'some_project', 'src')
74
+ FileUtils.mkdir_p dir
75
+ File.open File.join(dir, 'SomeProject.as'), 'w+' do |f|
76
+ f.write "Hello World"
77
+ end
78
+ @generator.input = 'some_project'
79
+ @generator.force = true
80
+ @generator.execute
81
+ assert_matches /public function SomeProject/, File.read(File.join(dir, 'SomeProject.as'))
82
+ end
83
+
61
84
  should "call another generator" do
62
85
  @generator.external = true
63
86
  @generator.execute
@@ -78,6 +101,7 @@ class GeneratorTest < Test::Unit::TestCase
78
101
  should "respect updates from subclasses" do
79
102
  @generator = configure_generator SubclassedGenerator.new
80
103
  @generator.input = 'some_project'
104
+ @generator.force = true
81
105
  @generator.execute
82
106
  assert_file File.join(@fixture, 'some_project', 'SomeFile') do |content|
83
107
  assert_matches /Living Jest enough for the City and SomeProject/, content
@@ -103,7 +127,7 @@ class GeneratorTest < Test::Unit::TestCase
103
127
 
104
128
  should "notify user of all files created" do
105
129
  @generator.input = 'some_project'
106
- @string_io.expects(:puts).with('Skipped existing: .')
130
+ @string_io.expects(:puts).with('Skipped directory: .')
107
131
  @string_io.expects(:puts).with('Created directory: ./some_project')
108
132
  @string_io.expects(:puts).with('Created file: ./some_project/SomeFile')
109
133
  @string_io.expects(:puts).with('Created file: ./some_project/SomeOtherFile')
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 1
8
- - 3
8
+ - 4
9
9
  - pre
10
- version: 1.1.3.pre
10
+ version: 1.1.4.pre
11
11
  platform: ruby
12
12
  authors:
13
13
  - Luke Bayes
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-29 00:00:00 -08:00
18
+ date: 2010-12-31 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -302,6 +302,7 @@ files:
302
302
  - test/fixtures/executable/echochamber_gem/echo_chamber.rb
303
303
  - test/fixtures/executable/fdb.rb
304
304
  - test/fixtures/executable/flex3sdk_gem/fdb
305
+ - test/fixtures/executable/flex3sdk_gem/fdb.bat
305
306
  - test/fixtures/executable/flex3sdk_gem/flex3sdk.rb
306
307
  - test/fixtures/executable/flex3sdk_gem/mxmlc
307
308
  - test/fixtures/executable/flex3sdk_gem/mxmlc.bat