Class: Rubu::Mark
- Inherits:
-
Object
- Object
- Rubu::Mark
- 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)
-
- (Object) base
readonly
Base name.
-
- (Object) dir
readonly
Absolute directory.
-
- (Object) ext
readonly
File extension.
-
- (Object) rdir
readonly
Relative directory.
-
- (Object) skip
Skip file in Step.
Class Method Summary (collapse)
-
+ (Object) glob(pattern)
Convert a list of file names matched with glob pattern to Marks.
-
+ (Object) list(files)
Convert a list of file names to Marks.
-
+ (Object) path(file_path)
Convert file path to Mark.
Instance Method Summary (collapse)
-
- (Object) [](key)
Get options with key.
-
- (Object) []=(key, val)
Set option.
-
- (Boolean) exist?
Does Mark exist?.
-
- (Mark) initialize(rdir, base, ext)
constructor
Create Mark object.
-
- (Object) path(ext = @ext)
Return absolute path.
-
- (Object) peer(rdir, ext, base = nil)
Return peer of Mark.
-
- (Object) rpath(ext = @ext)
Return relative path.
-
- (Object) set_opt(key, val)
Set option.
-
- (Object) time
Mark update time.
Constructor Details
- (Mark) initialize(rdir, base, ext)
Create Mark object.
336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/rubu.rb', line 336 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.
322 323 324 |
# File 'lib/rubu.rb', line 322 def base @base end |
- (Object) dir (readonly)
Absolute directory.
316 317 318 |
# File 'lib/rubu.rb', line 316 def dir @dir end |
- (Object) ext (readonly)
File extension.
325 326 327 |
# File 'lib/rubu.rb', line 325 def ext @ext end |
- (Object) rdir (readonly)
Relative directory.
319 320 321 |
# File 'lib/rubu.rb', line 319 def rdir @rdir end |
- (Object) skip
Skip file in Step.
328 329 330 |
# File 'lib/rubu.rb', line 328 def skip @skip end |
Class Method Details
+ (Object) glob(pattern)
Convert a list of file names matched with glob pattern to Marks.
310 311 312 |
# File 'lib/rubu.rb', line 310 def Mark.glob( pattern ) Mark.list( Dir.glob( pattern ) ) end |
+ (Object) list(files)
Convert a list of file names to Marks.
299 300 301 302 303 304 |
# File 'lib/rubu.rb', line 299 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.
287 288 289 290 291 292 293 294 |
# File 'lib/rubu.rb', line 287 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.
351 352 353 |
# File 'lib/rubu.rb', line 351 def []( key ) @opt[ key ] end |
- (Object) []=(key, val)
Set option.
356 357 358 |
# File 'lib/rubu.rb', line 356 def []=( key, val ) @opt[ key ] = val end |
- (Boolean) exist?
Does Mark exist?
391 392 393 |
# File 'lib/rubu.rb', line 391 def exist? File.exist?( path ) end |
- (Object) path(ext = @ext)
Return absolute path.
369 370 371 |
# File 'lib/rubu.rb', line 369 def path( ext = @ext ) "#{@dir.join('/')}/#{@base}#{ext}" end |
- (Object) peer(rdir, ext, base = nil)
Return peer of Mark.
385 386 387 388 |
# File 'lib/rubu.rb', line 385 def peer( rdir, ext, base = nil ) base ||= @base Mark.new( rdir, base, ext ) end |
- (Object) rpath(ext = @ext)
Return relative path.
376 377 378 |
# File 'lib/rubu.rb', line 376 def rpath( ext = @ext ) "#{@rdir.join('/')}/#{@base}#{ext}" end |
- (Object) set_opt(key, val)
Set option.
361 362 363 364 |
# File 'lib/rubu.rb', line 361 def set_opt( key, val ) @opt[ key ] = val self end |
- (Object) time
Mark update time.
396 397 398 |
# File 'lib/rubu.rb', line 396 def time File.stat( path ).mtime end |