Class: BBFlow::Misc

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/bb_flow/misc.rb

Class Method Summary collapse

Class Method Details

.edit(text = '') ⇒ String

Parameters:

  • text (String) (defaults to: '')

Returns:

  • (String)


31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bb_flow/misc.rb', line 31

def edit(text = '')
  file = Tempfile.new(%w(bb-flow .md))
  file.write(text)
  file.flush

  system(*[*Misc.editor, file.path])

  File.read(file.path)
ensure
  file.close
  file.unlink
end

.editorArray<String>

Returns editor with arguments.

Returns:

  • (Array<String>)

    editor with arguments.



52
53
54
# File 'lib/bb_flow/misc.rb', line 52

memoize def editor
  [`git config --global core.editor`.chomp.split(/\s+/), ['vi']].reject(&:empty?).first
end

.execute(*args) ⇒ String

Parameters:

  • args (Array<Object>)

Returns:

  • (String)


24
25
26
# File 'lib/bb_flow/misc.rb', line 24

def execute(*args)
  Open3.popen3(*args) { |_i, o| return o.read }
end

.gitGit::Base

Returns:

  • (Git::Base)


45
46
47
48
49
# File 'lib/bb_flow/misc.rb', line 45

memoize def git
  Git.open(Dir.pwd)
rescue ArgumentError
  Printer.panic("This directory (#{__dir__}) is not a git repository.")
end

.open_url(url) ⇒ void

This method returns an undefined value.

Parameters:

  • url (String)


11
12
13
14
15
16
17
18
19
# File 'lib/bb_flow/misc.rb', line 11

def open_url(url)
  if Gem::Platform.local.os == 'darwin'
    execute("open #{url}")
  else
    # FIXME: I'm not sure what's the proper way to open URLs on either Linux
    #        or Windows. If it's important for you, don't hesitate to edit.
    puts(url)
  end
end

.pluralize(word, count) ⇒ String

Parameters:

  • word (String)
  • count (Fixnum)

Returns:

  • (String)


60
61
62
# File 'lib/bb_flow/misc.rb', line 60

def pluralize(word, count)
  count == 1 ? word : word + 's'
end