ronin-gen 1.1.1 → 1.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/.document CHANGED
@@ -2,3 +2,4 @@ lib/**/*.rb
2
2
  -
3
3
  ChangeLog.md
4
4
  COPYING.txt
5
+ man/ronin-gen.1.md
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  doc
2
2
  pkg
3
+ man/*.[1-9]
3
4
  vendor/cache
4
5
  Gemfile.lock
5
6
  .bundle
@@ -1,7 +1,30 @@
1
+ ### 1.2.0 / 2012-05-28
2
+
3
+ * Require ronin-support ~> 0.5.
4
+ * Require ronin ~> 1.5.
5
+ * Added {Ronin::Gen::Actions#print_command}.
6
+ * Added `ronin/spec/gen`.
7
+ * Added a man-page for `ronin-gen`.
8
+ * Moved all `FileUtils` methods into {Ronin::Gen::Actions}.
9
+ * Changed {Ronin::Gen::Generator.generate} to pass arbitrary arguments down to
10
+ {Ronin::Gen::Generator#initialize}.
11
+ * Overrode {Ronin::Gen::FileGenerator#initialize} to accept a `path` argument.
12
+ * Overrode {Ronin::Gen::DirGenerator#initialize} to accept a `path` argument.
13
+ * {Ronin::Gen::FileGenerator#path} is now an instance variable.
14
+ * {Ronin::Gen::DirGenerator#path} is now an instance variable.
15
+ * Improved the `ronin-gen` command:
16
+ * Properly set the `path` of File/Dir generators.
17
+ * Rescue and print exceptions.
18
+ * Include [rubygems-tasks] in generated ronin libraries.
19
+ * Simplified the `name.gemspec` template used by the
20
+ {Ronin::Gen::Generators::Library library} generator.
21
+ * Fixed typos in the `Gemfile` template used by the
22
+ {Ronin::Gen::Generators::Library library} generator.
23
+
1
24
  ### 1.1.1 / 2012-03-03
2
25
 
3
26
  * Fixed multiple typos in the Library and Repository templates.
4
- * Fixed a template lookup bug in {Ronin::Gen::Generator#template}.
27
+ * Fixed a template lookup bug in `Ronin::Gen::Generator#template`.
5
28
 
6
29
  ### 1.1.0 / 2012-02-12
7
30
 
@@ -98,3 +121,4 @@
98
121
  * Provides the `ronin-gen` sub-command to invoke other generator
99
122
  sub-commands.
100
123
 
124
+ [rubygems-tasks]: https://github.com/postmodern/rubygems-tasks#readme
data/Gemfile CHANGED
@@ -1,25 +1,26 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- DM_URI = 'http://github.com/datamapper'
4
- DM_VERSION = '~> 1.0.2'
5
- RONIN_URI = 'http://github.com/ronin-ruby'
3
+ DM_URI = 'http://github.com/datamapper'
4
+ DM_VERSION = '~> 1.2'
5
+ RONIN_URI = 'http://github.com/ronin-ruby'
6
6
 
7
7
  gemspec
8
8
 
9
- platforms :jruby do
10
- gem 'jruby-openssl', '~> 0.7.0'
11
- end
9
+ gem 'jruby-openssl', '~> 0.7', :platforms => :jruby
12
10
 
13
11
  # Ronin dependencies:
14
- # gem 'ronin-support', '~> 0.4.0.rc1', :git => "#{RONIN_URI}/ronin-support.git"
15
- # gem 'ronin', '~> 1.4.0.rc1', :git => "#{RONIN_URI}/ronin.git"
12
+ # gem 'ronin-support', '~> 0.5.0.rc1', :git => "#{RONIN_URI}/ronin-support.git",
13
+ # :branch => '0.5.0'
14
+ # gem 'ronin', '~> 1.5.0.rc1', :git => "#{RONIN_URI}/ronin.git",
15
+ # :branch => '1.5.0'
16
16
 
17
17
  group :development do
18
- gem 'rake', '~> 0.8'
19
- gem 'kramdown', '~> 0.12'
18
+ gem 'rake', '~> 0.8'
19
+ gem 'rubygems-tasks', '~> 0.1'
20
+ gem 'rspec', '~> 2.4'
20
21
 
21
- gem 'ore-tasks', '~> 0.4'
22
- gem 'rspec', '~> 2.4'
22
+ gem 'redcarpet', '~> 2.1'
23
+ gem 'md2man', '~> 1.2', :git => 'http://github.com/postmodern/md2man.git', :branch => 'rake_task'
23
24
  end
24
25
 
25
26
  #
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Ronin Gen
2
2
 
3
- * [Source](http://github.com/ronin-ruby/ronin-gen)
4
- * [Issues](http://github.com/ronin-ruby/ronin-gen/issues)
5
- * [Documentation](http://rubydoc.info/github/ronin-ruby/ronin-gen/frames)
3
+ * [Source](https://github.com/ronin-ruby/ronin-gen)
4
+ * [Issues](https://github.com/ronin-ruby/ronin-gen/issues)
5
+ * [Documentation](http://ronin-ruby.github.com/docs/ronin-gen/frames)
6
6
  * [Mailing List](http://groups.google.com/group/ronin-ruby)
7
7
  * [irc.freenode.net #ronin](http://webchat.freenode.net/?channels=ronin&uio=Mj10cnVldd)
8
8
 
@@ -20,7 +20,9 @@ or payloads over many common Source-Code-Management (SCM) systems.
20
20
  * Provides {Ronin::Gen::DirGenerator}
21
21
  * Provides {Ronin::Gen::SourceCodeGenerator}
22
22
  * Provides {Ronin::Gen::RubyGenerator}
23
- * Generators for creating new Ronin Repositories and Libraries.
23
+ * Generators for creating new Ronin
24
+ {Ronin::Gen::Generators::Repository Repositories} and
25
+ {Ronin::Gen::Generators::Library Libraries}.
24
26
 
25
27
  ## Synopsis
26
28
 
@@ -32,18 +34,22 @@ Generate a skeleton Overlay:
32
34
 
33
35
  $ ronin-gen repository PATH [options]
34
36
 
37
+ List available generators:
38
+
39
+ $ ronin-gen
40
+
35
41
  ## Requirements
36
42
 
37
- * [open_namespace](http://github.com/postmodern/open_namespace#readme)
43
+ * [open_namespace](https://github.com/postmodern/open_namespace#readme)
38
44
  ~> 0.3
39
- * [data_paths](http://github.com/postmodern/data_paths#readme)
45
+ * [data_paths](https://github.com/postmodern/data_paths#readme)
40
46
  ~> 0.3
41
- * [parameters](http://github.com/postmodern/parameters#readme)
42
- ~> 0.4
43
- * [ronin-support](http://github.com/ronin-ruby/ronin-support#readme)
47
+ * [parameters](https://github.com/postmodern/parameters#readme)
44
48
  ~> 0.4
45
- * [ronin](http://github.com/ronin-ruby/ronin#readme)
46
- ~> 1.4
49
+ * [ronin-support](https://github.com/ronin-ruby/ronin-support#readme)
50
+ ~> 0.5
51
+ * [ronin](https://github.com/ronin-ruby/ronin#readme)
52
+ ~> 1.5
47
53
 
48
54
  ## Install
49
55
 
data/Rakefile CHANGED
@@ -18,8 +18,16 @@ end
18
18
 
19
19
  require 'rake'
20
20
 
21
- require 'ore/tasks'
22
- Ore::Tasks.new
21
+ require 'rubygems/tasks'
22
+ Gem::Tasks.new(:sign => {:checksum => true, :pgp => true}) do |tasks|
23
+ tasks.scm.tag.format = 'v%s'
24
+ tasks.console.command = 'ripl'
25
+ tasks.console.options = %w[
26
+ -rripl/multi_line
27
+ -rripl/auto_indent
28
+ -rripl/color_result
29
+ ]
30
+ end
23
31
 
24
32
  require 'rspec/core/rake_task'
25
33
  RSpec::Core::RakeTask.new
@@ -29,3 +37,6 @@ task :default => :spec
29
37
  require 'yard'
30
38
  YARD::Rake::YardocTask.new
31
39
  task :docs => :yard
40
+
41
+ require 'md2man/task'
42
+ Md2Man::Task.new
@@ -1,9 +1,14 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- RONIN_URI = 'http://github.com/ronin-ruby'
3
+ DM_URI = 'http://github.com/datamapper'
4
+ DM_VERSION = '~> 1.2'
5
+ RONIN_URI = 'http://github.com/ronin-ruby'
4
6
 
5
7
  gemspec
6
8
 
9
+ gem 'jruby-openssl', '~> 0.7', :platforms => :jruby
10
+
11
+ # Ronin dependencies:
7
12
  # gem 'ronin-support', '~> <%= Ronin::Support::VERSION %>', :git => "#{RONIN_URI}/ronin-support.git"
8
13
  # gem 'ronin', '~> <%= Ronin::VERSION %>', :git => "#{RONIN_URI}/ronin.git"
9
14
  <%- unless @generators.empty? -%>
@@ -14,8 +19,8 @@ group :development do
14
19
  gem 'rake', '~> 0.8'
15
20
  gem 'kramdown', '~> 0.12'
16
21
 
17
- gem 'ore-tasks', '~> 0.4'
18
- gem 'rspec', '~> 2.4'
22
+ gem 'rubygems-tasks', '~> 0.1'
23
+ gem 'rspec', '~> 2.4'
19
24
  end
20
25
 
21
26
  #
@@ -18,8 +18,16 @@ end
18
18
 
19
19
  require 'rake'
20
20
 
21
- require 'ore/tasks'
22
- Ore::Tasks.new
21
+ require 'rubygems/tasks'
22
+ Gem::Tasks.new(:sign => {:checksum => true, :pgp => true}) do |tasks|
23
+ tasks.scm.tag.format = 'v%s'
24
+ tasks.console.command = 'ripl'
25
+ tasks.console.options = %w[
26
+ -rripl/multi_line
27
+ -rripl/auto_indent
28
+ -rripl/color_result
29
+ ]
30
+ end
23
31
 
24
32
  require 'rspec/core/rake_task'
25
33
  RSpec::Core::RakeTask.new
@@ -16,4 +16,4 @@ dependencies:
16
16
 
17
17
  development_dependencies:
18
18
  bundler: ~> 1.0
19
- yard: ~> 0.7
19
+ yard: ~> 0.8
@@ -2,130 +2,59 @@
2
2
 
3
3
  require 'yaml'
4
4
 
5
- Gem::Specification.new do |gemspec|
6
- root = File.dirname(__FILE__)
7
- lib_dir = File.join(root,'lib')
8
- files = if File.directory?('.git')
9
- `git ls-files`.split($/)
10
- elsif File.directory?('.hg')
11
- `hg manifest`.split($/)
12
- elsif File.directory?('.svn')
13
- `svn ls -R`.split($/).select { |path| File.file?(path) }
14
- else
15
- Dir['{**/}{.*,*}'].select { |path| File.file?(path) }
16
- end
5
+ Gem::Specification.new do |gem|
6
+ gemspec = YAML.load_file('gemspec.yml')
17
7
 
18
- filter_files = lambda { |paths|
19
- case paths
20
- when Array
21
- (files & paths)
22
- when String
23
- (files & Dir[paths])
24
- end
25
- }
26
-
27
- version = {
28
- :file => 'ronin/<%= @dir_name %>/version',
29
- :constant => 'Ronin::<%= @module_name %>::VERSION'
30
- }
31
-
32
- defaults = {
33
- 'name' => File.basename(root),
34
- 'files' => files,
35
- 'executables' => filter_files['bin/*'].map { |path| File.basename(path) },
36
- 'test_files' => filter_files['{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'],
37
- 'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
38
- }
8
+ gem.name = gemspec.fetch('name')
9
+ gem.version = gemspec.fetch('version') do
10
+ lib_dir = File.join(File.dirname(__FILE__),'lib')
11
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
39
12
 
40
- metadata = defaults.merge(YAML.load_file('gemspec.yml'))
13
+ require 'ronin/<%= @dir_name %>/version'
14
+ Ronin::<%= @module_name %>::VERSION
15
+ end
41
16
 
42
- gemspec.name = metadata.fetch('name',defaults[:name])
43
- gemspec.version = if metadata['version']
44
- metadata['version']
45
- else
46
- $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
17
+ gem.summary = gemspec['summary']
18
+ gem.description = gemspec['description']
19
+ gem.licenses = Array(gemspec['license'])
20
+ gem.authors = Array(gemspec['authors'])
21
+ gem.email = gemspec['email']
22
+ gem.homepage = gemspec['homepage']
47
23
 
48
- require version[:file]
49
- eval(version[:constant])
50
- end
24
+ glob = lambda { |patterns| gem.files & Dir[*patterns] }
51
25
 
52
- gemspec.summary = metadata.fetch('summary',metadata['description'])
53
- gemspec.description = metadata.fetch('description',metadata['summary'])
26
+ gem.files = `git ls-files`.split($/)
27
+ gem.files = glob[gemspec['files']] if gemspec['files']
54
28
 
55
- case metadata['license']
56
- when Array
57
- gemspec.licenses = metadata['license']
58
- when String
59
- gemspec.license = metadata['license']
29
+ gem.executables = gemspec.fetch('executables') do
30
+ glob['bin/*'].map { |path| File.basename(path) }
60
31
  end
32
+ gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
61
33
 
62
- case metadata['authors']
63
- when Array
64
- gemspec.authors = metadata['authors']
65
- when String
66
- gemspec.author = metadata['authors']
67
- end
68
-
69
- gemspec.email = metadata['email']
70
- gemspec.homepage = metadata['homepage']
34
+ gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
35
+ gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
36
+ gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
71
37
 
72
- case metadata['require_paths']
73
- when Array
74
- gemspec.require_paths = metadata['require_paths']
75
- when String
76
- gemspec.require_path = metadata['require_paths']
77
- end
38
+ gem.require_paths = Array(gemspec.fetch('require_paths') {
39
+ %w[ext lib].select { |dir| File.directory?(dir) }
40
+ })
78
41
 
79
- gemspec.files = filter_files[metadata['files']]
42
+ gem.requirements = gemspec['requirements']
43
+ gem.required_ruby_version = gemspec['required_ruby_version']
44
+ gem.required_rubygems_version = gemspec['required_rubygems_version']
45
+ gem.post_install_message = gemspec['post_install_message']
80
46
 
81
- gemspec.executables = metadata['executables']
82
- gemspec.extensions = metadata['extensions']
83
-
84
- if Gem::VERSION < '1.7.'
85
- gemspec.default_executable = gemspec.executables.first
86
- end
87
-
88
- gemspec.test_files = filter_files[metadata['test_files']]
89
-
90
- unless gemspec.files.include?('.document')
91
- gemspec.extra_rdoc_files = metadata['extra_doc_files']
92
- end
93
-
94
- gemspec.post_install_message = metadata['post_install_message']
95
- gemspec.requirements = metadata['requirements']
96
-
97
- if gemspec.respond_to?(:required_ruby_version=)
98
- gemspec.required_ruby_version = metadata['required_ruby_version']
99
- end
100
-
101
- if gemspec.respond_to?(:required_rubygems_version=)
102
- gemspec.required_rubygems_version = metadata['required_rubygems_version']
103
- end
104
-
105
- parse_versions = lambda { |versions|
106
- case versions
107
- when Array
108
- versions.map { |v| v.to_s }
109
- when String
110
- versions.split(/,\s*/)
111
- end
112
- }
113
-
114
- if metadata['dependencies']
115
- metadata['dependencies'].each do |name,versions|
116
- gemspec.add_dependency(name,parse_versions[versions])
117
- end
118
- end
47
+ split = lambda { |string| string.split(/,\s*/) }
119
48
 
120
- if metadata['runtime_dependencies']
121
- metadata['runtime_dependencies'].each do |name,versions|
122
- gemspec.add_runtime_dependency(name,parse_versions[versions])
49
+ if gemspec['dependencies']
50
+ gemspec['dependencies'].each do |name,versions|
51
+ gem.add_dependency(name,split[versions])
123
52
  end
124
53
  end
125
54
 
126
- if metadata['development_dependencies']
127
- metadata['development_dependencies'].each do |name,versions|
128
- gemspec.add_development_dependency(name,parse_versions[versions])
55
+ if gemspec['development_dependencies']
56
+ gemspec['development_dependencies'].each do |name,versions|
57
+ gem.add_development_dependency(name,split[versions])
129
58
  end
130
59
  end
131
60
  end
@@ -11,15 +11,18 @@ has_yard: true
11
11
 
12
12
  requirements: git >= 1.6.0.0, for the library generator
13
13
 
14
+ generated_files:
15
+ - man/ronin-gen.1
16
+
14
17
  dependencies:
15
18
  open_namespace: ~> 0.3
16
19
  data_paths: ~> 0.3
17
20
  parameters: ~> 0.4
18
21
  # Ronin dependencies:
19
- ronin-support: ~> 0.4
20
- ronin: ~> 1.4
22
+ ronin-support: ~> 0.5.0.rc1
23
+ ronin: ~> 1.5.0.rc1
21
24
 
22
25
  development_dependencies:
23
26
  bundler: ~> 1.0
24
- yard: ~> 0.7.0
25
- yard-parameters: ~> 0.1.0
27
+ yard: ~> 0.8
28
+ yard-parameters: ~> 0.1
@@ -0,0 +1,503 @@
1
+ #
2
+ # Copyright (c) 2009-2012 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ #
4
+ # This file is part of Ronin Gen.
5
+ #
6
+ # Ronin Gen is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Ronin Gen is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Ronin Gen. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'ronin/templates/erb'
21
+ require 'ronin/ui/output'
22
+
23
+ require 'fileutils'
24
+
25
+ module Ronin
26
+ module Gen
27
+ #
28
+ # Action methods for the {Generator} class.
29
+ #
30
+ # @since 1.2.0
31
+ #
32
+ # @api semipublic
33
+ #
34
+ module Actions
35
+ protected
36
+
37
+ include FileUtils
38
+ include Templates::Erb
39
+
40
+ # ANSI Bold code
41
+ BOLD = "\e[1m"
42
+
43
+ # ANSI Green code
44
+ GREEN = "\e[32m"
45
+
46
+ # ANSI Clear code
47
+ CLEAR = "\e[0m"
48
+
49
+ #
50
+ # Prints a file action.
51
+ #
52
+ # @param [String] command
53
+ # The command/options that represents the file action.
54
+ #
55
+ # @param [Array<String>] arguments
56
+ # Additional arguments related to the file action.
57
+ #
58
+ # @since 1.2.0
59
+ #
60
+ def print_command(command,*arguments)
61
+ unless UI::Output.silent?
62
+ arguments = arguments.join(' ')
63
+
64
+ if $stdout.tty?
65
+ command = BOLD + GREEN + command + CLEAR
66
+ end
67
+
68
+ puts "\t#{command}\t#{arguments}"
69
+ end
70
+ end
71
+
72
+ #
73
+ # Runs a command.
74
+ #
75
+ # @param [String] command
76
+ # The command or program to run.
77
+ #
78
+ # @param [Array<String>] arguments
79
+ # Additional arguments to run the program with.
80
+ #
81
+ # @since 1.1.0
82
+ #
83
+ def run(command,*arguments)
84
+ print_command command, *arguments
85
+
86
+ system(command,*arguments)
87
+ end
88
+
89
+ #
90
+ # Changes the permissions of a files or directories.
91
+ #
92
+ # @param [String, Integer] mode
93
+ # The new permissions for the files or directories.
94
+ #
95
+ # @param [Array<String>] paths
96
+ # The path to the files or directories.
97
+ #
98
+ # @since 1.1.0
99
+ #
100
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#chmod-instance_method
101
+ #
102
+ def chmod(mode,paths)
103
+ print_command 'chmod', mode.to_s(8), *paths
104
+
105
+ super(mode,paths)
106
+ end
107
+
108
+ #
109
+ # Changes the permissions of files/directories, recursively.
110
+ #
111
+ # @param [String, Integer] mode
112
+ # The new permissions for the files or directories.
113
+ #
114
+ # @param [Array<String>] paths
115
+ # The path to the files or directories.
116
+ #
117
+ # @since 1.1.0
118
+ #
119
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#chmod_R-instance_method
120
+ #
121
+ def chmod_R(mode,paths)
122
+ print_command 'chmod -R', mode.to_s(8)
123
+
124
+ super(mode,paths)
125
+ end
126
+
127
+ #
128
+ # Changes ownership of files or directories.
129
+ #
130
+ # @param [String, nil] user
131
+ # The new owner of the files or directories.
132
+ #
133
+ # @param [String, nil] group
134
+ # The new group for the files or directories.
135
+ #
136
+ # @param [Array<String>] paths
137
+ # The path to the files or directories.
138
+ #
139
+ # @since 1.1.0
140
+ #
141
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#chown-instance_method
142
+ #
143
+ def chown(user,group,paths)
144
+ print_command 'chown', "#{user}:#{group}", *paths
145
+
146
+ super(user,group,paths)
147
+ end
148
+
149
+ #
150
+ # Changes ownership of files/directories, recursively.
151
+ #
152
+ # @param [String, nil] user
153
+ # The new owner of the files or directories.
154
+ #
155
+ # @param [String, nil] group
156
+ # The new group for the files or directories.
157
+ #
158
+ # @param [Array<String>] paths
159
+ # The path to the files or directories.
160
+ #
161
+ # @since 1.1.0
162
+ #
163
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#chown_R-instance_method
164
+ #
165
+ def chown_R(user,group,paths)
166
+ print_command 'chown -R', "#{user}:#{group}", *paths
167
+
168
+ super(user,group,paths)
169
+ end
170
+
171
+ #
172
+ # Copies a data file.
173
+ #
174
+ # @param [String] file
175
+ # The relative path to the data file.
176
+ #
177
+ # @param [String] destination
178
+ # The destination to copy the data file to.
179
+ #
180
+ # @since 0.2.0
181
+ #
182
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#cp-instance_method
183
+ #
184
+ def cp(file,destination=file)
185
+ print_command 'cp', destination
186
+
187
+ super(data_file(file),destination)
188
+ end
189
+
190
+ #
191
+ # Copies the contents of all data directories.
192
+ #
193
+ # @param [String] directory
194
+ # The data directories to copy from.
195
+ #
196
+ # @param [String, nil] destination
197
+ # The optional destination directory to copy the files to.
198
+ #
199
+ # @since 1.0.0
200
+ #
201
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#cp_r-instance_method
202
+ #
203
+ def cp_r(directory,destination=directory)
204
+ print_command 'cp -r', destination
205
+
206
+ data_dirs(directory) do |dir|
207
+ super(dir,destination)
208
+ end
209
+ end
210
+
211
+ #
212
+ # Installs a file.
213
+ #
214
+ # @param [String] src
215
+ # The file to install.
216
+ #
217
+ # @param [String] dest
218
+ # The destination path for the file.
219
+ #
220
+ # @param [Hash] options
221
+ # Additional options.
222
+ #
223
+ # @option options [String, Integer] :mode
224
+ # The permissions of the installed file.
225
+ #
226
+ # @since 1.1.0
227
+ #
228
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#install-instance_method
229
+ #
230
+ def install(src,dest,options={})
231
+ options = {:mode => options[:mode]} # only pass in :mode
232
+
233
+ print_command 'install', src, dest
234
+
235
+ super(data_file(src),dest,options)
236
+ end
237
+
238
+ #
239
+ # Creates a hard link.
240
+ #
241
+ # @param [String] src
242
+ # The path file/directory for the hard link.
243
+ #
244
+ # @param [String] dest
245
+ # The destination file/directory of the hard link.
246
+ #
247
+ # @since 1.1.0
248
+ #
249
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#ln-instance_method
250
+ #
251
+ def ln(src,dest)
252
+ print_command 'ln', src, dest
253
+
254
+ super(src,dest)
255
+ end
256
+
257
+ #
258
+ # Creates a symbolic link.
259
+ #
260
+ # @param [String] src
261
+ # The path file/directory for the symbolic link.
262
+ #
263
+ # @param [String] dest
264
+ # The destination file/directory of the symbolic link.
265
+ #
266
+ # @since 1.1.0
267
+ #
268
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#ln_s-instance_method
269
+ #
270
+ def ln_s(src,dest)
271
+ print_command 'ln -s', src, dest
272
+
273
+ super(src,dest)
274
+ end
275
+
276
+ #
277
+ # Forcibly creates a symbolic link.
278
+ #
279
+ # @param [String] src
280
+ # The path file/directory for the symbolic link.
281
+ #
282
+ # @param [String] dest
283
+ # The destination file/directory of the symbolic link.
284
+ #
285
+ # @since 1.1.0
286
+ #
287
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#ln_sf-instance_method
288
+ #
289
+ def ln_sf(src,dest)
290
+ print_command 'ln -sf', src, dest
291
+
292
+ super(src,dest)
293
+ end
294
+
295
+ #
296
+ # Creates an empty directory.
297
+ #
298
+ # @param [String] dir
299
+ # The relative path of the directory to create.
300
+ #
301
+ # @example
302
+ # mkdir 'sub/dir'
303
+ #
304
+ # @since 0.2.0
305
+ #
306
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#mkdir-instance_method
307
+ #
308
+ def mkdir(dir)
309
+ print_command 'mkdir', dir
310
+
311
+ super(dir)
312
+ end
313
+
314
+ #
315
+ # Creates an empty directory.
316
+ #
317
+ # @param [String] dir
318
+ # The relative path of the directory to create.
319
+ #
320
+ # @example
321
+ # mkdir 'sub/dir'
322
+ #
323
+ # @since 0.2.0
324
+ #
325
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#mkdir_p-instance_method
326
+ #
327
+ def mkdir_p(dir)
328
+ print_command 'mkdir', dir
329
+
330
+ super(dir)
331
+ end
332
+
333
+ #
334
+ # Moves a file or directory.
335
+ #
336
+ # @param [String] src
337
+ # The path to the file or directory.
338
+ #
339
+ # @param [String] dest
340
+ # The new path to move the file or directory to.
341
+ #
342
+ # @since 1.1.0
343
+ #
344
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#mv-instance_method
345
+ #
346
+ def mv(src,dest)
347
+ print_command 'mv', src, dest
348
+
349
+ super(src,dest)
350
+ end
351
+
352
+ #
353
+ # Removes one or more files.
354
+ #
355
+ # @param [Array<String>] paths
356
+ # The paths of the files and directories to remove.
357
+ #
358
+ # @param [Hash] options
359
+ # Additional options.
360
+ #
361
+ # @option options [Boolean] :force
362
+ # Specifies whether to forcible remove the files.
363
+ #
364
+ # @since 1.1.0
365
+ #
366
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#rm-instance_method
367
+ #
368
+ def rm(paths,options={})
369
+ options = {:force => options[:force]} # only pass in :force
370
+
371
+ print_command 'rm', *paths
372
+
373
+ super(paths,options)
374
+ end
375
+
376
+ #
377
+ # Recursively removes files and directories.
378
+ #
379
+ # @param [Array<String>] paths
380
+ # The paths of the files and directories to remove.
381
+ #
382
+ # @param [Hash] options
383
+ # Additional options.
384
+ #
385
+ # @option options [Boolean] :force
386
+ # Specifies whether to forcible remove the files.
387
+ #
388
+ # @since 1.1.0
389
+ #
390
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#rm_r-instance_method
391
+ #
392
+ def rm_r(paths,options={})
393
+ options = {:force => options[:force]} # only pass in :force
394
+
395
+ print_command 'rm -r', *paths
396
+
397
+ super(paths,options)
398
+ end
399
+
400
+ #
401
+ # Forcibly removes files and directories, recursively.
402
+ #
403
+ # @param [Array<String>] paths
404
+ # The paths of the files and directories to remove.
405
+ #
406
+ # @since 1.1.0
407
+ #
408
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#rm_rf-instance_method
409
+ #
410
+ def rm_rf(paths)
411
+ print_command 'rm -rf', *paths
412
+
413
+ super(paths)
414
+ end
415
+
416
+ #
417
+ # Removes one or more directories.
418
+ #
419
+ # @param [Array<String>] dirs
420
+ # The paths of the directories.
421
+ #
422
+ # @since 1.1.0
423
+ #
424
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#rmdir-instance_method
425
+ #
426
+ def rmdir(dirs)
427
+ print_command 'rmdir', *dirs
428
+
429
+ super(dirs)
430
+ end
431
+
432
+ #
433
+ # Touches a file.
434
+ #
435
+ # @param [String] path
436
+ # The relative path to the file to touch.
437
+ #
438
+ # @example
439
+ # touch 'TODO.txt'
440
+ #
441
+ # @since 0.2.0
442
+ #
443
+ # @see http://rubydoc.info/stdlib/fileutils/FileUtils#touch-instance_method
444
+ #
445
+ def touch(path)
446
+ print_command 'touch', path
447
+
448
+ return super(path)
449
+ end
450
+
451
+ #
452
+ # Opens a file for writing.
453
+ #
454
+ # @param [String] path
455
+ # The path of the file to write to.
456
+ #
457
+ # @yield [file]
458
+ # The given block will be passed the newly opened file.
459
+ #
460
+ # @yieldparam [File]
461
+ # The new file file, opened for writing.
462
+ #
463
+ # @since 1.1.0
464
+ #
465
+ def write(path,&block)
466
+ File.open(path,'wb',&block)
467
+ end
468
+
469
+ #
470
+ # Renders the ERB template and saves the result.
471
+ #
472
+ # @param [String] template_path
473
+ # The relative path to the template.
474
+ #
475
+ # @param [String, nil] destination
476
+ # The destination to write the result of the rendered template to.
477
+ #
478
+ # @return [nil, String]
479
+ # If destination is `nil`, the result of the rendered template
480
+ # will be returned.
481
+ #
482
+ # @example
483
+ # template 'Rakefile.erb', 'Rakefile'
484
+ #
485
+ # @example
486
+ # template '_helpers.erb'
487
+ #
488
+ # @since 0.2.0
489
+ #
490
+ def template(template_path,destination=nil)
491
+ if destination
492
+ print_command 'erb', destination
493
+
494
+ File.open(destination,'w') do |file|
495
+ file.write(erb_file(template_path))
496
+ end
497
+ else
498
+ erb_file(template_path).chomp
499
+ end
500
+ end
501
+ end
502
+ end
503
+ end