pineapples 0.3.34 → 0.3.345

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/bin/pineapples +13 -13
  3. data/lib/pineapples.rb +3 -1
  4. data/lib/pineapples/actions.rb +6 -0
  5. data/lib/pineapples/actions/base/target.rb +41 -91
  6. data/lib/pineapples/actions/bundle.rb +16 -0
  7. data/lib/pineapples/actions/chmod.rb +3 -2
  8. data/lib/pineapples/actions/copy_file.rb +1 -1
  9. data/lib/pineapples/actions/empty_directory.rb +1 -1
  10. data/lib/pineapples/actions/gsub_file.rb +5 -3
  11. data/lib/pineapples/actions/inside.rb +5 -1
  12. data/lib/pineapples/actions/rails/erb_converters.rb +11 -4
  13. data/lib/pineapples/actions/rails/new_hash_syntax_converter.rb +36 -0
  14. data/lib/pineapples/actions/rails/rails.rb +1 -0
  15. data/lib/pineapples/actions/remove_file.rb +28 -28
  16. data/lib/pineapples/actions/shell.rb +43 -9
  17. data/lib/pineapples/app_generator.rb +154 -38
  18. data/lib/pineapples/helpers.rb +31 -0
  19. data/lib/pineapples/parser.rb +42 -37
  20. data/lib/pineapples/setting.rb +155 -155
  21. data/lib/pineapples/settings.rb +31 -31
  22. data/lib/pineapples/templates/.example.env.tt +15 -0
  23. data/lib/pineapples/templates/.gitignore +3 -0
  24. data/lib/pineapples/templates/.simplecov.tt +11 -0
  25. data/lib/pineapples/templates/Gemfile.tt +23 -5
  26. data/lib/pineapples/templates/Procfile +1 -1
  27. data/lib/pineapples/templates/Procfile.dev.tt +2 -0
  28. data/lib/pineapples/templates/app/assets/javascripts/libs.js +4 -2
  29. data/lib/pineapples/templates/app/assets/stylesheets/application.scss +4 -1
  30. data/lib/pineapples/templates/app/controllers/application_controller.rb.tt +0 -2
  31. data/lib/pineapples/templates/app/controllers/auth!=devise!/confirmations_controller.rb +11 -0
  32. data/lib/pineapples/templates/app/controllers/auth!=devise!/passwords_controller.rb.tt +12 -0
  33. data/lib/pineapples/templates/app/controllers/auth!=devise!/registrations_controller.rb.tt +25 -0
  34. data/lib/pineapples/templates/app/controllers/auth!=devise!/sessions_controller.rb.tt +59 -0
  35. data/lib/pineapples/templates/app/models/user!=needs_user_model!.rb.tt +7 -4
  36. data/lib/pineapples/templates/app/policies!=pundit!/application_policy.rb +49 -0
  37. data/lib/pineapples/templates/app/presenters/base_presenter.rb.tt +24 -0
  38. data/lib/pineapples/templates/app/responders/application_responder.rb +9 -0
  39. data/lib/pineapples/templates/app/services/service.rb +7 -0
  40. data/lib/pineapples/templates/app/views/common/_footer.html.erb +3 -3
  41. data/lib/pineapples/templates/app/views/common/_header.html.erb +5 -5
  42. data/lib/pineapples/templates/app/views/layouts/application.html.erb.tt +0 -1
  43. data/lib/pineapples/templates/app/views/pages/home.html.erb +0 -1
  44. data/lib/pineapples/templates/bin/nginx +4 -0
  45. data/lib/pineapples/templates/bin/rails +1 -0
  46. data/lib/pineapples/templates/bin/rspec +19 -0
  47. data/lib/pineapples/templates/bin/setup +111 -21
  48. data/lib/pineapples/templates/config.ru.tt +3 -0
  49. data/lib/pineapples/templates/config/application.rb.tt +3 -3
  50. data/lib/pineapples/templates/config/boot.rb +5 -5
  51. data/lib/pineapples/templates/config/database.yml.tt +1 -1
  52. data/lib/pineapples/templates/config/environments/{development.rb → development.rb.tt} +6 -1
  53. data/lib/pineapples/templates/config/environments/production.rb +1 -1
  54. data/lib/pineapples/templates/config/environments/test.rb +2 -2
  55. data/lib/pineapples/templates/config/i18n-tasks.yml +2 -0
  56. data/lib/pineapples/templates/config/initializers/{carrierwave.rb → carrierwave!=carrierwave!.rb} +22 -22
  57. data/lib/pineapples/templates/config/initializers/devise!=devise!.rb.tt +262 -0
  58. data/lib/pineapples/templates/config/initializers/kaminari.rb +10 -0
  59. data/lib/pineapples/templates/config/initializers/seed_migrations.rb +15 -0
  60. data/lib/pineapples/templates/config/initializers/simple_form.rb +165 -0
  61. data/lib/pineapples/templates/config/locales/devise.en.yml +60 -0
  62. data/lib/pineapples/templates/config/locales/{en.yml → en.yml.tt} +2 -0
  63. data/lib/pineapples/templates/config/locales/kaminari.en.yml +17 -0
  64. data/lib/pineapples/templates/config/locales/simple_form.en.yml +31 -0
  65. data/lib/pineapples/templates/config/nginx.conf.tt +147 -0
  66. data/lib/pineapples/templates/config/puma/development.rb.tt +27 -0
  67. data/lib/pineapples/templates/config/{puma.rb → puma/production.rb} +5 -5
  68. data/lib/pineapples/templates/config/routes.rb.tt +4 -0
  69. data/lib/pineapples/templates/config/spring.rb +4 -0
  70. data/lib/pineapples/templates/lib/devise!=devise!/{ajax_failure.rb → ajax_failure!=ajax_login!.rb} +0 -0
  71. data/lib/pineapples/templates/lib/logging/custom_rack_logger.rb +7 -9
  72. data/lib/pineapples/templates/lib/logging/custom_request_logger.rb +46 -48
  73. data/lib/pineapples/templates/lib/tasks/admin!=user_role_field!.rake +18 -19
  74. data/lib/pineapples/templates/lib/templates/{erb → erb!=erb!}/scaffold/_form.html.erb +0 -0
  75. data/lib/pineapples/templates/lib/templates/haml!=haml!/scaffold/_form.html.haml +9 -0
  76. data/lib/pineapples/templates/lib/templates/slim!=slim!/scaffold/_form.html.slim +9 -0
  77. data/lib/pineapples/templates/spec/i18n_spec.rb +17 -0
  78. data/lib/pineapples/templates/spec/rails_helper.rb +30 -0
  79. data/lib/pineapples/templates/spec/spec_helper.rb +44 -0
  80. data/lib/pineapples/templates/spec/support/capybara.rb +4 -0
  81. data/lib/pineapples/templates/spec/support/database_cleaner.rb +27 -0
  82. data/lib/pineapples/templates/spec/support/email_matchers.rb +17 -0
  83. data/lib/pineapples/templates/spec/support/factory_girl.rb +14 -0
  84. data/lib/pineapples/templates/spec/support/job_helpers.rb +8 -0
  85. data/lib/pineapples/templates/spec/support/matchers.rb +10 -0
  86. data/lib/pineapples/templates/spec/support/rake_tasks.rb +8 -0
  87. data/lib/pineapples/templates/spec/support/shoulda_matchers.rb +24 -0
  88. data/lib/pineapples/version.rb +2 -2
  89. data/pineapples.gemspec +1 -3
  90. metadata +46 -12
  91. data/lib/pineapples/app_builder.rb +0 -70
  92. data/lib/pineapples/build_tasks/root_files.rb +0 -23
  93. data/lib/pineapples/templates/app/controllers/auth/confirmations_controller.rb +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4168dcbfa92187c3d8bcf7b67f594cb7a3308067
4
- data.tar.gz: 9fd839446bd1602e213722deb11049aa9cd9c642
3
+ metadata.gz: 6f0f84c10a46a615eba4dfc22bf19092b18c9e2e
4
+ data.tar.gz: f5f427c5265408244a73c6369dc2a073b3dc3ade
5
5
  SHA512:
6
- metadata.gz: 92f8f1dfe6d724cc76085cd4cda7f55c0ba0bb03557292b156310b3613c5afbd70d75537abffc289c513a7280068ba4b2d1f9c3d152f276e8e84867be3279fb5
7
- data.tar.gz: fedbe56b5c2475020d96dabe94a904cf4b11ff6c41bf3994a98e3a7724b32ad0b9581d5b3a61613da04d4887f5976452ccf0ba41dba520d8297fba1a11b551dd
6
+ metadata.gz: 2b0c292b8573424558413899a0c3a70350eb9d3a35906c348d149b67690e85d2d8b376efecfc6db65219e9f432d8f864cc37e862f81fcab2c5fa71fe9ea797d2
7
+ data.tar.gz: 9926d77f2319243f47332624b82a8fda99595dc91f884bfe8f626903cf611f6704a5ac26ade0090ed84b6e0445aab8a156e298eebbf6f0f62fe608a6d0ca59b7
@@ -1,13 +1,13 @@
1
- #!/usr/bin/env ruby
2
- require 'pathname'
3
-
4
- source_path = (Pathname.new(__FILE__).dirname + '../lib').expand_path
5
- $LOAD_PATH << source_path
6
-
7
- require 'pineapples'
8
-
9
- $terminal.indent_size = 2
10
-
11
- options = Pineapples::Parser.parse(ARGV)
12
- generator = Pineapples::AppGenerator.new(options)
13
- generator.start!
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ source_path = (Pathname.new(__FILE__).dirname + '../lib').expand_path
5
+ $LOAD_PATH << source_path
6
+
7
+ require 'pineapples'
8
+
9
+ $terminal.indent_size = 2
10
+
11
+ options = Pineapples::Parser.parse(ARGV)
12
+ generator = Pineapples::AppGenerator.new(options)
13
+ generator.start!
@@ -5,12 +5,14 @@ require 'active_support/core_ext/object/blank'
5
5
  require 'active_support/core_ext/string/inflections'
6
6
 
7
7
  require 'English'
8
- #require 'erb'
9
8
  require 'fileutils'
10
9
  require 'ostruct'
10
+ require 'open3'
11
11
  require 'optparse'
12
12
  require 'pathname'
13
+ require 'pty'
13
14
  require 'securerandom'
15
+ require 'shellwords'
14
16
 
15
17
  require 'pineapples/version'
16
18
  require 'pineapples/error'
@@ -4,6 +4,7 @@ require 'uri'
4
4
  require 'pineapples/actions/base/action'
5
5
  require 'pineapples/actions/base/target'
6
6
  require 'pineapples/actions/apply'
7
+ require 'pineapples/actions/bundle'
7
8
  require 'pineapples/actions/chmod'
8
9
  require 'pineapples/actions/copy_file'
9
10
  require 'pineapples/actions/create_file'
@@ -114,6 +115,11 @@ module Pineapples
114
115
  say(output)
115
116
  end
116
117
 
118
+ def say_title(title)
119
+ puts
120
+ puts "== #{title} ==".light_yellow
121
+ end
122
+
117
123
  def indent(verbose = true, level_increment = 1)
118
124
  $terminal.indent_level += level_increment if verbose
119
125
  yield
@@ -1,134 +1,84 @@
1
1
  module Pineapples
2
2
  module Actions
3
3
  class Target
4
- PASS_MATCH = /!=(.*?)!/
5
- GUARD_MATCH = /!(.*?)!/
6
- EVAL_MATCH = /%(.*?)%/
4
+ PASS_REGEX = /!=(.*?)!/
5
+ GUARD_REGEX = /!(.*?)!/
6
+ FILENAME_REGEX = /%(.*?)%/
7
7
 
8
8
  attr_reader :given,
9
9
  :fullpath,
10
10
  :relative,
11
- :action
11
+ :generator
12
12
 
13
- def initialize(target, action)
13
+ def initialize(target, generator)
14
14
  raise Error, 'Target should not be falsy' if !target
15
15
 
16
- @action = action
16
+ @generator = generator
17
17
  @given = target.to_s
18
18
 
19
- evaluate_pass_method!
20
- evaluate_guard_methods!
21
- evaluate_filename_method!
19
+ match!
22
20
 
23
21
  @fullpath = File.expand_path(@given, generator.current_app_dir)
24
22
  @relative = generator.relative_to_current_app_dir(@fullpath)
25
23
  end
26
24
 
27
- def generator
28
- action.generator
29
- end
30
-
31
25
  def skip?
32
- @skip = false if @skip.nil?
33
26
  @skip
34
27
  end
35
28
 
36
29
  private
37
30
 
38
- def evaluate_pass_method!
39
- if pass_match
40
- raise Error, methods_missing_error_message(pass_methods) if !generator_pass_method
41
-
42
- @skip = !generator.send(generator_pass_method)
43
- @given.gsub!(pass_match[0], '')
44
- end
45
- end
46
-
47
- def evaluate_guard_methods!
48
- if guard_match
49
- raise Error, methods_missing_error_message(guard_methods) if !generator_guard_method
50
-
51
- @skip = generator.send(generator_guard_method)
52
- @given.gsub!(guard_match[0], '')
53
- end
54
- end
55
-
56
- def evaluate_filename_method!
57
- if eval_match
58
- raise Error, methods_missing_error_message(filename_method) if !generator_filename_method
59
-
60
- filename = generator.send(filename_method)
61
- @given.gsub!(eval_match[0], filename)
62
- end
63
- end
64
-
65
- def pass_match
66
- PASS_MATCH.match(@given)
67
- end
68
-
69
- def guard_match
70
- GUARD_MATCH.match(@given)
71
- end
72
-
73
- def eval_match
74
- EVAL_MATCH.match(@given)
75
- end
76
-
77
- def generator_pass_method
78
- if @pass_method.nil?
79
- pass_methods.each do |method|
80
- if generator.respond_to?(method, true)
81
- @pass_method = method
82
- break
31
+ def match!
32
+ loop do
33
+ matched = false
34
+ [:pass, :guard, :filename].each do |type|
35
+ if match(type)
36
+ send(:"evaluate_#{type}_method!")
37
+ matched = true and break
83
38
  end
84
39
  end
40
+ break if !matched || @skip
85
41
  end
86
- @pass_method = false if @pass_method.nil?
87
- @pass_method
88
42
  end
89
43
 
90
- def generator_guard_method
91
- if @guard_method.nil?
92
- guard_methods.each do |method|
93
- if generator.respond_to?(method, true)
94
- @guard_method = method
95
- break
96
- end
97
- end
98
- end
99
- @guard_method = false if @guard_method.nil?
100
- @guard_method
44
+ def evaluate_pass_method!
45
+ method = find_generator_method!(methods_to_find(:pass))
46
+ @skip = !generator.send(method)
47
+ @given.sub!(match(:pass)[0], '')
101
48
  end
102
49
 
103
- def generator_filename_method
104
- if @filename_method.nil?
105
- @filename_method = generator.respond_to?(filename_method, true) ? filename_method : false
106
- end
107
- @filename_method
50
+ def evaluate_guard_method!
51
+ method = find_generator_method!(methods_to_find(:guard))
52
+ @skip = generator.send(method)
53
+ @given.sub!(match(:guard)[0], '')
54
+ end
55
+
56
+ def evaluate_filename_method!
57
+ method = find_generator_method!(methods_to_find(:filename))
58
+ filename = generator.send(method)
59
+ @given.sub!(match(:filename)[0], filename)
108
60
  end
109
61
 
110
- def guard_methods
111
- guard_method = guard_match[1].strip
112
- predicate_method = guard_method + '?'
113
- [guard_method, predicate_method]
62
+ def match(type)
63
+ regexp = self.class.const_get(type.to_s.upcase + '_REGEX')
64
+ regexp.match(@given)
114
65
  end
115
66
 
116
- def pass_methods
117
- pass_method = pass_match[1].strip
118
- predicate_method = pass_method + '?'
119
- [pass_method, predicate_method]
67
+ def methods_to_find(type)
68
+ method = match(type)[1].strip
69
+ type == :filename ? method : [method, method + '?']
120
70
  end
121
71
 
122
- def filename_method
123
- eval_match[1].strip
72
+ def find_generator_method!(methods)
73
+ Array(methods).each { |method| return method if generator.respond_to?(method, true) }
74
+ raise Error, methods_missing_error_message(methods)
124
75
  end
125
76
 
126
77
  def methods_missing_error_message(methods)
127
- plural = methods.is_a?(Array)
128
- methods = methods.join(', ') if plural
129
- methods_message = plural ? 'methods' : 'method'
78
+ methods = Array(methods)
79
+ methods_message = methods.length > 1 ? 'methods' : 'method'
130
80
 
131
- "No instance #{methods_message} #{methods} for AppGenerator, can't evaluate filepath #{given}"
81
+ "No instance #{methods_message} #{methods.join(', ')} for AppGenerator, can't evaluate filepath #{given}"
132
82
  end
133
83
  end
134
84
 
@@ -0,0 +1,16 @@
1
+ module Pineapples
2
+ module Actions
3
+ def bundle(command, options = {})
4
+ command = "#{command.first.first} #{command.first.last}" if command.is_a?(Hash)
5
+ say_status :bundle, "#{command}"
6
+
7
+ _bundle_command = Gem.bin_path('bundler', 'bundle')
8
+
9
+ require 'bundler'
10
+ Bundler.with_clean_env do
11
+ output = `"#{Gem.ruby}" "#{_bundle_command}" #{command} #{subcommands}`
12
+ print output if !options[:quiet]
13
+ end
14
+ end
15
+ end
16
+ end
@@ -18,11 +18,12 @@ module Pineapples
18
18
  execute = !options.fetch(:pretend, pretend?)
19
19
  color = options.fetch(:color, DEFAULT_COLOR)
20
20
 
21
- relative_path = relative_to_app_root(File.join(app_root, path))
21
+ full_path = File.join(app_root, path)
22
+ relative_path = relative_to_app_root(full_path)
22
23
 
23
24
  say_status(:chmod, relative_path, color, verbose)
24
25
 
25
- FileUtils.chmod_R(mode, path) if execute
26
+ FileUtils.chmod_R(mode, full_path) if execute
26
27
  end
27
28
  end
28
29
  end
@@ -39,7 +39,7 @@ module Pineapples
39
39
  super
40
40
  if options[:mode] == :preserve
41
41
  mode = File.stat(source).mode
42
- generator.chmod(target, mode, options)
42
+ generator.chmod(target.fullpath, mode, options)
43
43
  end
44
44
  end
45
45
 
@@ -25,7 +25,7 @@ module Pineapples
25
25
  def initialize(generator, target, options = {})
26
26
  super(generator, options)
27
27
 
28
- @target = Target.new(target, self)
28
+ @target = Target.new(target, generator)
29
29
  @skip = @target.skip?
30
30
  end
31
31
 
@@ -23,13 +23,15 @@ module Pineapples
23
23
  verbose = options.fetch(:verbose, verbose?)
24
24
  execute = options.fetch(:pretend, execute?)
25
25
 
26
- path = File.expand_path(path, app_root)
26
+ fullpath = File.expand_path(path, app_root)
27
+ raise Error, "File #{path} doesn't exist!" if !File.exist?(fullpath)
28
+
27
29
  say_status :gsub, relative_to_app_root(path), :light_yellow, verbose
28
30
 
29
31
  if execute
30
- content = File.binread(path)
32
+ content = File.binread(fullpath)
31
33
  content.gsub!(flag, *args, &block)
32
- File.open(path, 'wb') { |file| file.write(content) }
34
+ File.open(fullpath, 'wb') { |file| file.write(content) }
33
35
  end
34
36
  end
35
37
  end
@@ -50,9 +50,13 @@ module Pineapples
50
50
  inside(:root, options) { yield }
51
51
  end
52
52
 
53
+ def in_app_root(&block)
54
+ Dir.chdir(app_root, &block)
55
+ end
56
+
53
57
  private
54
58
 
55
- # helper method to abstract directory stack management in the "inside" action
59
+ # helper method to abstract directory stack management in the #inside action
56
60
  def with_directory(dir)
57
61
  not_in_root = (dir != :root)
58
62
 
@@ -5,15 +5,20 @@ module Pineapples
5
5
  recursive = options.fetch(:recursive, true)
6
6
  verbose = options.fetch(:verbose, verbose?)
7
7
  execute = !options.fetch(:pretend, pretend?)
8
+ preserve = options.fetch(:keep_old_files, false)
8
9
 
9
10
  description = 'Convert ERB views to HAML'
10
- say_action(:erb2haml, description, verbose)
11
+ say_status(:erb2haml, description, verbose)
11
12
 
12
13
  if execute
13
14
  target_path = File.expand_path(target, app_root)
14
- target_path = File.join(target_path, recursive_mask) if recursive
15
+ target_path = File.join(target_path, '**') if recursive
15
16
  shell "find #{target_path} -name \\*.erb -print | sed 'p;s/.erb$/.haml/' | xargs -n2 html2haml",
16
17
  verbose: false
18
+ if !preserve
19
+ erb_pattern = File.join(target_path, '*.erb')
20
+ Dir.glob(erb_pattern).each { |file| ::FileUtils.rm_f(file) }
21
+ end
17
22
  end
18
23
  end
19
24
 
@@ -21,17 +26,19 @@ module Pineapples
21
26
  recursive = options.fetch(:recursive, true)
22
27
  verbose = options.fetch(:verbose, verbose?)
23
28
  execute = !options.fetch(:pretend, pretend?)
29
+ preserve = options.falsetch(:keep_old_files, false)
24
30
 
25
31
  description = 'Convert ERB views to SLIM'
26
- say_action(:erb2slim, description, verbose)
32
+ say_status(:erb2slim, description, verbose)
27
33
 
28
34
  if execute
29
35
  erb2haml(target, options)
30
36
  target_path = File.expand_path(target, app_root)
31
37
  target_path = File.join(target_path, '**') if recursive
32
- shell "haml2slim #{target_path} --delete --trace", verbose: false
38
+ shell "haml2slim #{target_path} #{preserve ? '' : '--delete'} --trace", verbose: false
33
39
  end
34
40
  end
41
+
35
42
  end
36
43
  end
37
44
  end
@@ -0,0 +1,36 @@
1
+ module Pineapples
2
+ module Actions
3
+ FILE_WITH_RUBY_CODE = '.rb|.erb|.haml|.slim|.rake'
4
+ def convert_directory_to_new_hash_syntax(target, options = {})
5
+ recursive = options.delete(:recursive) || true
6
+
7
+ target_fullpath = File.expand_path(target, app_root)
8
+ target_fullpath = File.join(target_fullpath, '**') if recursive
9
+
10
+ excluded_files = Array(options[:exclude])
11
+ exclude_pattern = options[:exclude_pattern]
12
+
13
+ files = Dir.glob(target_fullpath, File::FNM_DOTMATCH)
14
+ files.sort.each do |file|
15
+ next if File.directory?(file)
16
+ next if exclude_pattern && file.match(exclude_pattern)
17
+ next if excluded_files.any? do |excluded_file|
18
+ File.basename(excluded_file) == File.basename(file_source)
19
+ end
20
+
21
+ case file
22
+ when /#{FILE_WITH_RUBY_CODE}$/
23
+ convert_file_to_new_hash_syntax(file)
24
+ end
25
+ end
26
+
27
+ end
28
+ # Converts file to new Ruby hash syntax, cause that is what I prefer
29
+ # Existing solutions on web usually use perl and shell, but we have
30
+ # power of Ruby and cool gsub_file action at our disposal!
31
+ def convert_file_to_new_hash_syntax(path)
32
+ regex = /:(\w+)(\s{1})(\s*)=>/
33
+ gsub_file(path, regex, '\1:\3')
34
+ end
35
+ end
36
+ end
@@ -1,5 +1,6 @@
1
1
  require_relative 'erb_converters'
2
2
  require_relative 'copy_migration'
3
+ require_relative 'new_hash_syntax_converter'
3
4
 
4
5
  module Pineapples
5
6
  module Actions
@@ -1,28 +1,28 @@
1
- module Pineapples
2
- module Actions
3
- # Removes a file at the given location.
4
- #
5
- # ==== Parameters
6
- # path<String>:: path of the file to be changed
7
- # options<Hash>:: give :verbose => false to not log the status.
8
- #
9
- # ==== Example
10
- #
11
- # remove_file 'README'
12
- # remove_file 'app/controllers/application_controller.rb'
13
- #
14
- def remove_file(path, options = {})
15
- return unless behaviour == :invoke
16
- path = File.expand_path(path, destination_root)
17
-
18
- message = relative_to_app_root(path)
19
- verbose = options.fetch(:verbose, verbose?)
20
- color = options.fetch(:color, :light_red)
21
- execute = options[:pretend] || execute?
22
-
23
- say_status :remove, message, color, verbose
24
- ::FileUtils.rm_rf(path) if execute && File.exist?(path)
25
- end
26
- alias_method :remove_dir, :remove_file
27
- end
28
- end
1
+ module Pineapples
2
+ module Actions
3
+ # Removes a file at the given location.
4
+ #
5
+ # ==== Parameters
6
+ # path<String>:: path of the file to be changed
7
+ # options<Hash>:: give :verbose => false to not log the status.
8
+ #
9
+ # ==== Example
10
+ #
11
+ # remove_file 'README'
12
+ # remove_file 'app/controllers/application_controller.rb'
13
+ #
14
+ def remove_file(path, options = {})
15
+ return unless behaviour == :invoke
16
+ path = File.expand_path(path, app_root)
17
+
18
+ message = relative_to_app_root(path)
19
+ verbose = options.fetch(:verbose, verbose?)
20
+ color = options.fetch(:color, :light_red)
21
+ execute = options[:pretend] || execute?
22
+
23
+ say_status :remove, message, color, verbose
24
+ ::FileUtils.rm_rf(path) if execute && File.exist?(path)
25
+ end
26
+ alias_method :remove_dir, :remove_file
27
+ end
28
+ end