recall 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +28 -0
- data/Rakefile +1 -0
- data/bin/recall +63 -0
- data/lib/recall.rb +8 -0
- data/lib/recall/results.rb +78 -0
- data/lib/recall/site_generator.rb +29 -0
- data/lib/recall/templates/sublime.rb.erb +10 -0
- data/lib/recall/version.rb +3 -0
- data/recall.gemspec +25 -0
- data/spec/lib/results_spec.rb +7 -0
- data/spec/spec_helper.rb +4 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 438f44d94fc5d3cab7053e56cbc845264456351f
|
4
|
+
data.tar.gz: bb141f27a0531c47cb76db12ba73d461e9e872f5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e0fa8ead146587bc79372e7f22c497ba8242a9a36c7dd383aa1afe16f22237f5ae13eea932aee915a9076f7a9b3340d5fe71df2158b790eabc505f61c1af9e6
|
7
|
+
data.tar.gz: db198c124420df9a9ce493e385a1e8915efd2f145fbe641bc05f7b418482f997f2c78dec9ac66602f3b17df17422fd492948b88753ec552a02fe560626906d56
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 sts10
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Recall
|
2
|
+
|
3
|
+
# Recall v. 0.0.1
|
4
|
+
#### A command line interface that searches for previous examples of Ruby code based on user's query and present results in default Ruby editor.
|
5
|
+
|
6
|
+
> [E]ach time the natural laziness which deters us from every difficult enterprise, every work of importance, has urged me to leave the thing alone, to drink my tea and to think merely of the worries of today and of my hopes for tomorrow, which let themselves be pondered over without effort or distress of mind.
|
7
|
+
|
8
|
+
> And suddenly the memory returns. The taste was that of the little crumb of madeleine...
|
9
|
+
|
10
|
+
## About
|
11
|
+
|
12
|
+
Ever want to find a piece of code you've written but aren't sure which project or file you wrote it in?
|
13
|
+
|
14
|
+
Recall is a simple Ruby app, run via the command line, to recursively search your the Ruby files in your code folder. It's a little janky at this point-- use at your own risk.
|
15
|
+
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
|
20
|
+
## Use
|
21
|
+
|
22
|
+
Type `recall` into your command line. The first time you call the gem it will ask for the absolute path of a directory for it to search. It will search all of the .rb files in that directory, recursively.
|
23
|
+
|
24
|
+
Your search directory will persist until you change it. To change the search directory, enter `change_dir` into the prompt.
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/recall
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'recall'
|
3
|
+
|
4
|
+
|
5
|
+
search_map = File.expand_path("../../lib/recall/search_map.txt", __FILE__)
|
6
|
+
|
7
|
+
|
8
|
+
if File.zero?(search_map)
|
9
|
+
puts "Where would you like to search? (Please input a absolute path.)"
|
10
|
+
@search_path = gets.chomp
|
11
|
+
|
12
|
+
File.open(search_map, "w") do |f|
|
13
|
+
|
14
|
+
f.write(
|
15
|
+
@search_path
|
16
|
+
)
|
17
|
+
|
18
|
+
f.close
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
File.open(search_map, "r") do |f|
|
24
|
+
f.each_line do |line|
|
25
|
+
@search_path = line
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
puts "Currently searching #{@search_path}"
|
30
|
+
puts "Enter 'change_dir' to change the search directory."
|
31
|
+
puts ''
|
32
|
+
|
33
|
+
puts "What would you like to search for?"
|
34
|
+
query = gets.chomp
|
35
|
+
|
36
|
+
|
37
|
+
if query == "change_dir"
|
38
|
+
puts "Where would you like to search? (Please input a absolute path.)"
|
39
|
+
@search_path = gets.chomp
|
40
|
+
|
41
|
+
File.open(search_map, "w") do |f|
|
42
|
+
|
43
|
+
f.write(
|
44
|
+
@search_path
|
45
|
+
)
|
46
|
+
|
47
|
+
f.close
|
48
|
+
end
|
49
|
+
|
50
|
+
puts ""
|
51
|
+
puts ""
|
52
|
+
puts "Now searching #{@search_path}"
|
53
|
+
puts ""
|
54
|
+
puts "What would you like to search for?"
|
55
|
+
query = gets.chomp
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
my_results = Recall::Results.new(query, @search_path)
|
60
|
+
|
61
|
+
site_generator = Recall::SiteGenerator.new(my_results.get_full_snippet)
|
62
|
+
|
63
|
+
site_generator.make_page!
|
data/lib/recall.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
class Recall::Results
|
2
|
+
attr_accessor :results_string
|
3
|
+
|
4
|
+
ALL = []
|
5
|
+
|
6
|
+
def initialize(query, search_path)
|
7
|
+
|
8
|
+
@query = query
|
9
|
+
@search_path = search_path
|
10
|
+
end
|
11
|
+
|
12
|
+
def url
|
13
|
+
"#{@query.downcase.gsub(" ", "_")}.html"
|
14
|
+
end
|
15
|
+
|
16
|
+
def method?
|
17
|
+
@query[0] == '.'
|
18
|
+
end
|
19
|
+
|
20
|
+
def symbol?
|
21
|
+
@query[0] == ':'
|
22
|
+
end
|
23
|
+
|
24
|
+
def format_query
|
25
|
+
if method?
|
26
|
+
a = @query.split('')
|
27
|
+
a[0] = '\.'
|
28
|
+
@query = a.join('')
|
29
|
+
end
|
30
|
+
|
31
|
+
if !symbol?
|
32
|
+
c = @query.split('')
|
33
|
+
c.unshift('\b')
|
34
|
+
c.push('\b')
|
35
|
+
@query = c.join('')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_grep_results
|
40
|
+
format_query # # /Users/samschlinkert/Documents/code/flatiron
|
41
|
+
return `grep -r -n -i --include=*.rb "#{@query}" #{@search_path} | sort -r`
|
42
|
+
end
|
43
|
+
|
44
|
+
Result = Struct.new(:file_path, :line_number, :code_snippet, :full_code)
|
45
|
+
|
46
|
+
def parse_results
|
47
|
+
results = get_grep_results.split("\n")
|
48
|
+
|
49
|
+
results.map do |result|
|
50
|
+
line_array = []
|
51
|
+
line_array = result.split(":")
|
52
|
+
Result.new(line_array[0], line_array[1], line_array[2], [''])
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_full_snippet
|
58
|
+
results = parse_results # array of Result structs
|
59
|
+
|
60
|
+
results.each do |result| # iterate over the Result structs
|
61
|
+
|
62
|
+
line_num = 0
|
63
|
+
|
64
|
+
File.open("#{result.file_path}", "r") do |f|
|
65
|
+
f.each_line do |line|
|
66
|
+
line_num = line_num + 1
|
67
|
+
if line_num < (result.line_number.to_i - 5) || line_num > (result.line_number.to_i + 15)
|
68
|
+
next
|
69
|
+
else
|
70
|
+
result.full_code << line
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Recall::SiteGenerator
|
2
|
+
|
3
|
+
def initialize(results)
|
4
|
+
@results = results
|
5
|
+
end
|
6
|
+
def make_page!
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
template_file = File.expand_path("../templates/sublime.rb.erb", __FILE__)
|
11
|
+
template_doc= File.open(template_file)
|
12
|
+
template = ERB.new(template_doc.read)
|
13
|
+
|
14
|
+
output_file = File.expand_path("../_site/ruby_file.rb", __FILE__)
|
15
|
+
File.open(output_file, "w") do |f|
|
16
|
+
|
17
|
+
f.write(
|
18
|
+
template.result(binding)
|
19
|
+
)
|
20
|
+
|
21
|
+
f.close
|
22
|
+
end
|
23
|
+
|
24
|
+
`open #{output_file}`
|
25
|
+
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
### Output from Recall search
|
2
|
+
<% @results.each do |result| %>
|
3
|
+
|
4
|
+
###########################
|
5
|
+
|
6
|
+
# File: <%= result.file_path %>
|
7
|
+
# Starting at line number: <%= result.line_number %>...
|
8
|
+
|
9
|
+
<% result.full_code.each { |line| %><%= line %><% } %>
|
10
|
+
<% end %>
|
data/recall.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'recall/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "recall"
|
8
|
+
spec.version = Recall::VERSION
|
9
|
+
spec.authors = ["Sam Schlinkert"]
|
10
|
+
spec.email = ["sschlinkert@gmail.com"]
|
11
|
+
spec.summary = "Simple Local Code Search"
|
12
|
+
spec.description = "Search a local directory for a specific query"
|
13
|
+
spec.homepage = "http://sts10.github.io"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
# spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.executables = ['recall']
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.1"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: recall
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sam Schlinkert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Search a local directory for a specific query
|
56
|
+
email:
|
57
|
+
- sschlinkert@gmail.com
|
58
|
+
executables:
|
59
|
+
- recall
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/recall
|
69
|
+
- lib/recall.rb
|
70
|
+
- lib/recall/_site/ruby_file.rb
|
71
|
+
- lib/recall/results.rb
|
72
|
+
- lib/recall/search_map.txt
|
73
|
+
- lib/recall/site_generator.rb
|
74
|
+
- lib/recall/templates/sublime.rb.erb
|
75
|
+
- lib/recall/version.rb
|
76
|
+
- recall.gemspec
|
77
|
+
- spec/lib/results_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
homepage: http://sts10.github.io
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.2.1
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Simple Local Code Search
|
103
|
+
test_files:
|
104
|
+
- spec/lib/results_spec.rb
|
105
|
+
- spec/spec_helper.rb
|