Class: TryRb::CLI
- Inherits:
-
Object
- Object
- TryRb::CLI
- Defined in:
- lib/tryrb/cli.rb
Class Attribute Summary collapse
-
.config ⇒ Object
writeonly
Sets the attribute config.
Class Method Summary collapse
- .filename_extname ⇒ Object
- .filename_prefix ⇒ Object
- .fullpath(filename) ⇒ Object
- .get_filename(name) ⇒ Object
- .start(args) ⇒ Object
Class Attribute Details
.config=(value) ⇒ Object (writeonly)
Sets the attribute config
8 9 10 |
# File 'lib/tryrb/cli.rb', line 8 def config=(value) @config = value end |
Class Method Details
.filename_extname ⇒ Object
26 27 28 |
# File 'lib/tryrb/cli.rb', line 26 def filename_extname '.rb' end |
.filename_prefix ⇒ Object
22 23 24 |
# File 'lib/tryrb/cli.rb', line 22 def filename_prefix Time.now.strftime("%Y%m%d%H%M%S") end |
.fullpath(filename) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/tryrb/cli.rb', line 13 def fullpath(filename) filename = get_filename(filename) = File.(@config.tmp_dir) FileUtils.mkdir_p unless Dir.exists?() File.join @config.tmp_dir, filename rescue Errno::EEXIST => e abort "File #{e..split[-1]} exists. The tmp directory can't be created! Please delete the file first." end |
.get_filename(name) ⇒ Object
30 31 32 33 34 |
# File 'lib/tryrb/cli.rb', line 30 def get_filename(name) parts = [filename_prefix] parts << name.gsub(/\.rb$/, '') if name parts * '_' + filename_extname end |
.start(args) ⇒ Object
9 10 11 |
# File 'lib/tryrb/cli.rb', line 9 def start(args) system([@config.editor, fullpath(args[0])] * ' ') end |