Class: Jenkins::FilePath

Inherits:
Object
  • Object
show all
Defined in:
lib/jenkins/filepath.rb

Defined Under Namespace

Classes: Stat

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(native) ⇒ FilePath

Returns a new instance of FilePath.



9
10
11
# File 'lib/jenkins/filepath.rb', line 9

def initialize(native)
  @native = native
end

Instance Attribute Details

#natvieObject (readonly)

Returns the value of attribute natvie.



7
8
9
# File 'lib/jenkins/filepath.rb', line 7

def natvie
  @natvie
end

Instance Method Details

#+(name) ⇒ Object

Ruby’s Pathname internace



15
16
17
# File 'lib/jenkins/filepath.rb', line 15

def +(name)
  FilePath.new(@native.child(name))
end

#basenameObject

TODO: utime



59
60
61
# File 'lib/jenkins/filepath.rb', line 59

def basename
  FilePath.new(create_filepath(@native.getName()))
end

#chmod(mask) ⇒ Object



42
43
44
# File 'lib/jenkins/filepath.rb', line 42

def chmod(mask)
  @native.chmod(mask)
end

#deleteObject Also known as: unlink



101
102
103
# File 'lib/jenkins/filepath.rb', line 101

def delete
  @native.delete()
end

#directory?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/jenkins/filepath.rb', line 70

def directory?
  @native.isDirectory()
end

#each_entry(&block) ⇒ Object

TODO: rmdir TODO: opendir



95
96
97
98
99
# File 'lib/jenkins/filepath.rb', line 95

def each_entry(&block)
  entries.each do |child|
    yield child
  end
end

#entriesObject



82
83
84
85
86
# File 'lib/jenkins/filepath.rb', line 82

def entries
  @native.list().map { |native|
    FilePath.new(native)
  }
end

#exist?Boolean

TODO: dirname TODO: extname

Returns:

  • (Boolean)


66
67
68
# File 'lib/jenkins/filepath.rb', line 66

def exist?
  @native.exists()
end

#file?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/jenkins/filepath.rb', line 74

def file?
  !directory?
end

#join(*names) ⇒ Object



19
20
21
# File 'lib/jenkins/filepath.rb', line 19

def join(*names)
  FilePath.new names.inject(@native) {|native, name| native.child(name) }
end

#mkdirObject



88
89
90
# File 'lib/jenkins/filepath.rb', line 88

def mkdir
  @native.mkdirs
end

#mtimeObject

TODO: atime jnr-posix? TODO: ctime jnr-posix?



38
39
40
# File 'lib/jenkins/filepath.rb', line 38

def mtime
  Time.at(@native.lastModified().to_f / 1000)
end

#parentObject

TODO: hudson.FilePath does not handle FilePath(“.”).parent since it scans the last “/” for file, the 2nd last “/” for directory. Can Jenkins handle new FilePatn(ch, “../..”) correctly?



113
114
115
116
# File 'lib/jenkins/filepath.rb', line 113

def parent
  parent = Pathname.new(to_s).parent.to_s
  FilePath.new(Java.hudson.FilePath.new(@native.getChannel(), parent))
end

#read(*args) ⇒ Object



31
32
33
# File 'lib/jenkins/filepath.rb', line 31

def read(*args)
  @native.read.to_io.read(*args)
end

#realpathObject



27
28
29
# File 'lib/jenkins/filepath.rb', line 27

def realpath
  @native.absolutize().getRemote()
end

#remote?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/jenkins/filepath.rb', line 124

def remote?
  @native.isRemote()
end

#rename(to) ⇒ Object

TODO: chown TODO: open



49
50
51
# File 'lib/jenkins/filepath.rb', line 49

def rename(to)
  @native.renameTo(create_filepath(to))
end

#rmtreeObject



106
107
108
# File 'lib/jenkins/filepath.rb', line 106

def rmtree
  @native.deleteRecursive()
end

#sizeObject



78
79
80
# File 'lib/jenkins/filepath.rb', line 78

def size
  @native.length()
end

#statObject



53
54
55
# File 'lib/jenkins/filepath.rb', line 53

def stat
  Stat.new(size, @native.mode(), mtime)
end

#to_sObject



23
24
25
# File 'lib/jenkins/filepath.rb', line 23

def to_s
  @native.getRemote()
end

#touch(time) ⇒ Object

Original interface



120
121
122
# File 'lib/jenkins/filepath.rb', line 120

def touch(time)
  @native.touch(time.to_i * 1000)
end