Module: Kanrisuru::Core::Path

Extended by:
OsPackage::Define
Defined in:
lib/kanrisuru/core/path.rb,
lib/kanrisuru/core/path/types.rb,
lib/kanrisuru/core/path/parsers/ls.rb,
lib/kanrisuru/core/path/commands/ls.rb,
lib/kanrisuru/core/path/commands/pwd.rb,
lib/kanrisuru/core/path/parsers/which.rb,
lib/kanrisuru/core/path/commands/which.rb,
lib/kanrisuru/core/path/commands/whoami.rb,
lib/kanrisuru/core/path/commands/readlink.rb,
lib/kanrisuru/core/path/commands/realpath.rb

Defined Under Namespace

Modules: Parser Classes: FileInfo, FileInfoId, FilePath, UserName

Instance Method Summary collapse

Methods included from OsPackage::Define

extended, os_define

Instance Method Details

#ls(opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/kanrisuru/core/path/commands/ls.rb', line 6

def ls(opts = {})
  path = opts[:path]
  all  = opts[:all]
  id   = opts[:id]

  command = Kanrisuru::Command.new('ls')
  command.append_flag('-i')
  command.append_flag('-l')
  command.append_flag('-a', all)
  command.append_flag('-n', id)

  command << (path || pwd.path)
  execute_shell(command)

  Kanrisuru::Result.new(command) do |cmd|
    Parser::Ls.parse(cmd, id)
  end
end

#pwdObject



6
7
8
9
10
11
12
13
# File 'lib/kanrisuru/core/path/commands/pwd.rb', line 6

def pwd
  command = Kanrisuru::Command.new('pwd')
  execute_shell(command)

  Kanrisuru::Result.new(command) do |cmd|
    FilePath.new(cmd.to_s)
  end
end


6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/kanrisuru/core/path/commands/readlink.rb', line 6

def readlink(path, opts = {})
  command = Kanrisuru::Command.new('readlink')
  command.append_flag('-f', opts[:canonicalize])
  command.append_flag('-e', opts[:canonicalize_existing])
  command.append_flag('-m', opts[:canonicalize_missing])

  command << path

  execute(command)

  Kanrisuru::Result.new(command) do |cmd|
    FilePath.new(cmd.to_s)
  end
end

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



6
7
8
9
10
11
12
13
14
15
# File 'lib/kanrisuru/core/path/commands/realpath.rb', line 6

def realpath(path, opts = {})
  command = Kanrisuru::Command.new("realpath #{path}")
  command.append_flag('-s', opts[:strip])

  execute(command)

  Kanrisuru::Result.new(command) do |cmd|
    FilePath.new(cmd.to_s)
  end
end

#which(program, opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/kanrisuru/core/path/commands/which.rb', line 6

def which(program, opts = {})
  command = Kanrisuru::Command.new('which')
  command.append_flag('-a', opts[:all])
  command << program

  execute_shell(command)

  Kanrisuru::Result.new(command) do |cmd|
    Parser::Which.parse(cmd)
  end
end

#whoamiObject



6
7
8
9
10
11
12
13
# File 'lib/kanrisuru/core/path/commands/whoami.rb', line 6

def whoami
  command = Kanrisuru::Command.new('whoami')
  execute_shell(command)

  Kanrisuru::Result.new(command) do |cmd|
    UserName.new(cmd.to_s)
  end
end