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

#initialize(rdir, base, ext) ⇒ Mark

Create Mark object.

Parameters:

  • rdir

    Relative file path.

  • base

    Basename of file.

  • ext

    File extension (suffix).



333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/rubu.rb', line 333

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

#baseObject (readonly)

Base name.



319
320
321
# File 'lib/rubu.rb', line 319

def base
  @base
end

#dirObject (readonly)

Absolute directory.



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

def dir
  @dir
end

#extObject (readonly)

File extension.



322
323
324
# File 'lib/rubu.rb', line 322

def ext
  @ext
end

#rdirObject (readonly)

Relative directory.



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

def rdir
  @rdir
end

#skipObject

Skip file in Step.



325
326
327
# File 'lib/rubu.rb', line 325

def skip
  @skip
end

Class Method Details

.glob(pattern) ⇒ Object

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

Parameters:

  • pattern

    Glob pattern.



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

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

.list(files) ⇒ Object

Convert a list of file names to Marks.

Parameters:

  • files

    List of files to convert to Marks.



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

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

.path(file_path) ⇒ Object

Convert file path to Mark.

Parameters:

  • file_path

    Relative or absolute path of file.



284
285
286
287
288
289
290
291
# File 'lib/rubu.rb', line 284

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

#[](key) ⇒ Object

Get options with key.



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

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

#[]=(key, val) ⇒ Object

Set option.



353
354
355
# File 'lib/rubu.rb', line 353

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

#exist?Boolean

Does Mark exist?

Returns:

  • (Boolean)


388
389
390
# File 'lib/rubu.rb', line 388

def exist?
    File.exist?( path )
end

#path(ext = @ext) ⇒ Object

Return absolute path.

Parameters:

  • ext (defaults to: @ext)

    Use this extensions instead, if given.



366
367
368
# File 'lib/rubu.rb', line 366

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

#peer(rdir, ext, base = nil) ⇒ Object

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).



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

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

#rpath(ext = @ext) ⇒ Object

Return relative path.

Parameters:

  • ext (defaults to: @ext)

    Use this extensions instead, if given.



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

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

#set_opt(key, val) ⇒ Object

Set option.



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

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

#timeObject

Mark update time.



393
394
395
# File 'lib/rubu.rb', line 393

def time
    File.stat( path ).mtime
end