https://github.com/adamsanderson/qwandry

qwandry 能高速定位到我们须要找到 库文件, 项目 的工具。

Ruby中实现高速定位的方法有好多种。我知道的有三个:

  1. 使用bundle

    命令是

    cd `bundle show activerecord`

    这种方法不方便的地方是 仅仅能在支持bundle的环境下执行,并且仅仅能打开指定的gem文件夹

  2. 通过tag方法(tag 定位更精确,能够定位到方法级别)



    局限:  仅仅能在相应的编辑器里执行
  3. 或者通过 qwandry

安装

gem install qwandry

使用

qw matrix        # opens ruby's matrix class in your editor
qw rails # will ask you which version of rails you want to open
qw activerec 3.1 # will find the gem activerecord 3.1 and open it
You can also use Qwandry with other common languages:
qw -r python numpy # opens python's numpy library
qw -r perl URI # open perl's URI library
qw -r node express # open express if it is installed for node



指定编辑器打开

EDITOR=subl qw activerecord 3.2.14

怎样自己定义?

touch ~/.qwandry/init.rb

然后copy例如以下内容到文件里

register 'projects' do
add 'your project path'
end default :ruby, :gem, :projects

解释



register 方法是 将指定的文件夹打包

add 将文件夹增加到搜索中 



default 是设置默认的搜索范围

实现的基本原理

  1. 通过配置 config 将非常多文件夹打包成 Package, 然后将 Package 打包成 Repository(仓库)
  2. 初始化一个Launcher(有Editor等)
  3. 依据输入的名称找到相应的Repository中的package(实际上是一个文件夹地址)
  4. 运行系统命令: editor(vim) path

源码分析

qwandry中比較重要的几个类

Repository

是一个基类,职责是存储全部的能够搜索的库文件夹和名称. 继承与它的子类必须实现  scan 方法。

它有两个子类: LibraryRepository 和 FlatRepository

Configuration

是一个用于配置搜索库的文件夹的类,能够动态的加入新的搜索路径。 实现的方法比較track, 用的是万恶得 eval 方法。

Launcher

是用于打开指定文件夹的关键类。它有两个关键方法: find 和  launch

find方法的实现

    # Searches all of the loaded repositories for `name`
def find(*pattern)
# Create a glob pattern from the user's input, for instance
# ["rails","2.3"] => "rails*2.3*"
pattern = pattern.join('*')
pattern << '*' unless pattern =~ /\*$/ packages = []
repositories = Qwandry::Configuration.repositories
repositories.each do |repo|
packages.concat(repo.scan(pattern))
end differentiate packages
packages
end

就是从仓库中找到合适得 Package

launch 方法的实现

    # Launches a Package or path represented by a String. Unless `editor` will
# check against the environment by default.
def launch(package, editor=nil)
editor ||= @editor || ENV['QWANDRY_EDITOR'] || ENV['VISUAL'] || ENV['EDITOR'] if (!editor) || (editor =~ /^\s*$/) # if the editor is not set, or is blank, exit with a message:
puts "Please set QWANDRY_EDITOR, VISUAL or EDITOR, or pass in an editor to use"
exit 1
end paths = package.is_a? (String) ? [package] : package.paths
# Editors may have options, 'mate -w' for instance
editor_and_options = editor.strip.split(/\s+/) Dir.chdir(File.dirname paths.first) do
# Launch the editor with its options and any paths that we have been passed
system(*(editor_and_options + paths))
end
end

主要的思路就是找到相应的editor打开指定的文件夹,打开文件夹的方法非常easy

system(*(editor_and_options + paths))

最新文章

  1. 安卓ApiDemos最简单的使用方法
  2. 如何在eclipse中通过Juit进行单元测试
  3. 2015-SH项目总结
  4. idea intellij 混淆anroid代码
  5. APS-C画幅与全画幅
  6. C语言运算符优先级和口诀(转)
  7. C# String.split()用法小结。String.Split 方法 (String[], StringSplitOptions)
  8. 100803C
  9. POJ 1947Rebuilding Roads(树形DP + 01背包)
  10. 快排java实现
  11. [Shell]字符截取命令:cut, printf, awk, sed
  12. 详解JavaScript函数模式
  13. java导出txt文本
  14. 夺命雷公狗---DEDECMS----13dedecms首页的完成
  15. linux 获取cpu 个数
  16. 新发现一个函数:GradientFill
  17. final使用
  18. Spring+IOC(DI)+AOP概念及优缺点
  19. 笔记:Maven 生命周期与命令行详解
  20. Matlab绘图基础——散点生成三角网(TIN)

热门文章

  1. php简单测试slim框架的功能
  2. A - George and Accommodation
  3. Spark Streaming概念学习系列之SparkStreaming性能调优
  4. VCRuntime静默安装
  5. webpack-1
  6. Codeforces Round #450
  7. python课程设计笔记(四)整数、浮点数与字符串 time库
  8. 【Oracle】创建概要文件
  9. 基于Nginx服务的用户认证
  10. Java中面向对象三大特性之——封装