bundler_package_git 1.1.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +22 -0
- data/.rvmrc +1 -0
- data/CHANGELOG.md +659 -0
- data/ISSUES.md +47 -0
- data/LICENSE +23 -0
- data/README.md +29 -0
- data/Rakefile +167 -0
- data/UPGRADING.md +103 -0
- data/bin/bundle +22 -0
- data/bundler.gemspec +30 -0
- data/lib/bundler.rb +283 -0
- data/lib/bundler/capistrano.rb +11 -0
- data/lib/bundler/cli.rb +490 -0
- data/lib/bundler/definition.rb +429 -0
- data/lib/bundler/dependency.rb +130 -0
- data/lib/bundler/deployment.rb +53 -0
- data/lib/bundler/dsl.rb +243 -0
- data/lib/bundler/environment.rb +47 -0
- data/lib/bundler/fetcher.rb +101 -0
- data/lib/bundler/gem_helper.rb +146 -0
- data/lib/bundler/graph.rb +130 -0
- data/lib/bundler/index.rb +131 -0
- data/lib/bundler/installer.rb +117 -0
- data/lib/bundler/lazy_specification.rb +71 -0
- data/lib/bundler/lockfile_parser.rb +108 -0
- data/lib/bundler/remote_specification.rb +57 -0
- data/lib/bundler/resolver.rb +470 -0
- data/lib/bundler/rubygems_ext.rb +226 -0
- data/lib/bundler/runtime.rb +201 -0
- data/lib/bundler/settings.rb +117 -0
- data/lib/bundler/setup.rb +16 -0
- data/lib/bundler/shared_helpers.rb +167 -0
- data/lib/bundler/source.rb +675 -0
- data/lib/bundler/spec_set.rb +134 -0
- data/lib/bundler/templates/Executable +16 -0
- data/lib/bundler/templates/Gemfile +4 -0
- data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
- data/lib/bundler/templates/newgem/Rakefile.tt +2 -0
- data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
- data/lib/bundler/templates/newgem/gitignore.tt +4 -0
- data/lib/bundler/templates/newgem/lib/newgem.rb.tt +7 -0
- data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
- data/lib/bundler/templates/newgem/newgem.gemspec.tt +21 -0
- data/lib/bundler/ui.rb +73 -0
- data/lib/bundler/vendor/net/http/faster.rb +27 -0
- data/lib/bundler/vendor/net/http/persistent.rb +464 -0
- data/lib/bundler/vendor/thor.rb +319 -0
- data/lib/bundler/vendor/thor/actions.rb +297 -0
- data/lib/bundler/vendor/thor/actions/create_file.rb +105 -0
- data/lib/bundler/vendor/thor/actions/directory.rb +93 -0
- data/lib/bundler/vendor/thor/actions/empty_directory.rb +134 -0
- data/lib/bundler/vendor/thor/actions/file_manipulation.rb +229 -0
- data/lib/bundler/vendor/thor/actions/inject_into_file.rb +104 -0
- data/lib/bundler/vendor/thor/base.rb +556 -0
- data/lib/bundler/vendor/thor/core_ext/file_binary_read.rb +9 -0
- data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +75 -0
- data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +100 -0
- data/lib/bundler/vendor/thor/error.rb +30 -0
- data/lib/bundler/vendor/thor/invocation.rb +168 -0
- data/lib/bundler/vendor/thor/parser.rb +4 -0
- data/lib/bundler/vendor/thor/parser/argument.rb +67 -0
- data/lib/bundler/vendor/thor/parser/arguments.rb +161 -0
- data/lib/bundler/vendor/thor/parser/option.rb +120 -0
- data/lib/bundler/vendor/thor/parser/options.rb +174 -0
- data/lib/bundler/vendor/thor/shell.rb +88 -0
- data/lib/bundler/vendor/thor/shell/basic.rb +275 -0
- data/lib/bundler/vendor/thor/shell/color.rb +108 -0
- data/lib/bundler/vendor/thor/shell/html.rb +121 -0
- data/lib/bundler/vendor/thor/task.rb +114 -0
- data/lib/bundler/vendor/thor/util.rb +229 -0
- data/lib/bundler/vendor/thor/version.rb +3 -0
- data/lib/bundler/version.rb +6 -0
- data/lib/bundler/vlad.rb +9 -0
- data/man/bundle-config.ronn +90 -0
- data/man/bundle-exec.ronn +111 -0
- data/man/bundle-install.ronn +314 -0
- data/man/bundle-package.ronn +59 -0
- data/man/bundle-update.ronn +176 -0
- data/man/bundle.ronn +80 -0
- data/man/gemfile.5.ronn +279 -0
- data/man/index.txt +6 -0
- data/spec/cache/gems_spec.rb +219 -0
- data/spec/cache/git_spec.rb +9 -0
- data/spec/cache/path_spec.rb +27 -0
- data/spec/cache/platform_spec.rb +57 -0
- data/spec/install/deploy_spec.rb +197 -0
- data/spec/install/deprecated_spec.rb +37 -0
- data/spec/install/gems/c_ext_spec.rb +48 -0
- data/spec/install/gems/dependency_api_spec.rb +85 -0
- data/spec/install/gems/env_spec.rb +107 -0
- data/spec/install/gems/flex_spec.rb +313 -0
- data/spec/install/gems/groups_spec.rb +245 -0
- data/spec/install/gems/packed_spec.rb +84 -0
- data/spec/install/gems/platform_spec.rb +208 -0
- data/spec/install/gems/resolving_spec.rb +72 -0
- data/spec/install/gems/simple_case_spec.rb +715 -0
- data/spec/install/gems/standalone_spec.rb +162 -0
- data/spec/install/gems/sudo_spec.rb +73 -0
- data/spec/install/gems/win32_spec.rb +26 -0
- data/spec/install/gemspec_spec.rb +108 -0
- data/spec/install/git_spec.rb +571 -0
- data/spec/install/invalid_spec.rb +17 -0
- data/spec/install/path_spec.rb +353 -0
- data/spec/install/upgrade_spec.rb +26 -0
- data/spec/lock/git_spec.rb +35 -0
- data/spec/lock/lockfile_spec.rb +683 -0
- data/spec/other/check_spec.rb +221 -0
- data/spec/other/clean_spec.rb +202 -0
- data/spec/other/config_spec.rb +40 -0
- data/spec/other/console_spec.rb +54 -0
- data/spec/other/exec_spec.rb +241 -0
- data/spec/other/ext_spec.rb +16 -0
- data/spec/other/gem_helper_spec.rb +128 -0
- data/spec/other/help_spec.rb +38 -0
- data/spec/other/init_spec.rb +40 -0
- data/spec/other/newgem_spec.rb +24 -0
- data/spec/other/open_spec.rb +35 -0
- data/spec/other/show_spec.rb +82 -0
- data/spec/pack/gems_spec.rb +54 -0
- data/spec/quality_spec.rb +58 -0
- data/spec/resolver/basic_spec.rb +20 -0
- data/spec/resolver/platform_spec.rb +82 -0
- data/spec/runtime/executable_spec.rb +110 -0
- data/spec/runtime/load_spec.rb +107 -0
- data/spec/runtime/platform_spec.rb +90 -0
- data/spec/runtime/require_spec.rb +231 -0
- data/spec/runtime/setup_spec.rb +688 -0
- data/spec/runtime/with_clean_env_spec.rb +15 -0
- data/spec/spec_helper.rb +85 -0
- data/spec/support/artifice/endpoint.rb +50 -0
- data/spec/support/artifice/endpoint_fallback.rb +22 -0
- data/spec/support/artifice/endpoint_marshal_fail.rb +11 -0
- data/spec/support/artifice/endpoint_redirect.rb +11 -0
- data/spec/support/builders.rb +574 -0
- data/spec/support/fakeweb/rack-1.0.0.marshal +2 -0
- data/spec/support/fakeweb/windows.rb +23 -0
- data/spec/support/helpers.rb +246 -0
- data/spec/support/indexes.rb +112 -0
- data/spec/support/matchers.rb +89 -0
- data/spec/support/path.rb +73 -0
- data/spec/support/platforms.rb +53 -0
- data/spec/support/ruby_ext.rb +20 -0
- data/spec/support/rubygems_ext.rb +35 -0
- data/spec/support/rubygems_hax/platform.rb +11 -0
- data/spec/support/sudo.rb +21 -0
- data/spec/update/gems_spec.rb +121 -0
- data/spec/update/git_spec.rb +196 -0
- data/spec/update/source_spec.rb +51 -0
- metadata +294 -0
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'thor/actions/empty_directory'
|
2
|
+
|
3
|
+
class Thor
|
4
|
+
module Actions
|
5
|
+
|
6
|
+
# Create a new file relative to the destination root with the given data,
|
7
|
+
# which is the return value of a block or a data string.
|
8
|
+
#
|
9
|
+
# ==== Parameters
|
10
|
+
# destination<String>:: the relative path to the destination root.
|
11
|
+
# data<String|NilClass>:: the data to append to the file.
|
12
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
13
|
+
#
|
14
|
+
# ==== Examples
|
15
|
+
#
|
16
|
+
# create_file "lib/fun_party.rb" do
|
17
|
+
# hostname = ask("What is the virtual hostname I should use?")
|
18
|
+
# "vhost.name = #{hostname}"
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# create_file "config/apach.conf", "your apache config"
|
22
|
+
#
|
23
|
+
def create_file(destination, *args, &block)
|
24
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
25
|
+
data = args.first
|
26
|
+
action CreateFile.new(self, destination, block || data.to_s, config)
|
27
|
+
end
|
28
|
+
alias :add_file :create_file
|
29
|
+
|
30
|
+
# AddFile is a subset of Template, which instead of rendering a file with
|
31
|
+
# ERB, it gets the content from the user.
|
32
|
+
#
|
33
|
+
class CreateFile < EmptyDirectory #:nodoc:
|
34
|
+
attr_reader :data
|
35
|
+
|
36
|
+
def initialize(base, destination, data, config={})
|
37
|
+
@data = data
|
38
|
+
super(base, destination, config)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Checks if the content of the file at the destination is identical to the rendered result.
|
42
|
+
#
|
43
|
+
# ==== Returns
|
44
|
+
# Boolean:: true if it is identical, false otherwise.
|
45
|
+
#
|
46
|
+
def identical?
|
47
|
+
exists? && File.binread(destination) == render
|
48
|
+
end
|
49
|
+
|
50
|
+
# Holds the content to be added to the file.
|
51
|
+
#
|
52
|
+
def render
|
53
|
+
@render ||= if data.is_a?(Proc)
|
54
|
+
data.call
|
55
|
+
else
|
56
|
+
data
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def invoke!
|
61
|
+
invoke_with_conflict_check do
|
62
|
+
FileUtils.mkdir_p(File.dirname(destination))
|
63
|
+
File.open(destination, 'wb') { |f| f.write render }
|
64
|
+
end
|
65
|
+
given_destination
|
66
|
+
end
|
67
|
+
|
68
|
+
protected
|
69
|
+
|
70
|
+
# Now on conflict we check if the file is identical or not.
|
71
|
+
#
|
72
|
+
def on_conflict_behavior(&block)
|
73
|
+
if identical?
|
74
|
+
say_status :identical, :blue
|
75
|
+
else
|
76
|
+
options = base.options.merge(config)
|
77
|
+
force_or_skip_or_conflict(options[:force], options[:skip], &block)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# If force is true, run the action, otherwise check if it's not being
|
82
|
+
# skipped. If both are false, show the file_collision menu, if the menu
|
83
|
+
# returns true, force it, otherwise skip.
|
84
|
+
#
|
85
|
+
def force_or_skip_or_conflict(force, skip, &block)
|
86
|
+
if force
|
87
|
+
say_status :force, :yellow
|
88
|
+
block.call unless pretend?
|
89
|
+
elsif skip
|
90
|
+
say_status :skip, :yellow
|
91
|
+
else
|
92
|
+
say_status :conflict, :red
|
93
|
+
force_or_skip_or_conflict(force_on_collision?, true, &block)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Shows the file collision menu to the user and gets the result.
|
98
|
+
#
|
99
|
+
def force_on_collision?
|
100
|
+
base.shell.file_collision(destination){ render }
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'thor/actions/empty_directory'
|
2
|
+
|
3
|
+
class Thor
|
4
|
+
module Actions
|
5
|
+
|
6
|
+
# Copies recursively the files from source directory to root directory.
|
7
|
+
# If any of the files finishes with .tt, it's considered to be a template
|
8
|
+
# and is placed in the destination without the extension .tt. If any
|
9
|
+
# empty directory is found, it's copied and all .empty_directory files are
|
10
|
+
# ignored. Remember that file paths can also be encoded, let's suppose a doc
|
11
|
+
# directory with the following files:
|
12
|
+
#
|
13
|
+
# doc/
|
14
|
+
# components/.empty_directory
|
15
|
+
# README
|
16
|
+
# rdoc.rb.tt
|
17
|
+
# %app_name%.rb
|
18
|
+
#
|
19
|
+
# When invoked as:
|
20
|
+
#
|
21
|
+
# directory "doc"
|
22
|
+
#
|
23
|
+
# It will create a doc directory in the destination with the following
|
24
|
+
# files (assuming that the app_name is "blog"):
|
25
|
+
#
|
26
|
+
# doc/
|
27
|
+
# components/
|
28
|
+
# README
|
29
|
+
# rdoc.rb
|
30
|
+
# blog.rb
|
31
|
+
#
|
32
|
+
# ==== Parameters
|
33
|
+
# source<String>:: the relative path to the source root.
|
34
|
+
# destination<String>:: the relative path to the destination root.
|
35
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
36
|
+
# If :recursive => false, does not look for paths recursively.
|
37
|
+
#
|
38
|
+
# ==== Examples
|
39
|
+
#
|
40
|
+
# directory "doc"
|
41
|
+
# directory "doc", "docs", :recursive => false
|
42
|
+
#
|
43
|
+
def directory(source, *args, &block)
|
44
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
45
|
+
destination = args.first || source
|
46
|
+
action Directory.new(self, source, destination || source, config, &block)
|
47
|
+
end
|
48
|
+
|
49
|
+
class Directory < EmptyDirectory #:nodoc:
|
50
|
+
attr_reader :source
|
51
|
+
|
52
|
+
def initialize(base, source, destination=nil, config={}, &block)
|
53
|
+
@source = File.expand_path(base.find_in_source_paths(source.to_s))
|
54
|
+
@block = block
|
55
|
+
super(base, destination, { :recursive => true }.merge(config))
|
56
|
+
end
|
57
|
+
|
58
|
+
def invoke!
|
59
|
+
base.empty_directory given_destination, config
|
60
|
+
execute!
|
61
|
+
end
|
62
|
+
|
63
|
+
def revoke!
|
64
|
+
execute!
|
65
|
+
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
|
69
|
+
def execute!
|
70
|
+
lookup = config[:recursive] ? File.join(source, '**') : source
|
71
|
+
lookup = File.join(lookup, '{*,.[a-z]*}')
|
72
|
+
|
73
|
+
Dir[lookup].each do |file_source|
|
74
|
+
next if File.directory?(file_source)
|
75
|
+
file_destination = File.join(given_destination, file_source.gsub(source, '.'))
|
76
|
+
file_destination.gsub!('/./', '/')
|
77
|
+
|
78
|
+
case file_source
|
79
|
+
when /\.empty_directory$/
|
80
|
+
dirname = File.dirname(file_destination).gsub(/\/\.$/, '')
|
81
|
+
next if dirname == given_destination
|
82
|
+
base.empty_directory(dirname, config)
|
83
|
+
when /\.tt$/
|
84
|
+
destination = base.template(file_source, file_destination[0..-4], config, &@block)
|
85
|
+
else
|
86
|
+
destination = base.copy_file(file_source, file_destination, config, &@block)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
class Thor
|
2
|
+
module Actions
|
3
|
+
|
4
|
+
# Creates an empty directory.
|
5
|
+
#
|
6
|
+
# ==== Parameters
|
7
|
+
# destination<String>:: the relative path to the destination root.
|
8
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
9
|
+
#
|
10
|
+
# ==== Examples
|
11
|
+
#
|
12
|
+
# empty_directory "doc"
|
13
|
+
#
|
14
|
+
def empty_directory(destination, config={})
|
15
|
+
action EmptyDirectory.new(self, destination, config)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Class which holds create directory logic. This is the base class for
|
19
|
+
# other actions like create_file and directory.
|
20
|
+
#
|
21
|
+
# This implementation is based in Templater actions, created by Jonas Nicklas
|
22
|
+
# and Michael S. Klishin under MIT LICENSE.
|
23
|
+
#
|
24
|
+
class EmptyDirectory #:nodoc:
|
25
|
+
attr_reader :base, :destination, :given_destination, :relative_destination, :config
|
26
|
+
|
27
|
+
# Initializes given the source and destination.
|
28
|
+
#
|
29
|
+
# ==== Parameters
|
30
|
+
# base<Thor::Base>:: A Thor::Base instance
|
31
|
+
# source<String>:: Relative path to the source of this file
|
32
|
+
# destination<String>:: Relative path to the destination of this file
|
33
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
34
|
+
#
|
35
|
+
def initialize(base, destination, config={})
|
36
|
+
@base, @config = base, { :verbose => true }.merge(config)
|
37
|
+
self.destination = destination
|
38
|
+
end
|
39
|
+
|
40
|
+
# Checks if the destination file already exists.
|
41
|
+
#
|
42
|
+
# ==== Returns
|
43
|
+
# Boolean:: true if the file exists, false otherwise.
|
44
|
+
#
|
45
|
+
def exists?
|
46
|
+
::File.exists?(destination)
|
47
|
+
end
|
48
|
+
|
49
|
+
def invoke!
|
50
|
+
invoke_with_conflict_check do
|
51
|
+
::FileUtils.mkdir_p(destination)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def revoke!
|
56
|
+
say_status :remove, :red
|
57
|
+
::FileUtils.rm_rf(destination) if !pretend? && exists?
|
58
|
+
given_destination
|
59
|
+
end
|
60
|
+
|
61
|
+
protected
|
62
|
+
|
63
|
+
# Shortcut for pretend.
|
64
|
+
#
|
65
|
+
def pretend?
|
66
|
+
base.options[:pretend]
|
67
|
+
end
|
68
|
+
|
69
|
+
# Sets the absolute destination value from a relative destination value.
|
70
|
+
# It also stores the given and relative destination. Let's suppose our
|
71
|
+
# script is being executed on "dest", it sets the destination root to
|
72
|
+
# "dest". The destination, given_destination and relative_destination
|
73
|
+
# are related in the following way:
|
74
|
+
#
|
75
|
+
# inside "bar" do
|
76
|
+
# empty_directory "baz"
|
77
|
+
# end
|
78
|
+
#
|
79
|
+
# destination #=> dest/bar/baz
|
80
|
+
# relative_destination #=> bar/baz
|
81
|
+
# given_destination #=> baz
|
82
|
+
#
|
83
|
+
def destination=(destination)
|
84
|
+
if destination
|
85
|
+
@given_destination = convert_encoded_instructions(destination.to_s)
|
86
|
+
@destination = ::File.expand_path(@given_destination, base.destination_root)
|
87
|
+
@relative_destination = base.relative_to_original_destination_root(@destination)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Filenames in the encoded form are converted. If you have a file:
|
92
|
+
#
|
93
|
+
# %class_name%.rb
|
94
|
+
#
|
95
|
+
# It gets the class name from the base and replace it:
|
96
|
+
#
|
97
|
+
# user.rb
|
98
|
+
#
|
99
|
+
def convert_encoded_instructions(filename)
|
100
|
+
filename.gsub(/%(.*?)%/) do |string|
|
101
|
+
instruction = $1.strip
|
102
|
+
base.respond_to?(instruction) ? base.send(instruction) : string
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Receives a hash of options and just execute the block if some
|
107
|
+
# conditions are met.
|
108
|
+
#
|
109
|
+
def invoke_with_conflict_check(&block)
|
110
|
+
if exists?
|
111
|
+
on_conflict_behavior(&block)
|
112
|
+
else
|
113
|
+
say_status :create, :green
|
114
|
+
block.call unless pretend?
|
115
|
+
end
|
116
|
+
|
117
|
+
destination
|
118
|
+
end
|
119
|
+
|
120
|
+
# What to do when the destination file already exists.
|
121
|
+
#
|
122
|
+
def on_conflict_behavior(&block)
|
123
|
+
say_status :exist, :blue
|
124
|
+
end
|
125
|
+
|
126
|
+
# Shortcut to say_status shell method.
|
127
|
+
#
|
128
|
+
def say_status(status, color)
|
129
|
+
base.shell.say_status status, relative_destination, color if config[:verbose]
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,229 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
class Thor
|
5
|
+
module Actions
|
6
|
+
|
7
|
+
# Copies the file from the relative source to the relative destination. If
|
8
|
+
# the destination is not given it's assumed to be equal to the source.
|
9
|
+
#
|
10
|
+
# ==== Parameters
|
11
|
+
# source<String>:: the relative path to the source root.
|
12
|
+
# destination<String>:: the relative path to the destination root.
|
13
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
14
|
+
#
|
15
|
+
# ==== Examples
|
16
|
+
#
|
17
|
+
# copy_file "README", "doc/README"
|
18
|
+
#
|
19
|
+
# copy_file "doc/README"
|
20
|
+
#
|
21
|
+
def copy_file(source, *args, &block)
|
22
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
23
|
+
destination = args.first || source
|
24
|
+
source = File.expand_path(find_in_source_paths(source.to_s))
|
25
|
+
|
26
|
+
create_file destination, nil, config do
|
27
|
+
content = File.binread(source)
|
28
|
+
content = block.call(content) if block
|
29
|
+
content
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Gets the content at the given address and places it at the given relative
|
34
|
+
# destination. If a block is given instead of destination, the content of
|
35
|
+
# the url is yielded and used as location.
|
36
|
+
#
|
37
|
+
# ==== Parameters
|
38
|
+
# source<String>:: the address of the given content.
|
39
|
+
# destination<String>:: the relative path to the destination root.
|
40
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
41
|
+
#
|
42
|
+
# ==== Examples
|
43
|
+
#
|
44
|
+
# get "http://gist.github.com/103208", "doc/README"
|
45
|
+
#
|
46
|
+
# get "http://gist.github.com/103208" do |content|
|
47
|
+
# content.split("\n").first
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
def get(source, *args, &block)
|
51
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
52
|
+
destination = args.first
|
53
|
+
|
54
|
+
source = File.expand_path(find_in_source_paths(source.to_s)) unless source =~ /^http\:\/\//
|
55
|
+
render = open(source) {|input| input.binmode.read }
|
56
|
+
|
57
|
+
destination ||= if block_given?
|
58
|
+
block.arity == 1 ? block.call(render) : block.call
|
59
|
+
else
|
60
|
+
File.basename(source)
|
61
|
+
end
|
62
|
+
|
63
|
+
create_file destination, render, config
|
64
|
+
end
|
65
|
+
|
66
|
+
# Gets an ERB template at the relative source, executes it and makes a copy
|
67
|
+
# at the relative destination. If the destination is not given it's assumed
|
68
|
+
# to be equal to the source removing .tt from the filename.
|
69
|
+
#
|
70
|
+
# ==== Parameters
|
71
|
+
# source<String>:: the relative path to the source root.
|
72
|
+
# destination<String>:: the relative path to the destination root.
|
73
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
74
|
+
#
|
75
|
+
# ==== Examples
|
76
|
+
#
|
77
|
+
# template "README", "doc/README"
|
78
|
+
#
|
79
|
+
# template "doc/README"
|
80
|
+
#
|
81
|
+
def template(source, *args, &block)
|
82
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
83
|
+
destination = args.first || source
|
84
|
+
|
85
|
+
source = File.expand_path(find_in_source_paths(source.to_s))
|
86
|
+
context = instance_eval('binding')
|
87
|
+
|
88
|
+
create_file destination, nil, config do
|
89
|
+
content = ERB.new(::File.binread(source), nil, '-').result(context)
|
90
|
+
content = block.call(content) if block
|
91
|
+
content
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Changes the mode of the given file or directory.
|
96
|
+
#
|
97
|
+
# ==== Parameters
|
98
|
+
# mode<Integer>:: the file mode
|
99
|
+
# path<String>:: the name of the file to change mode
|
100
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
101
|
+
#
|
102
|
+
# ==== Example
|
103
|
+
#
|
104
|
+
# chmod "script/*", 0755
|
105
|
+
#
|
106
|
+
def chmod(path, mode, config={})
|
107
|
+
return unless behavior == :invoke
|
108
|
+
path = File.expand_path(path, destination_root)
|
109
|
+
say_status :chmod, relative_to_original_destination_root(path), config.fetch(:verbose, true)
|
110
|
+
FileUtils.chmod_R(mode, path) unless options[:pretend]
|
111
|
+
end
|
112
|
+
|
113
|
+
# Prepend text to a file. Since it depends on inject_into_file, it's reversible.
|
114
|
+
#
|
115
|
+
# ==== Parameters
|
116
|
+
# path<String>:: path of the file to be changed
|
117
|
+
# data<String>:: the data to prepend to the file, can be also given as a block.
|
118
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
119
|
+
#
|
120
|
+
# ==== Example
|
121
|
+
#
|
122
|
+
# prepend_file 'config/environments/test.rb', 'config.gem "rspec"'
|
123
|
+
#
|
124
|
+
# prepend_file 'config/environments/test.rb' do
|
125
|
+
# 'config.gem "rspec"'
|
126
|
+
# end
|
127
|
+
#
|
128
|
+
def prepend_file(path, *args, &block)
|
129
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
130
|
+
config.merge!(:after => /\A/)
|
131
|
+
inject_into_file(path, *(args << config), &block)
|
132
|
+
end
|
133
|
+
|
134
|
+
# Append text to a file. Since it depends on inject_into_file, it's reversible.
|
135
|
+
#
|
136
|
+
# ==== Parameters
|
137
|
+
# path<String>:: path of the file to be changed
|
138
|
+
# data<String>:: the data to append to the file, can be also given as a block.
|
139
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
140
|
+
#
|
141
|
+
# ==== Example
|
142
|
+
#
|
143
|
+
# append_file 'config/environments/test.rb', 'config.gem "rspec"'
|
144
|
+
#
|
145
|
+
# append_file 'config/environments/test.rb' do
|
146
|
+
# 'config.gem "rspec"'
|
147
|
+
# end
|
148
|
+
#
|
149
|
+
def append_file(path, *args, &block)
|
150
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
151
|
+
config.merge!(:before => /\z/)
|
152
|
+
inject_into_file(path, *(args << config), &block)
|
153
|
+
end
|
154
|
+
|
155
|
+
# Injects text right after the class definition. Since it depends on
|
156
|
+
# inject_into_file, it's reversible.
|
157
|
+
#
|
158
|
+
# ==== Parameters
|
159
|
+
# path<String>:: path of the file to be changed
|
160
|
+
# klass<String|Class>:: the class to be manipulated
|
161
|
+
# data<String>:: the data to append to the class, can be also given as a block.
|
162
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
163
|
+
#
|
164
|
+
# ==== Examples
|
165
|
+
#
|
166
|
+
# inject_into_class "app/controllers/application_controller.rb", " filter_parameter :password\n"
|
167
|
+
#
|
168
|
+
# inject_into_class "app/controllers/application_controller.rb", ApplicationController do
|
169
|
+
# " filter_parameter :password\n"
|
170
|
+
# end
|
171
|
+
#
|
172
|
+
def inject_into_class(path, klass, *args, &block)
|
173
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
174
|
+
config.merge!(:after => /class #{klass}\n|class #{klass} .*\n/)
|
175
|
+
inject_into_file(path, *(args << config), &block)
|
176
|
+
end
|
177
|
+
|
178
|
+
# Run a regular expression replacement on a file.
|
179
|
+
#
|
180
|
+
# ==== Parameters
|
181
|
+
# path<String>:: path of the file to be changed
|
182
|
+
# flag<Regexp|String>:: the regexp or string to be replaced
|
183
|
+
# replacement<String>:: the replacement, can be also given as a block
|
184
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
185
|
+
#
|
186
|
+
# ==== Example
|
187
|
+
#
|
188
|
+
# gsub_file 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1'
|
189
|
+
#
|
190
|
+
# gsub_file 'README', /rake/, :green do |match|
|
191
|
+
# match << " no more. Use thor!"
|
192
|
+
# end
|
193
|
+
#
|
194
|
+
def gsub_file(path, flag, *args, &block)
|
195
|
+
return unless behavior == :invoke
|
196
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
197
|
+
|
198
|
+
path = File.expand_path(path, destination_root)
|
199
|
+
say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true)
|
200
|
+
|
201
|
+
unless options[:pretend]
|
202
|
+
content = File.binread(path)
|
203
|
+
content.gsub!(flag, *args, &block)
|
204
|
+
File.open(path, 'wb') { |file| file.write(content) }
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
# Removes a file at the given location.
|
209
|
+
#
|
210
|
+
# ==== Parameters
|
211
|
+
# path<String>:: path of the file to be changed
|
212
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
213
|
+
#
|
214
|
+
# ==== Example
|
215
|
+
#
|
216
|
+
# remove_file 'README'
|
217
|
+
# remove_file 'app/controllers/application_controller.rb'
|
218
|
+
#
|
219
|
+
def remove_file(path, config={})
|
220
|
+
return unless behavior == :invoke
|
221
|
+
path = File.expand_path(path, destination_root)
|
222
|
+
|
223
|
+
say_status :remove, relative_to_original_destination_root(path), config.fetch(:verbose, true)
|
224
|
+
::FileUtils.rm_rf(path) if !options[:pretend] && File.exists?(path)
|
225
|
+
end
|
226
|
+
alias :remove_dir :remove_file
|
227
|
+
|
228
|
+
end
|
229
|
+
end
|