Class: Rubu::Mark
- Inherits:
-
Object
- Object
- Rubu::Mark
- Defined in:
- lib/rubu.rb
Overview
Source or Target file for build commands. Rubu handles only Marks, and hence bare file names are not usable.
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.
Class Method Summary collapse
-
.glob(pattern) ⇒ Object
Convert a list of file names matched with 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.
-
#[]=(key, val) ⇒ Object
Set options.
-
#exist? ⇒ Boolean
Does Mark exist?.
-
#initialize(rdir, base, ext) ⇒ Mark
constructor
A new instance of Mark.
-
#path(ext = nil) ⇒ Object
Return absolute path.
-
#peer(rdir, ext, base = nil) ⇒ Object
Return peer of Mark.
-
#rpath(ext = nil) ⇒ Object
Return relative path.
-
#set_opt(key, val) ⇒ Object
Set options.
-
#time ⇒ Object
Mark creation time.
Constructor Details
#initialize(rdir, base, ext) ⇒ Mark
Returns a new instance of Mark.
299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/rubu.rb', line 299 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.
290 291 292 |
# File 'lib/rubu.rb', line 290 def base @base end |
#dir ⇒ Object (readonly)
Absolute directory.
284 285 286 |
# File 'lib/rubu.rb', line 284 def dir @dir end |
#ext ⇒ Object (readonly)
File extension.
293 294 295 |
# File 'lib/rubu.rb', line 293 def ext @ext end |
#rdir ⇒ Object (readonly)
Relative directory.
287 288 289 |
# File 'lib/rubu.rb', line 287 def rdir @rdir end |
#skip ⇒ Object
Skip file.
296 297 298 |
# File 'lib/rubu.rb', line 296 def skip @skip end |
Class Method Details
.glob(pattern) ⇒ Object
Convert a list of file names matched with pattern to Marks.
268 269 270 |
# File 'lib/rubu.rb', line 268 def Mark.glob( pattern ) Mark.list( Dir.glob( pattern ) ) end |
.list(files) ⇒ Object
Convert a list of file names to Marks.
260 261 262 263 264 265 |
# File 'lib/rubu.rb', line 260 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.
273 274 275 276 277 278 279 280 |
# File 'lib/rubu.rb', line 273 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.
314 315 316 |
# File 'lib/rubu.rb', line 314 def []( key ) @opt[ key ] end |
#[]=(key, val) ⇒ Object
Set options.
319 320 321 |
# File 'lib/rubu.rb', line 319 def []=( key, val ) @opt[ key ] = val end |
#exist? ⇒ Boolean
Does Mark exist?
348 349 350 |
# File 'lib/rubu.rb', line 348 def exist? File.exist?( path ) end |
#path(ext = nil) ⇒ Object
Return absolute path.
330 331 332 333 |
# File 'lib/rubu.rb', line 330 def path( ext = nil ) ext ||= @ext "#{@dir.join('/')}/#{@base}#{ext}" end |
#peer(rdir, ext, base = nil) ⇒ Object
Return peer of Mark.
342 343 344 345 |
# File 'lib/rubu.rb', line 342 def peer( rdir, ext, base = nil ) base ||= @base Mark.new( rdir, base, ext ) end |
#rpath(ext = nil) ⇒ Object
Return relative path.
336 337 338 339 |
# File 'lib/rubu.rb', line 336 def rpath( ext = nil ) ext ||= @ext "#{@rdir.join('/')}/#{@base}#{ext}" end |
#set_opt(key, val) ⇒ Object
Set options.
324 325 326 327 |
# File 'lib/rubu.rb', line 324 def set_opt( key, val ) @opt[ key ] = val self end |
#time ⇒ Object
Mark creation time.
353 354 355 |
# File 'lib/rubu.rb', line 353 def time File.stat( path ).mtime end |