prj 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5d755efc6530adac2bdda8cde66a08fcf8ec3024
4
+ data.tar.gz: 93dd041d8360989d8478756a04775cba78e6d2f2
5
+ SHA512:
6
+ metadata.gz: 5cbd2335708ecdee9c2345724bcdbdb0a331ff01ceb34337e5db3cbfbcfcedd35278b237c12eb56ea2160b0eeafb48bc5db4d59c1adecb19adbcf62673f16273
7
+ data.tar.gz: b6ddc26391eeb07e758334d4b0f072d1819139e90d13a7a0f3a88154d0f6af47f717a839434ec9d0617a2551e400c565266838594abcbe7de7afe59d9ee464e0
data/Rakefile CHANGED
@@ -26,7 +26,7 @@ task :default => [:all_specs]
26
26
 
27
27
  require 'rake/extensiontask'
28
28
  Rake::ExtensionTask.new do |t|
29
- t.name = 'finder'
29
+ t.name = 'fast_traverse'
30
30
  t.ext_dir = 'ext/prj'
31
31
  t.lib_dir = 'lib/prj'
32
32
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
@@ -1,4 +1,4 @@
1
1
  require 'mkmf'
2
2
 
3
- dir_config('finder')
4
- create_makefile('finder')
3
+ dir_config('fast_traverse')
4
+ create_makefile('fast_traverse')
@@ -0,0 +1,47 @@
1
+ #include <ruby.h>
2
+
3
+ #include <sys/types.h>
4
+ #include <sys/stat.h>
5
+ #include <fts.h>
6
+
7
+ void Init_fast_traverse();
8
+
9
+ VALUE prj_fast_traverse_traverse_m(VALUE self, VALUE projects_root, VALUE search_nested_repositories);
10
+
11
+ VALUE Prj, FastTraverse;
12
+
13
+ void Init_fast_traverse() {
14
+ Prj = rb_define_module("Prj");
15
+ FastTraverse = rb_define_module_under(Prj, "FastTraverse");
16
+ rb_define_singleton_method(FastTraverse, "traverse", prj_fast_traverse_traverse_m, 2);
17
+ }
18
+
19
+ VALUE prj_fast_traverse_traverse_m(VALUE self, VALUE projects_root, VALUE search_nested_repositories) {
20
+ FTS *fs = NULL;
21
+ FTSENT *child = NULL;
22
+ FTSENT *parent = NULL;
23
+ VALUE parent_path, child_name;
24
+
25
+ char *paths[] = { StringValueCStr(projects_root), NULL };
26
+ fs = fts_open(paths, FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT, NULL);
27
+
28
+ if (fs == NULL) {
29
+ return Qnil;
30
+ }
31
+
32
+ while ((parent = fts_read(fs)) != NULL) {
33
+ child = fts_children(fs, 0);
34
+ while(child != NULL) {
35
+ parent_path = rb_str_new(parent->fts_path, parent->fts_pathlen);
36
+ child_name = rb_str_new(child->fts_name, child->fts_namelen);
37
+ if (child->fts_info == FTS_D && rb_block_given_p() && RTEST(rb_yield_values(2, parent_path, child_name))) {
38
+ fts_set(fs, (RTEST(search_nested_repositories) ? child : parent), FTS_SKIP);
39
+ }
40
+ child = child->fts_link;
41
+ }
42
+ }
43
+
44
+ fts_close(fs);
45
+ return Qnil;
46
+ }
47
+
@@ -0,0 +1,34 @@
1
+ require 'prj/fast_traverse'
2
+
3
+ module Prj
4
+
5
+ class Finder
6
+ def initialize(projects_root, options = {})
7
+ @root = File.expand_path(projects_root)
8
+ @vcs_directories = Array(options[:vcs_directories])
9
+ @search_nested_repositories = !!options[:search_nested_repositories]
10
+ @result = []
11
+ end
12
+
13
+ def find_project_directories
14
+ return @result unless @result.empty?
15
+ FastTraverse.traverse(@root, @search_nested_repositories) do |parent_path, child_name|
16
+ next false unless vcs_directory?(child_name)
17
+ @result << normalize_path(parent_path)
18
+ end
19
+ @result
20
+ end
21
+
22
+ private
23
+
24
+ def vcs_directory?(directory_name)
25
+ @vcs_directories.include? directory_name
26
+ end
27
+
28
+ def normalize_path(path)
29
+ path.sub(@root, "").chomp("/")
30
+ end
31
+ end
32
+
33
+ end
34
+
metadata CHANGED
@@ -1,68 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prj
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.0.1
4
+ version: 1.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Vladimir Yarotsky
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-17 00:00:00.000000000 Z
11
+ date: 2013-06-24 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
- version_requirements: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '2.11'
22
15
  requirement: !ruby/object:Gem::Requirement
23
- none: false
24
16
  requirements:
25
17
  - - ~>
26
18
  - !ruby/object:Gem::Version
27
19
  version: '2.11'
28
20
  type: :development
29
21
  prerelease: false
30
- - !ruby/object:Gem::Dependency
31
- name: rake
32
22
  version_requirements: !ruby/object:Gem::Requirement
33
- none: false
34
23
  requirements:
35
24
  - - ~>
36
25
  - !ruby/object:Gem::Version
37
- version: '0.9'
26
+ version: '2.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
38
29
  requirement: !ruby/object:Gem::Requirement
39
- none: false
40
30
  requirements:
41
31
  - - ~>
42
32
  - !ruby/object:Gem::Version
43
33
  version: '0.9'
44
34
  type: :development
45
35
  prerelease: false
46
- - !ruby/object:Gem::Dependency
47
- name: simplecov
48
36
  version_requirements: !ruby/object:Gem::Requirement
49
- none: false
50
37
  requirements:
51
38
  - - ~>
52
39
  - !ruby/object:Gem::Version
53
- version: '0.6'
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
54
43
  requirement: !ruby/object:Gem::Requirement
55
- none: false
56
44
  requirements:
57
45
  - - ~>
58
46
  - !ruby/object:Gem::Version
59
47
  version: '0.6'
60
48
  type: :development
61
49
  prerelease: false
62
- description: ! ' Prj is an utility to quickly go to project directory using fuzzy
63
- matching
64
-
65
- '
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.6'
55
+ description: |2
56
+ Prj is an utility to quickly go to project directory using fuzzy matching
66
57
  email: vladimir.yarotksy@gmail.com
67
58
  executables:
68
59
  - prj
@@ -73,11 +64,12 @@ files:
73
64
  - bin/prj
74
65
  - lib/prj/app.rb
75
66
  - lib/prj/dir_with_score.rb
67
+ - lib/prj/fast_traverse.bundle
76
68
  - lib/prj/filter.rb
77
- - lib/prj/finder.bundle
69
+ - lib/prj/finder.rb
78
70
  - lib/prj.rb
79
71
  - ext/prj/extconf.rb
80
- - ext/prj/finder.c
72
+ - ext/prj/fast_traverse.c
81
73
  - spec/acceptance/app_spec.rb
82
74
  - spec/lib/prj/filter_spec.rb
83
75
  - spec/lib/prj/finder_spec.rb
@@ -91,27 +83,25 @@ files:
91
83
  homepage: http://github.com/v-yarotsky/prj
92
84
  licenses:
93
85
  - MIT
86
+ metadata: {}
94
87
  post_install_message:
95
88
  rdoc_options: []
96
89
  require_paths:
97
90
  - lib
98
91
  required_ruby_version: !ruby/object:Gem::Requirement
99
- none: false
100
92
  requirements:
101
- - - ! '>='
93
+ - - '>='
102
94
  - !ruby/object:Gem::Version
103
95
  version: '0'
104
96
  required_rubygems_version: !ruby/object:Gem::Requirement
105
- none: false
106
97
  requirements:
107
- - - ! '>='
98
+ - - '>='
108
99
  - !ruby/object:Gem::Version
109
100
  version: 1.3.6
110
101
  requirements: []
111
102
  rubyforge_project:
112
- rubygems_version: 1.8.25
103
+ rubygems_version: 2.0.3
113
104
  signing_key:
114
105
  specification_version: 3
115
106
  summary: Fuzzy-matching project finder
116
107
  test_files: []
117
- has_rdoc:
@@ -1,127 +0,0 @@
1
- #include <ruby.h>
2
-
3
- #include <sys/types.h>
4
- #include <sys/stat.h>
5
- #include <fts.h>
6
-
7
- void Init_finder();
8
-
9
- VALUE prj_finder_initialize_m(VALUE self, VALUE projectsRoot, VALUE options);
10
- VALUE expand_path(VALUE path);
11
-
12
- VALUE prj_finder_find_project_directories_m(VALUE self);
13
- VALUE prj_finder_traverse_projects_root(VALUE self, char *projectsRoot, int searchNestedRepositories, VALUE (*callback)(VALUE self, const FTS *fs, const FTSENT *parent, const FTSENT *child));
14
- VALUE prj_finder_collect_project(VALUE self, const FTS *fs, const FTSENT *parent, const FTSENT *child);
15
- char * prj_finder_normalize_path(char *path);
16
- VALUE prj_finder_is_vcs_dir(VALUE self, const char *dir);
17
-
18
- VALUE Prj, PrjFinder;
19
-
20
- void Init_finder() {
21
- Prj = rb_define_module("Prj");
22
- PrjFinder = rb_define_class_under(Prj, "Finder", rb_cObject);
23
- rb_define_method(PrjFinder, "initialize", prj_finder_initialize_m, 2);
24
- rb_define_method(PrjFinder, "find_project_directories", prj_finder_find_project_directories_m, 0);
25
- }
26
-
27
- VALUE prj_finder_initialize_m(VALUE self, VALUE projectsRoot, VALUE options) {
28
- VALUE expandedProjectsRoot, vcsDirectories, searchNestedRepositories;
29
- expandedProjectsRoot = expand_path(projectsRoot);
30
-
31
- vcsDirectories = rb_hash_aref(options, ID2SYM(rb_intern("vcs_directories")));
32
-
33
- if (!RTEST(vcsDirectories)) {
34
- vcsDirectories = rb_ary_new();
35
- }
36
-
37
- searchNestedRepositories = rb_hash_aref(options, ID2SYM(rb_intern("search_nested_repositories")));
38
-
39
- rb_iv_set(self, "@root", expandedProjectsRoot);
40
- rb_iv_set(self, "@vcs_directories", rb_check_array_type(vcsDirectories));
41
- rb_iv_set(self, "@search_nested_repositories", searchNestedRepositories);
42
- rb_iv_set(self, "@project_directories", rb_ary_new());
43
- return self;
44
- }
45
-
46
- VALUE expand_path(VALUE path) {
47
- VALUE file;
48
- file = rb_const_get(rb_cObject, rb_intern("File"));
49
- return rb_funcall(file, rb_intern("expand_path"), 1, rb_check_string_type(path));
50
- }
51
-
52
- VALUE prj_finder_find_project_directories_m(VALUE self) {
53
- VALUE result, root, searchNestedRepositories;
54
-
55
- result = rb_iv_get(self, "@project_directories");
56
- root = rb_iv_get(self, "@root");
57
- searchNestedRepositories = rb_iv_get(self, "@search_nested_repositories");
58
-
59
- if (RARRAY_LEN(result) == 0) {
60
- prj_finder_traverse_projects_root(self, StringValueCStr(root), RTEST(searchNestedRepositories), &prj_finder_collect_project);
61
- }
62
-
63
- return result;
64
- }
65
-
66
- VALUE prj_finder_traverse_projects_root(VALUE self, char *projectsRoot, int searchNestedRepositories, VALUE (*callback)(VALUE self, const FTS *fs, const FTSENT *parent, const FTSENT *child)) {
67
- FTS *fs = NULL;
68
- FTSENT *child = NULL;
69
- FTSENT *parent = NULL;
70
-
71
- char *paths[] = { projectsRoot, NULL };
72
- fs = fts_open(paths, FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT, NULL);
73
-
74
- if (fs == NULL) {
75
- return Qnil;
76
- }
77
-
78
- while ((parent = fts_read(fs)) != NULL) {
79
- child = fts_children(fs, 0);
80
- while (child != NULL) {
81
- if (child->fts_info == FTS_D && RTEST(callback(self, fs, parent, child))) {
82
- fts_set(fs, (searchNestedRepositories ? child : parent), FTS_SKIP);
83
- }
84
- child = child->fts_link;
85
- }
86
- }
87
- fts_close(fs);
88
-
89
- return Qnil;
90
- }
91
-
92
- VALUE prj_finder_collect_project(VALUE self, const FTS *fs, const FTSENT *parent, const FTSENT *child) {
93
- VALUE root, result;
94
- char *prefixed, *unprefixed;
95
-
96
- if (!prj_finder_is_vcs_dir(self, child->fts_name)) {
97
- return Qfalse;
98
- }
99
-
100
- root = rb_iv_get(self, "@root");
101
- result = rb_iv_get(self, "@project_directories");
102
-
103
- prefixed = parent->fts_path;
104
- unprefixed = prefixed + RSTRING_LEN(root);
105
-
106
- rb_ary_push(result, rb_str_new2(prj_finder_normalize_path(unprefixed)));
107
- return Qtrue;
108
- }
109
-
110
- // strips unnecessary trailing / on linux
111
- char * prj_finder_normalize_path(char *path) {
112
- size_t path_length;
113
- path_length = strlen(path);
114
-
115
- if (path[path_length - 1] == '/') {
116
- path[path_length - 1] = '\0';
117
- }
118
-
119
- return path;
120
- }
121
-
122
- VALUE prj_finder_is_vcs_dir(VALUE self, const char *dir) {
123
- VALUE vcsDirectories;
124
- vcsDirectories = rb_iv_get(self, "@vcs_directories");
125
- return rb_funcall(vcsDirectories, rb_intern("include?"), 1, rb_str_new2(dir));
126
- }
127
-
Binary file