Module: SugarHigh::FileExt

Included in:
File
Defined in:
lib/sugar-high/file_ext.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

instance methods

Returns:



47
48
49
# File 'lib/sugar-high/file_ext.rb', line 47

def blank?
  File.zero?(self.path)
end

#has_content?(content_matcher = nil, &block) ⇒ Boolean

Returns:



51
52
53
54
55
56
57
58
59
60
# File 'lib/sugar-high/file_ext.rb', line 51

def has_content? content_matcher = nil, &block
  content_matcher ||= yield
  begin
    content_matcher = content_matcher.to_regexp
  rescue
    raise ArgumentError, "Content match must be specified as either a String or Regexp"
  end
  matched = self.read_content =~ content_matcher
  !(matched).nil?
end

#read_content(options = {}, &block) ⇒ Object Also known as: with_content



62
63
64
# File 'lib/sugar-high/file_ext.rb', line 62

def read_content options = {}, &block
  File.read_from self.path, options, &block
end