Class: Rubu::Mark

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

Overview

Source or Target file for Step commands. Rubu handles only Marks, and hence bare file names are not usable.

Mark includes both relative and absolute paths for the file.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Mark) initialize(rdir, base, ext)

Create Mark object.

Parameters:

  • rdir

    Relative file path.

  • base

    Basename of file.

  • ext

    File extension (suffix).



324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/rubu.rb', line 324

def initialize( rdir, base, ext )
    if rdir.kind_of? Array
        @dir = File.absolute_path( rdir.join( '/' ) ).split( '/' )
        @rdir = rdir
    else
        @dir = File.absolute_path( rdir ).split( '/' )
        @rdir = rdir.split( '/' )
    end
    @ext = ext
    @base = base
    @opt = {}
    @skip = false
end

Instance Attribute Details

- (Object) base (readonly)

Base name.



310
311
312
# File 'lib/rubu.rb', line 310

def base
  @base
end

- (Object) dir (readonly)

Absolute directory.



304
305
306
# File 'lib/rubu.rb', line 304

def dir
  @dir
end

- (Object) ext (readonly)

File extension.



313
314
315
# File 'lib/rubu.rb', line 313

def ext
  @ext
end

- (Object) rdir (readonly)

Relative directory.



307
308
309
# File 'lib/rubu.rb', line 307

def rdir
  @rdir
end

- (Object) skip

Skip file in Step.



316
317
318
# File 'lib/rubu.rb', line 316

def skip
  @skip
end

Class Method Details

+ (Object) glob(pattern)

Convert a list of file names matched with glob pattern to Marks.

Parameters:

  • pattern

    Glob pattern.



298
299
300
# File 'lib/rubu.rb', line 298

def Mark.glob( pattern )
    Mark.list( Dir.glob( pattern ) )
end

+ (Object) list(files)

Convert a list of file names to Marks.

Parameters:

  • files

    List of files to convert to Marks.



287
288
289
290
291
292
# File 'lib/rubu.rb', line 287

def Mark.list( files )
    unless files.kind_of? Array
        files = [ files ]
    end
    files.map{ |file| Mark.path( file ) }
end

+ (Object) path(file_path)

Convert file path to Mark.

Parameters:

  • file_path

    Relative or absolute path of file.



275
276
277
278
279
280
281
282
# File 'lib/rubu.rb', line 275

def Mark.path( file_path )
    path = File.absolute_path( file_path )
    dir = File.dirname( path ).split( '/' )
    rdir = dir - Dir.pwd.split( '/' )
    ext = File.extname( path )
    base = File.basename( path, ext )
    Mark.new( rdir, base, ext )
end

Instance Method Details

- (Object) [](key)

Get options with key.



339
340
341
# File 'lib/rubu.rb', line 339

def []( key )
    @opt[ key ]
end

- (Object) []=(key, val)

Set option.



344
345
346
# File 'lib/rubu.rb', line 344

def []=( key, val )
    @opt[ key ] = val
end

- (Boolean) exist?

Does Mark exist?

Returns:

  • (Boolean)


379
380
381
# File 'lib/rubu.rb', line 379

def exist?
    File.exist?( path )
end

- (Object) path(ext = @ext)

Return absolute path.

Parameters:

  • ext (defaults to: @ext)

    Use this extensions instead, if given.



357
358
359
# File 'lib/rubu.rb', line 357

def path( ext = @ext )
    "#{@dir.join('/')}/#{@base}#{ext}"
end

- (Object) peer(rdir, ext, base = nil)

Return peer of Mark.

Parameters:

  • rdir

    Relative path of peer.

  • ext

    Extension of peer.

  • base (defaults to: nil)

    Optional basename of peer (use original if not given).



373
374
375
376
# File 'lib/rubu.rb', line 373

def peer( rdir, ext, base = nil )
    base ||= @base
    Mark.new( rdir, base, ext )
end

- (Object) rpath(ext = @ext)

Return relative path.

Parameters:

  • ext (defaults to: @ext)

    Use this extensions instead, if given.



364
365
366
# File 'lib/rubu.rb', line 364

def rpath( ext = @ext )
    "#{@rdir.join('/')}/#{@base}#{ext}"
end

- (Object) set_opt(key, val)

Set option.



349
350
351
352
# File 'lib/rubu.rb', line 349

def set_opt( key, val )
    @opt[ key ] = val
    self
end

- (Object) time

Mark update time.



384
385
386
# File 'lib/rubu.rb', line 384

def time
    File.stat( path ).mtime
end