module Kanrisuru::Core::Stat
Constants
- FileStat
Public Instance Methods
block_device?(path)
click to toggle source
# File lib/kanrisuru/core/stat.rb, line 38 def block_device?(path) file_type?(path, 'block special file') end
char_device?(path)
click to toggle source
# File lib/kanrisuru/core/stat.rb, line 42 def char_device?(path) file_type?(path, 'character special file') end
dir?(path)
click to toggle source
# File lib/kanrisuru/core/stat.rb, line 26 def dir?(path) file_type?(path, 'directory') end
empty_file?(path)
click to toggle source
# File lib/kanrisuru/core/stat.rb, line 34 def empty_file?(path) file_type?(path, 'regular empty file') end
file?(path)
click to toggle source
# File lib/kanrisuru/core/stat.rb, line 30 def file?(path) file_type?(path, 'regular file') end
file_type?(path, type)
click to toggle source
# File lib/kanrisuru/core/stat.rb, line 57 def file_type?(path, type) command = Kanrisuru::Command.new("stat #{path}") command.append_arg('-c', '%F') execute(command) result = Kanrisuru::Result.new(command, &:to_s) result.success? ? result.data == type : false end
inode?(path)
click to toggle source
# File lib/kanrisuru/core/stat.rb, line 50 def inode?(path) command = Kanrisuru::Command.new("stat #{path}") command.append_arg('-c', '%i') execute(command) command.success? end
stat(path, opts = {})
click to toggle source
# File lib/kanrisuru/core/stat.rb, line 68 def stat(path, opts = {}) follow = opts[:follow] command = Kanrisuru::Command.new('stat') command.append_flag('-L', follow) command.append_arg('-c', '%A,%b,%D,%F,%g,%G,%h,%i,%n,%s,%u,%U,%x,%y,%z') command << path execute(command) Kanrisuru::Result.new(command) do |cmd| string = cmd.to_s values = string.split(',') FileStat.new( Kanrisuru::Mode.new(values[0]), values[1].to_i, values[2], values[3], values[4].to_i, values[5], values[6].to_i, values[7].to_i, values[8], values[9].to_i, values[10].to_i, values[11], values[12] ? DateTime.parse(values[12]) : nil, values[13] ? DateTime.parse(values[13]) : nil, values[14] ? DateTime.parse(values[14]) : nil ) end end
symlink?(path)
click to toggle source
# File lib/kanrisuru/core/stat.rb, line 46 def symlink?(path) file_type?(path, 'symbolic link') end