Class: Thor::Actions::Directory

Inherits:
EmptyDirectory show all
Defined in:
lib/thor/actions/directory.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes inherited from EmptyDirectory

#base, #config, #destination, #given_destination, #relative_destination

Instance Method Summary collapse

Methods inherited from EmptyDirectory

#convert_encoded_instructions, #exists?, #invoke_with_conflict_check, #on_conflict_behavior, #on_file_clash_behavior, #pretend?, #say_status

Constructor Details

#initialize(base, source, destination = nil, config = {}, &block) ⇒ Directory

Returns a new instance of Directory.



58
59
60
61
62
# File 'lib/thor/actions/directory.rb', line 58

def initialize(base, source, destination = nil, config = {}, &block)
  @source = File.expand_path(base.find_in_source_paths(source.to_s))
  @block  = block
  super(base, destination, {:recursive => true}.merge(config))
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



56
57
58
# File 'lib/thor/actions/directory.rb', line 56

def source
  @source
end

Instance Method Details

#execute!Object (protected)



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/thor/actions/directory.rb', line 75

def execute!
  lookup = Util.escape_globs(source)
  lookup = config[:recursive] ? File.join(lookup, "**") : lookup
  lookup = file_level_lookup(lookup)

  files(lookup).sort.each do |file_source|
    next if File.directory?(file_source)
    next if config[:exclude_pattern] && file_source.match(config[:exclude_pattern])
    file_destination = File.join(given_destination, file_source.gsub(source, "."))
    file_destination.gsub!("/./", "/")

    case file_source
    when /\.empty_directory$/
      dirname = File.dirname(file_destination).gsub(%r{/\.$}, "")
      next if dirname == given_destination
      base.empty_directory(dirname, config)
    when /#{TEMPLATE_EXTNAME}$/
      base.template(file_source, file_destination[0..-4], config, &@block)
    else
      base.copy_file(file_source, file_destination, config, &@block)
    end
  end
end

#file_level_lookup(previous_lookup) ⇒ Object (protected)



100
101
102
# File 'lib/thor/actions/directory.rb', line 100

def file_level_lookup(previous_lookup)
  File.join(previous_lookup, "{*,.[a-z]*}")
end

#files(lookup) ⇒ Object (protected)



104
105
106
# File 'lib/thor/actions/directory.rb', line 104

def files(lookup)
  Dir[lookup]
end

#invoke!Object



64
65
66
67
# File 'lib/thor/actions/directory.rb', line 64

def invoke!
  base.empty_directory given_destination, config
  execute!
end

#revoke!Object



69
70
71
# File 'lib/thor/actions/directory.rb', line 69

def revoke!
  execute!
end