Class: Roast::Resources::FileResource

Inherits:
BaseResource show all
Defined in:
lib/roast/resources/file_resource.rb

Overview

Resource implementation for files

Instance Attribute Summary

Attributes inherited from BaseResource

#target

Instance Method Summary collapse

Methods inherited from BaseResource

#initialize

Constructor Details

This class inherits a constructor from Roast::Resources::BaseResource

Instance Method Details

#contentsObject



20
21
22
# File 'lib/roast/resources/file_resource.rb', line 20

def contents
  File.read(target) if exists?
end

#exists?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/roast/resources/file_resource.rb', line 16

def exists?
  File.exist?(target) && !Dir.exist?(target)
end

#nameObject



24
25
26
# File 'lib/roast/resources/file_resource.rb', line 24

def name
  File.basename(target) if target
end

#processObject



7
8
9
10
11
12
13
14
# File 'lib/roast/resources/file_resource.rb', line 7

def process
  # Handle glob patterns in the target
  if target.include?("*") || target.include?("?")
    Dir.glob(target).map { |f| File.expand_path(f) unless Dir.exist?(f) }.compact.join("\n")
  else
    File.expand_path(target)
  end
end

#typeObject



28
29
30
# File 'lib/roast/resources/file_resource.rb', line 28

def type
  :file
end