Class: ZKSync::CryptoInode
- Inherits:
-
Object
- Object
- ZKSync::CryptoInode
- Defined in:
- lib/zksync/crypto_inode.rb
Instance Attribute Summary collapse
-
#atime ⇒ Object
Returns the value of attribute atime.
-
#ctime ⇒ Object
Returns the value of attribute ctime.
-
#ftype ⇒ Object
Returns the value of attribute ftype.
-
#gid ⇒ Object
Returns the value of attribute gid.
-
#index ⇒ Object
Returns the value of attribute index.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#mtime ⇒ Object
Returns the value of attribute mtime.
-
#path ⇒ Object
Returns the value of attribute path.
-
#sha256 ⇒ Object
Returns the value of attribute sha256.
-
#size ⇒ Object
Returns the value of attribute size.
-
#uid ⇒ Object
Returns the value of attribute uid.
Instance Method Summary collapse
- #equals(other) ⇒ Object
-
#initialize(arg) ⇒ CryptoInode
constructor
A new instance of CryptoInode.
- #inode_width ⇒ Object
- #set_from_fs(fs_path, opts = {}) ⇒ Object
- #slots_used ⇒ Object
- #to_h ⇒ Object
- #to_json ⇒ Object
-
#to_s ⇒ Object
string is json right-space-padded to a multiple of inode_width, so we can reuse lines in @@index.
Constructor Details
#initialize(arg) ⇒ CryptoInode
Returns a new instance of CryptoInode.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/zksync/crypto_inode.rb', line 22 def initialize(arg) if arg.is_a?(String) @path = arg else arg.each do |k,v| v = Time.parse(v) if [:atime, :mtime].include?(k.to_sym) self.send(:"#{k}=", v) end end end |
Instance Attribute Details
#atime ⇒ Object
Returns the value of attribute atime.
20 21 22 |
# File 'lib/zksync/crypto_inode.rb', line 20 def atime @atime end |
#ctime ⇒ Object
Returns the value of attribute ctime.
20 21 22 |
# File 'lib/zksync/crypto_inode.rb', line 20 def ctime @ctime end |
#ftype ⇒ Object
Returns the value of attribute ftype.
20 21 22 |
# File 'lib/zksync/crypto_inode.rb', line 20 def ftype @ftype end |
#gid ⇒ Object
Returns the value of attribute gid.
20 21 22 |
# File 'lib/zksync/crypto_inode.rb', line 20 def gid @gid end |
#index ⇒ Object
Returns the value of attribute index.
20 21 22 |
# File 'lib/zksync/crypto_inode.rb', line 20 def index @index end |
#mode ⇒ Object
Returns the value of attribute mode.
20 21 22 |
# File 'lib/zksync/crypto_inode.rb', line 20 def mode @mode end |
#mtime ⇒ Object
Returns the value of attribute mtime.
20 21 22 |
# File 'lib/zksync/crypto_inode.rb', line 20 def mtime @mtime end |
#path ⇒ Object
Returns the value of attribute path.
20 21 22 |
# File 'lib/zksync/crypto_inode.rb', line 20 def path @path end |
#sha256 ⇒ Object
Returns the value of attribute sha256.
20 21 22 |
# File 'lib/zksync/crypto_inode.rb', line 20 def sha256 @sha256 end |
#size ⇒ Object
Returns the value of attribute size.
20 21 22 |
# File 'lib/zksync/crypto_inode.rb', line 20 def size @size end |
#uid ⇒ Object
Returns the value of attribute uid.
20 21 22 |
# File 'lib/zksync/crypto_inode.rb', line 20 def uid @uid end |
Instance Method Details
#equals(other) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/zksync/crypto_inode.rb', line 62 def equals(other) [ :path, :mtime, :ctime, :atime, :mode, :uid, :gid, :size, :ftype, :sha256 ].each do |key| return false unless self.send(key) == other.send(key) end true end |
#inode_width ⇒ Object
33 34 35 |
# File 'lib/zksync/crypto_inode.rb', line 33 def inode_width CryptoFileIndex.inode_width end |
#set_from_fs(fs_path, opts = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/zksync/crypto_inode.rb', line 41 def set_from_fs(fs_path, opts={}) stat = File.stat(fs_path) @fs_path = fs_path @atime = stat.atime @mtime = stat.mtime @ctime = stat.ctime @ftype = stat.ftype @gid = stat.gid @mode = stat.mode @size = stat.ftype == "directory" ? 0 : stat.size @uid = stat.uid sha256 if opts[:hash] end |
#slots_used ⇒ Object
37 38 39 |
# File 'lib/zksync/crypto_inode.rb', line 37 def slots_used (to_s.length.to_f/inode_width).ceil end |
#to_h ⇒ Object
70 71 72 |
# File 'lib/zksync/crypto_inode.rb', line 70 def to_h { path:path, mtime:mtime, ctime:ctime, atime:atime, mode:mode, uid:uid, gid:gid, size:size, ftype:ftype, sha256:sha256 } end |
#to_json ⇒ Object
74 75 76 |
# File 'lib/zksync/crypto_inode.rb', line 74 def to_json to_h.to_json end |
#to_s ⇒ Object
string is json right-space-padded to a multiple of inode_width, so we can reuse lines in @@index
79 80 81 82 |
# File 'lib/zksync/crypto_inode.rb', line 79 def to_s json = to_json json.length.to_s + "|" + json end |