Class: BBFlow::Misc
Class Method Summary collapse
- .edit(text = '') ⇒ String
-
.editor ⇒ Array<String>
Editor with arguments.
- .execute(*args) ⇒ String
- .git ⇒ Git::Base
- .open_url(url) ⇒ void
- .pluralize(word, count) ⇒ String
Class Method Details
.edit(text = '') ⇒ 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 |
.editor ⇒ Array<String>
Returns 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
24 25 26 |
# File 'lib/bb_flow/misc.rb', line 24 def execute(*args) Open3.popen3(*args) { |_i, o| return o.read } end |
.git ⇒ 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.
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
60 61 62 |
# File 'lib/bb_flow/misc.rb', line 60 def pluralize(word, count) count == 1 ? word : word + 's' end |