Module: ChefUtils::DSL::TrainHelpers

Extended by:
TrainHelpers
Includes:
Internal
Included in:
ChefUtils, Introspection, Service, TrainHelpers
Defined in:
lib/chef-utils/dsl/train_helpers.rb

Instance Method Summary collapse

Instance Method Details

#dir_exist?(path) ⇒ Boolean

Alias to easily convert Dir.exist to dir_exist

Returns:

  • (Boolean)


80
81
82
# File 'lib/chef-utils/dsl/train_helpers.rb', line 80

def dir_exist?(path)
  file_directory?(path)
end

#file_directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
75
76
77
# File 'lib/chef-utils/dsl/train_helpers.rb', line 71

def file_directory?(path)
  if __transport_connection
    __transport_connection.file(filename).directory?
  else
    File.directory?(path)
  end
end

#file_exist?(filename) ⇒ Boolean

Train wrapper around File.exist? to make it local mode aware.

Parameters:

  • filename

    filename to check

Returns:

  • (Boolean)

    if it exists



43
44
45
46
47
48
49
# File 'lib/chef-utils/dsl/train_helpers.rb', line 43

def file_exist?(filename)
  if __transport_connection
    __transport_connection.file(filename).exist?
  else
    File.exist?(filename)
  end
end

#file_open(*args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

XXX: modifications to the StringIO won’t get written back FIXME: this is very experimental and may be a bad idea and may break at any time



55
56
57
58
59
60
61
62
63
64
# File 'lib/chef-utils/dsl/train_helpers.rb', line 55

def file_open(*args, &block)
  if __transport_connection
    content = __transport_connection.file(args[0]).content
    string_io = StringIO.new content
    yield string_io if block_given?
    string_io
  else
    File.open(*args, &block)
  end
end

#file_read(path) ⇒ Object

Alias to easily convert IO.read / File.read to file_read



67
68
69
# File 'lib/chef-utils/dsl/train_helpers.rb', line 67

def file_read(path)
  file_open(path).read
end