Class: CliTasks::Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/clitasks/commands.rb

Class Method Summary collapse

Class Method Details

.create(*args) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/clitasks/commands.rb', line 17

def create(*args)
  name = args.join ' '
  timestamp = Time.now.strftime('%Y%m%d%H%M%S')
  filename = "./stories/index/#{timestamp}.rb"

  FileUtils.mkdir_p("./stories/index")
  checklog("Creating '#{filename}'"){ IO.write(filename, template(name)) }
  checklog("Opening '#{filename}'"){ system(ENV['EDITOR'] || 'vim', filename) }
end

.edit(*args) ⇒ Object



4
5
6
7
# File 'lib/clitasks/commands.rb', line 4

def edit(*args)
  files = grep(*args)
  system(ENV['EDITOR'] || 'vim', *files)
end

.list(*args) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/clitasks/commands.rb', line 35

def list(*args)
  if args.any?
    Viewer.print *args
  else
    Viewer.print 'stories/index/*'
  end
end

.rebuildObject



27
28
29
# File 'lib/clitasks/commands.rb', line 27

def rebuild
  LinkBuilder.all
end

.search(*args) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/clitasks/commands.rb', line 9

def search(*args)
  if (args[0] || '').strip =~ /-(s|-simple)/i
    puts grep(*args.tap(&:shift))
  else
    Viewer.print(*grep(*args))
  end
end

.storiesObject



31
32
33
# File 'lib/clitasks/commands.rb', line 31

def stories
  @stories ||= World.instance.stories
end