Module: Kanrisuru::Core::Stat

Extended by:
OsPackage::Define
Defined in:
lib/kanrisuru/core/stat.rb,
lib/kanrisuru/core/stat/types.rb,
lib/kanrisuru/core/stat/parsers/stat.rb,
lib/kanrisuru/core/stat/commands/stat.rb

Defined Under Namespace

Modules: Parser Classes: FileStat

Instance Method Summary collapse

Methods included from OsPackage::Define

extended, os_define

Instance Method Details

#block_device?(path) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/kanrisuru/core/stat/commands/stat.rb', line 18

def block_device?(path)
  file_type?(path, 'block special file')
end

#char_device?(path) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/kanrisuru/core/stat/commands/stat.rb', line 22

def char_device?(path)
  file_type?(path, 'character special file')
end

#dir?(path) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/kanrisuru/core/stat/commands/stat.rb', line 6

def dir?(path)
  file_type?(path, 'directory')
end

#empty_file?(path) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/kanrisuru/core/stat/commands/stat.rb', line 14

def empty_file?(path)
  file_type?(path, 'regular empty file')
end

#file?(path) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/kanrisuru/core/stat/commands/stat.rb', line 10

def file?(path)
  file_type?(path, 'regular file')
end

#file_type?(path, type) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
# File 'lib/kanrisuru/core/stat/commands/stat.rb', line 37

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) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
# File 'lib/kanrisuru/core/stat/commands/stat.rb', line 30

def inode?(path)
  command = Kanrisuru::Command.new("stat #{path}")
  command.append_arg('-c', '%i')
  execute(command)
  command.success?
end

#stat(path, opts = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/kanrisuru/core/stat/commands/stat.rb', line 48

def stat(path, opts = {})
  command = Kanrisuru::Command.new('stat')
  command.append_flag('-L', opts[: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|
    Parser::Stat.parse(cmd)
  end
end

#symlink?(path) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/kanrisuru/core/stat/commands/stat.rb', line 26

def symlink?(path)
  file_type?(path, 'symbolic link')
end