Class: Cliff::Helpers
- Inherits:
-
Object
- Object
- Cliff::Helpers
- Defined in:
- lib/cliff.rb
Class Method Summary collapse
- .cache_file_name ⇒ Object
-
.copy(content) ⇒ Object
Copy content to clipboard.
- .fetch_languages ⇒ Object
- .is_language?(opt) ⇒ Boolean
- .load_languages_from_cache ⇒ Object
- .refresh_languages_cache ⇒ Object
Class Method Details
.cache_file_name ⇒ Object
43 44 45 |
# File 'lib/cliff.rb', line 43 def cache_file_name File.join(ENV['HOME'], ".friendpaste_languages") end |
.copy(content) ⇒ Object
Copy content to clipboard
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cliff.rb', line 66 def copy(content) case RUBY_PLATFORM when /darwin/ return content if `which pbcopy`.strip == '' IO.popen('pbcopy', 'r+') { |clip| clip.print content } when /linux/ return content if `which xclip 2> /dev/null`.strip == '' IO.popen('xclip', 'r+') { |clip| clip.print content } when /i386-cygwin/ return content if `which putclip`.strip == '' IO.popen('putclip', 'r+') { |clip| clip.print content } end content end |
.fetch_languages ⇒ Object
61 62 63 |
# File 'lib/cliff.rb', line 61 def fetch_languages open("#{fp_url}/_all_languages").read end |
.is_language?(opt) ⇒ Boolean
39 40 41 |
# File 'lib/cliff.rb', line 39 def is_language?(opt) Cliff.languages.flatten.include?(opt) end |
.load_languages_from_cache ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/cliff.rb', line 53 def load_languages_from_cache if File.exists?(cache_file_name) JSON.parse(File.read(cache_file_name)) else refresh_languages_cache end end |
.refresh_languages_cache ⇒ Object
47 48 49 50 51 |
# File 'lib/cliff.rb', line 47 def refresh_languages_cache languages = fetch_languages File.open(cache_file_name, 'w+') {|f| f.write(languages) } JSON.parse(languages) end |