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