-
-
Save mori-dev/911621 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Prerequisite: $ gem install bundler json | |
require 'rubygems' | |
require 'bundler' | |
require 'json' | |
require 'open-uri' | |
class Integer | |
def to_currency | |
self.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\1,').reverse | |
end | |
end | |
begin | |
Bundler.definition.dependencies.select{ |i| i.groups.include? :default }.each do |dependency| | |
json = JSON.parse(open("http://rubygems.org/api/v1/gems/#{dependency.name}.json").read) | |
name = json['name'] | |
authors = json['authors'] | |
downloads = json['downloads'].to_currency | |
project_uri = json['project_uri'] | |
doc_uri = json['documentation_uri'] | |
src_uri = json['source_code_uri'] | |
info = json['info'].split("\n").first.strip | |
puts name + ' (by ' + authors + ')' | |
puts 'Downloads: ' + downloads | |
puts 'Project : ' + project_uri if project_uri | |
puts 'Document : ' + doc_uri if doc_uri | |
puts 'Source : ' + src_uri if src_uri | |
puts info | |
puts '-' * 60 | |
end | |
rescue => e | |
puts "Error: #{e}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun gemref () | |
"編集中のファイルのプロジェクトで使われているGem情報を表示する" | |
(interactive) | |
(let* ((command "gemref") | |
(buffer "*gemref*")) | |
(when (get-buffer buffer) | |
(kill-buffer buffer)) | |
(get-buffer-create buffer) | |
(with-temp-directory (gemref-top-dir "Gemfile") | |
(call-process command nil buffer nil)) | |
(switch-to-buffer buffer))) | |
;;(global-set-key (kbd "M-h") 'gemref) | |
(defun gemref-top-dir (name &optional dir) | |
(interactive) | |
(let ((default-directory (file-name-as-directory (or dir default-directory)))) | |
(if (file-exists-p name) | |
(file-name-directory (expand-file-name name)) | |
(unless (string= "/" (directory-file-name default-directory)) | |
(gemref-top-dir name (expand-file-name ".." default-directory)))))) | |
(defmacro* with-temp-directory (dir &body body) | |
`(with-temp-buffer | |
(cd ,dir) | |
,@body)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gemref を emacs から使う。色付けはやめた。