reditor 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35bee5c62877ca050e26ad2d340b1db648ab3ee9
4
- data.tar.gz: c54e40dde0e6f8fe6a6c60b040d02fe38f8fd247
3
+ metadata.gz: 08dc51f8ec9fddc219f8e5a0237593bb66ec6a16
4
+ data.tar.gz: 4ecdd9976fc3a8373015ef3458ae344048f50298
5
5
  SHA512:
6
- metadata.gz: 7096bb557e3cfe6aac7fc7632c5aa533cae42bddff69cafb1b4065cc7eea0f8750b3f75bf2ef2f51538d0fd8c06667973ff39c4e5a341d68624fd85f6b137381
7
- data.tar.gz: a7e4cddc1c9701a4380ad1257e73d24829a3f08998e7bd775814e9ac36fdf162e235f9579022201f7ae94a520c4ecfdec308f6b999a42e83307af0dbbde3ba9d
6
+ metadata.gz: 161cca83d6088e6492df71b7714280c9c59f20b7f477f4750366ad69a1e0da998873a751e6e9198a48288afaf61a8e5cd5a8d56af97b88d9532222e55604df80
7
+ data.tar.gz: fef80fba2bb1fbef96fbe53e5c594d5c5770fd4558337872f2784916f2baa95f9207b6eaf6a126a2486e27fb138f6c26cd4e917e0288cee5d271566dc2b60a44
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - '1.9.3'
3
+ - '2.0.0'
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Reditor
1
+ # Reditor [![Build Status](https://travis-ci.org/hibariya/reditor.png?branch=master)](https://travis-ci.org/hibariya/reditor)
2
2
 
3
3
  Reditor provides `reditor` command.
4
4
 
@@ -3,8 +3,8 @@ require 'rubygems'
3
3
  module Reditor
4
4
  class LibraryNotFound < LoadError; end
5
5
 
6
- autoload :LibraryLocator, 'reditor/library_locator'
7
- autoload :CandidatesLocator, 'reditor/candidates_locator'
8
- autoload :Command, 'reditor/command'
9
- autoload :VERSION, 'reditor/version'
6
+ autoload :LibraryLocator, 'reditor/library_locator'
7
+ autoload :LibrarySearchQuery, 'reditor/library_search_query'
8
+ autoload :Command, 'reditor/command'
9
+ autoload :VERSION, 'reditor/version'
10
10
  end
@@ -36,9 +36,8 @@ module Reditor
36
36
  say "Reditor version #{VERSION}"
37
37
  end
38
38
 
39
- # XXX FIXME: a more better implementation
40
39
  def method_missing(name, *args, &block)
41
- send :open, name
40
+ open name
42
41
  end
43
42
 
44
43
  private
@@ -59,16 +58,16 @@ module Reditor
59
58
  end
60
59
 
61
60
  def choose_exec(name, &block)
62
- candidates = CandidatesLocator.detect(name)
61
+ names = LibrarySearchQuery.search(name)
63
62
 
64
- candidates.each.with_index do |candidate, i|
65
- say "[#{i}] #{candidate}"
63
+ names.each.with_index do |name, i|
64
+ say "[#{i}] #{name}"
66
65
  end
67
- print "Choose number of library [0]> "
66
+ print 'Choose number of library [0]> '
68
67
 
69
68
  abort_reditor unless num = $stdin.gets
70
69
 
71
- detect_exec candidates[num.to_i], &block
70
+ detect_exec names[num.to_i], &block
72
71
  rescue Interrupt
73
72
  abort_reditor
74
73
  end
@@ -1,4 +1,5 @@
1
1
  require 'pathname'
2
+ require 'bundler'
2
3
 
3
4
  # TODO: care version specification
4
5
  module Reditor
@@ -18,12 +19,11 @@ module Reditor
18
19
  end
19
20
 
20
21
  def detect_from_bundler
21
- require 'bundler'
22
-
23
22
  return nil unless spec = Bundler.load.specs.find {|spec| spec.name == name }
24
23
 
25
- Pathname.new(spec.full_gem_path)
24
+ Pathname(spec.full_gem_path)
26
25
  rescue NameError, Bundler::GemNotFound, Bundler::GemfileNotFound
26
+ # NOP (probably it's not available bundler project)
27
27
  end
28
28
 
29
29
  def detect_from_loadpath
@@ -32,15 +32,16 @@ module Reditor
32
32
  $LOAD_PATH.map {|path|
33
33
  full_path = File.expand_path(path + '/' + basename)
34
34
 
35
- Pathname.new(full_path)
35
+ Pathname(full_path)
36
36
  }.detect(&:exist?)
37
37
  end
38
38
 
39
39
  def detect_from_gem
40
40
  spec = Gem::Specification.find_by_name(name)
41
41
 
42
- Pathname.new(spec.full_gem_path)
42
+ Pathname(spec.full_gem_path)
43
43
  rescue Gem::LoadError
44
+ # NOP (Gem couldn't find #{name} gem)
44
45
  end
45
46
  end
46
47
  end
@@ -0,0 +1,67 @@
1
+ require 'pathname'
2
+ require 'hotwater'
3
+ require 'bundler'
4
+
5
+ module Reditor
6
+ class LibrarySearchQuery
7
+ def self.search(query, limit = 20)
8
+ new(query).search(limit)
9
+ end
10
+
11
+ def initialize(query)
12
+ @query = query.to_s
13
+
14
+ quoted = Regexp.quote(@query)
15
+ @substr_pattern = /^#{quoted}|#{quoted}$/i
16
+ @partial_pattern = /#{quoted}/i
17
+ end
18
+
19
+ def search(limit)
20
+ available_libraries.sort_by {|name|
21
+ indexes_with_match(name) + indexes_with_distance(name)
22
+ }.take(limit)
23
+ end
24
+
25
+ def available_libraries
26
+ @available_libraries ||= (
27
+ availables_from_loadpath +
28
+ availables_from_gem +
29
+ availables_from_bundler
30
+ ).uniq
31
+ end
32
+
33
+ private
34
+
35
+ def indexes_with_match(name)
36
+ words = name.split(/-_/)
37
+ substr_count = words.grep(@substr_pattern).count
38
+ partial_count = words.grep(@partial_pattern).count
39
+
40
+ [-substr_count, -partial_count]
41
+ end
42
+
43
+ def indexes_with_distance(name)
44
+ [Hotwater.damerau_levenshtein_distance(@query, name)]
45
+ end
46
+
47
+ def availables_from_bundler
48
+ Bundler.load.specs.map(&:name)
49
+ rescue NameError, Bundler::GemNotFound, Bundler::GemfileNotFound
50
+ []
51
+ end
52
+
53
+ def availables_from_gem
54
+ Gem::Specification.map(&:name)
55
+ rescue Gem::LoadError
56
+ []
57
+ end
58
+
59
+ def availables_from_loadpath
60
+ $LOAD_PATH.each_with_object([]) {|path, availables|
61
+ Pathname(File.expand_path(path)).entries.each do |entry|
62
+ availables << entry.basename('.rb').to_s if entry.extname == '.rb'
63
+ end
64
+ }
65
+ end
66
+ end
67
+ end
@@ -1,3 +1,3 @@
1
1
  module Reditor
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -4,7 +4,7 @@ require File.expand_path('../lib/reditor/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ['hibariya']
6
6
  gem.email = ['celluloid.key@gmail.com']
7
- gem.description = %q{Open a ruby library with your editor. Reditor supports gem, bundler, and stdlib(pure ruby).}
7
+ gem.description = %q{Open a ruby library with your editor. Reditor supports gem, bundler, and stdlib (pure ruby).}
8
8
  gem.summary = %q{Open a ruby library with your editor}
9
9
  gem.homepage = 'https://github.com/hibariya/reditor'
10
10
 
@@ -16,11 +16,11 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Reditor::VERSION
17
17
 
18
18
  gem.add_runtime_dependency 'hotwater', '~> 0.1.2'
19
- gem.add_runtime_dependency 'thor', '~> 0.17.0'
20
- gem.add_runtime_dependency 'rake', '~> 10.0.3' # workaround for `WARN: Unresolved specs during Gem::Specification.reset: rake (>= 0)' on ruby-2.0.0
19
+ gem.add_runtime_dependency 'thor', '~> 0.18.1'
20
+ gem.add_runtime_dependency 'rake', '~> 10.1.0' # workaround for `WARN: Unresolved specs during Gem::Specification.reset: rake (>= 0)' on ruby-2.0.0
21
21
 
22
22
  gem.add_development_dependency 'pry'
23
23
  gem.add_development_dependency 'rake'
24
- gem.add_development_dependency 'rspec', '~> 2.13.0'
24
+ gem.add_development_dependency 'rspec', '~> 2.14.1'
25
25
  gem.add_development_dependency 'tapp'
26
26
  end
@@ -7,16 +7,24 @@ describe 'reditor command' do
7
7
  command = PROJECT_ROOT.join('bin/reditor').to_path
8
8
  project = PROJECT_ROOT.join("spec/samples/#{options[:where]}").to_path
9
9
 
10
- Open3.capture2e(
11
- {'EDITOR' => options[:editor]},
12
- command,
13
- library_name,
14
- chdir: project
15
- ).first
10
+ Bundler.with_clean_env {
11
+ Open3.capture2e(
12
+ {'EDITOR' => options[:editor]},
13
+ command,
14
+ library_name,
15
+ chdir: project
16
+ ).first
17
+ }
16
18
  end
17
19
 
18
20
  let(:thor_in_bundler_project) { /thor-0\.14\.6/ }
19
21
 
22
+ before :all do
23
+ Bundler.with_clean_env do
24
+ system 'bundle', chdir: PROJECT_ROOT.join('spec/samples/bundler_project').to_path
25
+ end
26
+ end
27
+
20
28
  describe '#open' do
21
29
  context 'Standard library in non-bundler broject (happy case)' do
22
30
  subject { capture_reditor('thread', where: 'blank_project') }
@@ -0,0 +1,51 @@
1
+ require 'reditor'
2
+ require 'spec_helper'
3
+
4
+ describe Reditor::LibrarySearchQuery do
5
+ describe '.search(query, limit)' do
6
+ before do
7
+ Reditor::LibrarySearchQuery.any_instance.stub(:available_libraries) {
8
+ %w(
9
+ rails_admin
10
+ railtie
11
+ activemodel
12
+ active_decorator
13
+ action
14
+ jquery-atwho-rails
15
+ itwho
16
+ csv
17
+ )
18
+ }
19
+ end
20
+
21
+ describe 'rails' do
22
+ subject { Reditor::LibrarySearchQuery.search('rails', 3) }
23
+
24
+ it { should == %w(rails_admin jquery-atwho-rails railtie) }
25
+ end
26
+
27
+ describe 'rails_' do
28
+ subject { Reditor::LibrarySearchQuery.search('rails_', 2) }
29
+
30
+ it { should == %w(rails_admin railtie) }
31
+ end
32
+
33
+ describe 'cvs' do
34
+ subject { Reditor::LibrarySearchQuery.search('cvs', 1) }
35
+
36
+ it { should == %w(csv) }
37
+ end
38
+
39
+ describe 'atwho' do
40
+ subject { Reditor::LibrarySearchQuery.search('atwho', 2) }
41
+
42
+ it { should == %w(jquery-atwho-rails itwho) }
43
+ end
44
+
45
+ describe 'active' do
46
+ subject { Reditor::LibrarySearchQuery.search('active', 3) }
47
+
48
+ it { should == %w(activemodel active_decorator action) }
49
+ end
50
+ end
51
+ end
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'thor', '0.14.6'
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'thor', '0.14.6'
@@ -9,8 +9,4 @@ PROJECT_ROOT = Pathname.new(__FILE__).dirname.join('..').realpath
9
9
  RSpec.configure do |config|
10
10
  config.filter_run focus: true
11
11
  config.run_all_when_everything_filtered = true
12
-
13
- config.before :suite do
14
- system 'bundle', chdir: PROJECT_ROOT.join('spec/samples/bundler_project').to_path
15
- end
16
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reditor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hibariya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-04 00:00:00.000000000 Z
11
+ date: 2013-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hotwater
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 0.17.0
33
+ version: 0.18.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 0.17.0
40
+ version: 0.18.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 10.0.3
47
+ version: 10.1.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 10.0.3
54
+ version: 10.1.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: 2.13.0
89
+ version: 2.14.1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: 2.13.0
96
+ version: 2.14.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: tapp
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: Open a ruby library with your editor. Reditor supports gem, bundler,
112
- and stdlib(pure ruby).
112
+ and stdlib (pure ruby).
113
113
  email:
114
114
  - celluloid.key@gmail.com
115
115
  executables:
@@ -118,18 +118,20 @@ extensions: []
118
118
  extra_rdoc_files: []
119
119
  files:
120
120
  - .gitignore
121
+ - .travis.yml
121
122
  - Gemfile
122
123
  - LICENSE
123
124
  - README.md
124
125
  - Rakefile
125
126
  - bin/reditor
126
127
  - lib/reditor.rb
127
- - lib/reditor/candidates_locator.rb
128
128
  - lib/reditor/command.rb
129
129
  - lib/reditor/library_locator.rb
130
+ - lib/reditor/library_search_query.rb
130
131
  - lib/reditor/version.rb
131
132
  - reditor.gemspec
132
133
  - spec/command_spec.rb
134
+ - spec/library_search_query_spec.rb
133
135
  - spec/samples/blank_project/.gitkeep
134
136
  - spec/samples/bundler_project/Gemfile
135
137
  - spec/samples/bundler_project_without_lockfile/Gemfile
@@ -153,14 +155,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
155
  version: '0'
154
156
  requirements: []
155
157
  rubyforge_project:
156
- rubygems_version: 2.0.0
158
+ rubygems_version: 2.0.3
157
159
  signing_key:
158
160
  specification_version: 4
159
161
  summary: Open a ruby library with your editor
160
162
  test_files:
161
163
  - spec/command_spec.rb
164
+ - spec/library_search_query_spec.rb
162
165
  - spec/samples/blank_project/.gitkeep
163
166
  - spec/samples/bundler_project/Gemfile
164
167
  - spec/samples/bundler_project_without_lockfile/Gemfile
165
168
  - spec/spec_helper.rb
166
- has_rdoc:
@@ -1,52 +0,0 @@
1
- require 'pathname'
2
- require 'hotwater'
3
-
4
- module Reditor
5
- class CandidatesLocator
6
- def self.detect(keyword)
7
- new(keyword.to_s).detect
8
- end
9
-
10
- attr_reader :keyword, :limit
11
-
12
- def initialize(keyword, limit = 20)
13
- @keyword, @limit = keyword, limit
14
- end
15
-
16
- def detect
17
- available_libraries.sort_by {|name|
18
- Hotwater.damerau_levenshtein_distance(@keyword, name)
19
- }.take(@limit)
20
- end
21
-
22
- def available_libraries
23
- (availables_from_loadpath +
24
- availables_from_gem +
25
- availables_from_bundler).uniq
26
- end
27
-
28
- private
29
-
30
- def availables_from_bundler
31
- require 'bundler'
32
-
33
- Bundler.load.specs.map(&:name)
34
- rescue NameError, Bundler::GemNotFound, Bundler::GemfileNotFound
35
- []
36
- end
37
-
38
- def availables_from_gem
39
- Gem::Specification.map(&:name)
40
- rescue Gem::LoadError
41
- []
42
- end
43
-
44
- def availables_from_loadpath
45
- $LOAD_PATH.each_with_object([]) {|path, availables|
46
- Pathname.new(File.expand_path(path)).entries.each do |entry|
47
- availables << entry.basename('.rb').to_s if entry.extname == '.rb'
48
- end
49
- }
50
- end
51
- end
52
- end