Module: Richfile::Base

Defined in:
lib/richfile/base.rb

Overview

Methods to be included in File objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#sizeObject (readonly)

size of the file in bytes. see File#size



22
23
24
# File 'lib/richfile/base.rb', line 22

def size
  @size
end

Instance Method Details

#exists?Boolean

proxies File.exists?. This will always go to the real File.exists?, it will not be cached.

Returns:

  • (Boolean)


70
71
72
# File 'lib/richfile/base.rb', line 70

def exists?
  File.exists?(path)
end

#refresh!Object

refresh the Richfile added attributes. All the attributes referred once are loaded.



47
48
49
50
51
52
53
54
# File 'lib/richfile/base.rb', line 47

def refresh!
  self.size! if @size
  DIGESTS.each do |digest|
    d_downcase, d_sym, d_bang, d_var = Richfile.digest_variants(digest)
    send d_bang if (instance_variable_get(d_var))
  end
  self
end

#refresh_all!Object

refresh all attributes. All attributes wil be loaded, so all digests will be calculated. You will most probably never need this method.



59
60
61
62
63
64
65
66
# File 'lib/richfile/base.rb', line 59

def refresh_all!
  self.size!
  DIGESTS.each do |digest|
    d_downcase, d_sym, d_bang, d_var = Richfile.digest_variants(digest)
    send d_bang
  end
  self
end

#size!Object

refresh the size attribute.



81
82
83
84
# File 'lib/richfile/base.rb', line 81

def size!
  @size = nil
  self.size
end