Method: Thor::Actions#apply

Defined in:
lib/thor/actions.rb

#apply(path, config = {}) ⇒ Object

Loads an external file and execute it in the instance binding.

Parameters

path<String>

The path to the file to execute. Can be a web address or a relative path from the source root.

Examples

apply "http://gist.github.com/103208"

apply "recipes/jquery.rb"


209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/thor/actions.rb', line 209

def apply(path, config = {})
  verbose = config.fetch(:verbose, true)
  is_uri  = path =~ %r{^https?\://}
  path    = find_in_source_paths(path) unless is_uri

  say_status :apply, path, verbose
  shell.padding += 1 if verbose

  if is_uri
    contents = open(path, "Accept" => "application/x-thor-template") { |io| io.read }
  else
    contents = open(path) { |io| io.read }
  end

  instance_eval(contents, path)
  shell.padding -= 1 if verbose
end

Comments