Class: TryRb::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/tryrb/cli.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.config=(value) ⇒ Object (writeonly)

Sets the attribute config

Parameters:

  • value

    the value to set the attribute config to.



8
9
10
# File 'lib/tryrb/cli.rb', line 8

def config=(value)
  @config = value
end

Class Method Details

.filename_extnameObject



26
27
28
# File 'lib/tryrb/cli.rb', line 26

def filename_extname
  '.rb'
end

.filename_prefixObject



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)
  expanded_path = File.expand_path(@config.tmp_dir)
  FileUtils.mkdir_p expanded_path unless Dir.exists?(expanded_path)
  File.join @config.tmp_dir, filename
rescue Errno::EEXIST => e
  abort "File #{e.message.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