Files

SugarHigh::FileExt::ClassMethods

Public Instance Methods

blank?(file_name) click to toggle source
# File lib/sugar-high/file_ext.rb, line 4
def blank? file_name
  raise ArgumentError, "Filename argument must not be blank" if file_name.blank?
  raise ArgumentError, "There is no file at: #{file_name}" if !File.file?(file_name)
  File.zero?(file_name)
end
has_content?(file_name, content_matcher, &block) click to toggle source
# File lib/sugar-high/file_ext.rb, line 10
def has_content? file_name, content_matcher, &block
  file = get_file file_name
  file.has_content? content_matcher, &block
end
read_content_from(file_name, options = {}) click to toggle source
Alias for: read_from
read_from(file_name, options = {}) click to toggle source
# File lib/sugar-high/file_ext.rb, line 15
def read_from file_name, options = {}, &block
  raise ArgumentError, "File to read from not found or not a file: #{file_name}" if !File.file? file_name
  content = File.read file_name

  if options[:before]
    begin
      regexp = options[:before].to_regexp
      index = content.match(regexp).offset_before
      content = content[0..index]
    rescue
      raise ArgumentError, ":before option must be a string or regular expression, was : #{options[:before]}"
    end
  end

  if options[:after]
    begin
      regexp = options[:after].to_regexp
      index = content.match(regexp).offset_after
      content = content[index..-1]
    rescue
      raise ArgumentError, ":after option must be a string or regular expression, was : #{options[:after]}"
    end
  end
  yield content if block
  content
end
with_content_from(file_name, options = {}) click to toggle source
Alias for: read_from

[Validate]

Generated with the Darkfish Rdoc Generator 2.