prj 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Prj
2
2
  ==========
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/v-yarotsky/prj.png)](http://travis-ci.org/v-yarotsky/prj)
4
+ [![Build Status](https://travis-ci.org/v-yarotsky/prj.png?branch=master)](https://travis-ci.org/v-yarotsky/prj)
5
5
  [![Code Climate](https://codeclimate.com/github/v-yarotsky/prj.png)](https://codeclimate.com/github/v-yarotsky/prj)
6
6
  [![Gem Version](https://badge.fury.io/rb/prj.png)](http://badge.fury.io/rb/prj)
7
7
 
@@ -27,6 +27,7 @@ Installation & Configuration:
27
27
  3. Put a project root directory name into ~/.prj.yml, i.e:
28
28
  ```
29
29
  projects_root: ~/Projects
30
+ case_sensitive: false
30
31
  vcs_directories:
31
32
  - .git
32
33
  - .svn
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.1.0
@@ -19,7 +19,7 @@ module Prj
19
19
  return 0
20
20
  end
21
21
  finder = Finder.new(config.fetch("projects_root"), config.fetch("vcs_directories"))
22
- filter = Filter.new(@letters)
22
+ filter = Filter.new(@letters, config.fetch("case_sensitive") { true })
23
23
  directories = finder.find_project_directories
24
24
  filtered_directories = filter.filter(directories)
25
25
  target_directory = File.join(config.fetch("projects_root"), filtered_directories.first.to_s)
@@ -4,8 +4,9 @@ require 'strscan'
4
4
  module Prj
5
5
 
6
6
  class Filter
7
- def initialize(letters)
7
+ def initialize(letters, case_sensitive = true)
8
8
  @letters = letters.to_a
9
+ @case_sensitive = case_sensitive
9
10
  end
10
11
 
11
12
  def filter(directories)
@@ -15,7 +16,8 @@ module Prj
15
16
  def distance(dir)
16
17
  scanner = StringScanner.new(dir)
17
18
  @letters.each do |letter|
18
- scanner.scan(/.*?[#{letter}]/) or return :no_score
19
+ regexp = Regexp.new(".*?[#{letter}]", !@case_sensitive)
20
+ scanner.scan(regexp) or return :no_score
19
21
  end
20
22
  scanner.pos - @letters.length
21
23
  end
@@ -25,7 +25,7 @@ describe "Prj::App" do
25
25
  subdirectories.each { |d| FileUtils.mkdir_p(d) }
26
26
  end
27
27
 
28
- context "with default projcts root" do
28
+ context "within projcts root" do
29
29
  it "prints matching directory and returns 0" do
30
30
  with_config("projects_root" => root) do
31
31
  Prj::App.new(output, ["ap"]).run.should == 0
@@ -39,6 +39,13 @@ describe "Prj::App" do
39
39
  output.string.chomp.should == root + "/"
40
40
  end
41
41
  end
42
+
43
+ it "allows case-insensitive search if option specified in config" do
44
+ with_config("projects_root" => root, "case_sensitive" => false) do
45
+ Prj::App.new(output, ["Fo"]).run.should == 0
46
+ output.string.chomp.should == File.join(root, "foo")
47
+ end
48
+ end
42
49
  end
43
50
 
44
51
  it "uses ~/.prj.yml as config file" do
@@ -2,10 +2,6 @@ require 'spec_helper'
2
2
  require 'prj/filter'
3
3
 
4
4
  describe "Prj::Filter" do
5
- def filter(letters)
6
- Prj::Filter.new(letters)
7
- end
8
-
9
5
  describe "#distance" do
10
6
  it "should calculate distance as difference between character positions except first character position" do
11
7
  filter(%w(f o)).distance("foo bar").should == 0
@@ -46,7 +42,15 @@ describe "Prj::Filter" do
46
42
  dirs = ["/granny/", "/franchise/"]
47
43
  filter(%w(a n)).filter(dirs).should == ["/granny/", "/franchise/"]
48
44
  end
45
+
46
+ it "supports case-insensitive mode" do
47
+ dirs = ["/Hello/", "/hello-world/", "/hi-fella/"]
48
+ filter(%w(h e l l o), false).filter(dirs).should == ["/Hello/", "/hello-world/"]
49
+ end
49
50
  end
50
51
 
52
+ def filter(letters, options = {})
53
+ Prj::Filter.new(letters, options)
54
+ end
51
55
  end
52
56
 
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: prj
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Vladimir Yarotsky
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-07 00:00:00.000000000 Z
12
+ date: 2013-06-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec