josevalim-thor 0.10.3 → 0.10.4

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.
@@ -46,13 +46,11 @@ class Thor
46
46
 
47
47
  def invoke!
48
48
  Dir[File.join(source, '**', '*')].each do |file_source|
49
- file_destination = File.join(relative_destination, file_source.gsub(source, ''))
49
+ file_destination = File.join(given_destination, file_source.gsub(source, '.'))
50
50
 
51
51
  if File.directory?(file_source)
52
52
  base.empty_directory(file_destination, @log_status)
53
53
  elsif file_source !~ /\.empty_directory$/
54
- file_source.gsub!(base.source_root, '.')
55
-
56
54
  if file_source =~ /\.tt$/
57
55
  base.template(file_source, file_destination[0..-4], @log_status)
58
56
  else
@@ -8,7 +8,7 @@ class Thor
8
8
  # by Jonas Nicklas and Michael S. Klishin under MIT LICENSE.
9
9
  #
10
10
  class Templater #:nodoc:
11
- attr_reader :base, :source, :destination, :relative_destination
11
+ attr_reader :base, :source, :destination, :given_destination, :relative_destination
12
12
 
13
13
  # Initializes given the source and destination.
14
14
  #
@@ -86,20 +86,45 @@ class Thor
86
86
  !respond_to?(:render)
87
87
  end
88
88
 
89
- # Sets the source value from a relative source value.
89
+ # Sets the absolute source value from a relative source value. Notice
90
+ # that we need to take into consideration both the source_root as the
91
+ # relative_root.
92
+ #
93
+ # Let's suppose that we are on the directory "dest", with source root set
94
+ # to "source" and with the following scenario:
95
+ #
96
+ # inside "bar" do
97
+ # copy_file "baz.rb"
98
+ # end
99
+ #
100
+ # In this case, the user wants to copy the file at "source/bar/baz.rb"
101
+ # to "dest/bar/baz.rb". If we don't take into account the relative_root
102
+ # (in this case, "bar"), it would copy the contents at "source/baz.rb".
90
103
  #
91
104
  def source=(source)
92
105
  if source
93
- @source = ::File.expand_path(source.to_s, base.source_root)
106
+ @source = ::File.expand_path(source.to_s, File.join(base.source_root, base.relative_root))
94
107
  end
95
108
  end
96
109
 
97
- # Sets the destination value from a relative destination value. The
98
- # relative destination is kept to be used in output messages.
110
+ # Sets the absolute destination value from a relative destination value.
111
+ # It also stores the given and relative destination. Let's suppose our
112
+ # script is being executed on "dest", it sets the destination root to
113
+ # "dest". The destination, given_destination and relative_destination
114
+ # are related in the following way:
115
+ #
116
+ # inside "bar" do
117
+ # empty_directory "baz"
118
+ # end
119
+ #
120
+ # destination #=> dest/bar/baz
121
+ # relative_destination #=> bar/baz
122
+ # given_destination #=> baz
99
123
  #
100
124
  def destination=(destination)
101
125
  if destination
102
- @destination = ::File.expand_path(convert_encoded_instructions(destination.to_s), base.destination_root)
126
+ @given_destination = convert_encoded_instructions(destination.to_s)
127
+ @destination = ::File.expand_path(@given_destination, base.destination_root)
103
128
  @relative_destination = base.relative_to_absolute_root(@destination)
104
129
  end
105
130
  end
data/lib/thor/actions.rb CHANGED
@@ -82,12 +82,22 @@ class Thor
82
82
  @root_stack[0] = File.expand_path(root || '')
83
83
  end
84
84
 
85
+ # Gets the current root relative to the absolute root.
86
+ #
87
+ # inside "foo" do
88
+ # relative_root #=> "foo"
89
+ # end
90
+ #
91
+ def relative_root(remove_dot=true)
92
+ relative_to_absolute_root(root, remove_dot)
93
+ end
94
+
85
95
  # Returns the given path relative to the absolute root (ie, root where
86
96
  # the script started).
87
97
  #
88
98
  def relative_to_absolute_root(path, remove_dot=true)
89
99
  path = path.gsub(@root_stack[0], '.')
90
- remove_dot ? path[2..-1] : path
100
+ remove_dot ? (path[2..-1] || '') : path
91
101
  end
92
102
 
93
103
  # Get the source root in the class. Raises an error if a source root is
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: josevalim-thor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.10.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yehuda Katz