taglob 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +9 -0
- data/README.txt +49 -0
- data/Rakefile +20 -0
- data/lib/taglob.rb +23 -0
- data/spec/spec_taglob.rb +70 -0
- data/spec/tagged_files/epic_lulz.rb +8 -0
- data/spec/tagged_files/foo.rb +1 -0
- data/spec/tagged_files/foo_bar_buttz.rb +2 -0
- metadata +72 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= taglob
|
2
|
+
|
3
|
+
== DESCRIPTION:
|
4
|
+
|
5
|
+
tags + Dir.glob = Dir.taglob
|
6
|
+
|
7
|
+
== FEATURES/PROBLEMS:
|
8
|
+
|
9
|
+
* easily select tagged Ruby files
|
10
|
+
|
11
|
+
== SYNOPSIS:
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'taglob'
|
15
|
+
|
16
|
+
Dir.taglob('**/*.rb','foo','bar','buttz').each {|file| puts "#{file} was tagged with foo or bar or buttz!"}
|
17
|
+
|
18
|
+
== REQUIREMENTS:
|
19
|
+
|
20
|
+
* none?
|
21
|
+
|
22
|
+
== INSTALL:
|
23
|
+
|
24
|
+
* sudo gem install taglob
|
25
|
+
|
26
|
+
== LICENSE:
|
27
|
+
|
28
|
+
(The MIT License)
|
29
|
+
|
30
|
+
Copyright (c) 2008 Adam Anderson
|
31
|
+
|
32
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
33
|
+
a copy of this software and associated documentation files (the
|
34
|
+
'Software'), to deal in the Software without restriction, including
|
35
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
36
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
37
|
+
permit persons to whom the Software is furnished to do so, subject to
|
38
|
+
the following conditions:
|
39
|
+
|
40
|
+
The above copyright notice and this permission notice shall be
|
41
|
+
included in all copies or substantial portions of the Software.
|
42
|
+
|
43
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
44
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
45
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
46
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
47
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
48
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
49
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hoe'
|
3
|
+
require './lib/taglob.rb'
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
|
6
|
+
Hoe.new('Taglob', Taglob::VERSION) do |p|
|
7
|
+
p.name = "taglob"
|
8
|
+
p.author = "Adam Anderson"
|
9
|
+
p.description = "Tagging for Ruby files"
|
10
|
+
p.email = 'adamandersonis@gmail.com'
|
11
|
+
p.summary = "Dir.taglob selects tagged Ruby files"
|
12
|
+
p.url = "http://taglob.rubyforge.org"
|
13
|
+
p.remote_rdoc_dir = '' # Release to root
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
desc "Run all examples"
|
18
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
19
|
+
t.spec_files = FileList['spec/*.rb']
|
20
|
+
end
|
data/lib/taglob.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
class Taglob
|
2
|
+
VERSION = '0.0.1'
|
3
|
+
end
|
4
|
+
|
5
|
+
class Dir
|
6
|
+
|
7
|
+
def self.taglob(pattern,*tags)
|
8
|
+
tagged_files = []
|
9
|
+
Dir.glob(pattern).each do |file|
|
10
|
+
parsed_tags = []
|
11
|
+
File.readlines(file).each do |line|
|
12
|
+
parsed_tags = parsed_tags | self.parse_tags(line)
|
13
|
+
end
|
14
|
+
tagged_files << file unless (parsed_tags & tags).empty?
|
15
|
+
end
|
16
|
+
tagged_files
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.parse_tags(line)
|
20
|
+
line =~ /^#tags:\s+(.*)/ ?$1.split(',') : []
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/spec/spec_taglob.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'lib/taglob'
|
2
|
+
|
3
|
+
describe "Taglob#parse_tags" do
|
4
|
+
|
5
|
+
#taglob formatted line is as follows:
|
6
|
+
#tags: foo,bar,lulz,epic
|
7
|
+
|
8
|
+
it "should parse tags from taglob formatted line(#tags: foo,bar,buttz)" do
|
9
|
+
tags = Dir.parse_tags("#tags: foo,bar,buttz")
|
10
|
+
tags.should be_a_kind_of(Array)
|
11
|
+
tags.should_not be_empty
|
12
|
+
tags.should have(3).items
|
13
|
+
tags.should include('foo')
|
14
|
+
tags.should include('bar')
|
15
|
+
tags.should include('buttz')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return an empty array for a taglob formatted line with no tags" do
|
19
|
+
tags = Dir.parse_tags("#tags: ")
|
20
|
+
tags.should be_a_kind_of(Array)
|
21
|
+
tags.should be_empty
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return an empty array for an incorrectly formatted line" do
|
25
|
+
tags = Dir.parse_tags("#tags ")
|
26
|
+
tags.should be_a_kind_of(Array)
|
27
|
+
tags.should be_empty
|
28
|
+
tags = Dir.parse_tags("tags: foo,bar,buttz")
|
29
|
+
tags.should be_a_kind_of(Array)
|
30
|
+
tags.should be_empty
|
31
|
+
tags = Dir.parse_tags(" #tags: lololo")
|
32
|
+
tags.should be_a_kind_of(Array)
|
33
|
+
tags.should be_empty
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "Taglob#taglob" do
|
39
|
+
|
40
|
+
it "should select files tagged with specified tags" do
|
41
|
+
tagged_files = Dir.taglob('spec/tagged_files/*.rb','foo','bar','buttz')
|
42
|
+
tagged_files.should be_a_kind_of(Array)
|
43
|
+
tagged_files.should_not be_empty
|
44
|
+
tagged_files.should have(2).items
|
45
|
+
tagged_files.should include('spec/tagged_files/foo.rb')
|
46
|
+
tagged_files.should include('spec/tagged_files/foo_bar_buttz.rb')
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should not select files that are not tagged with specified tags" do
|
50
|
+
tagged_files = Dir.taglob('spec/tagged_files/*.rb','lol','rofl')
|
51
|
+
tagged_files.should be_a_kind_of(Array)
|
52
|
+
tagged_files.should be_empty
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should not care where the taglob line is in the file" do
|
56
|
+
tagged_files = Dir.taglob('spec/tagged_files/*.rb','buttz')
|
57
|
+
tagged_files.should be_a_kind_of(Array)
|
58
|
+
tagged_files.should_not be_empty
|
59
|
+
tagged_files.should have(1).items
|
60
|
+
tagged_files.should include('spec/tagged_files/foo_bar_buttz.rb')
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should count every taglob line" do
|
64
|
+
tagged_files = Dir.taglob('spec/tagged_files/*.rb','epic','lulz')
|
65
|
+
tagged_files.should be_a_kind_of(Array)
|
66
|
+
tagged_files.should_not be_empty
|
67
|
+
tagged_files.should have(1).items
|
68
|
+
tagged_files.should include('spec/tagged_files/epic_lulz.rb')
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
#tags: foo
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: taglob
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Anderson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-14 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.5.1
|
23
|
+
version:
|
24
|
+
description: Tagging for Ruby files
|
25
|
+
email: adamandersonis@gmail.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- History.txt
|
32
|
+
- Manifest.txt
|
33
|
+
- README.txt
|
34
|
+
files:
|
35
|
+
- History.txt
|
36
|
+
- Manifest.txt
|
37
|
+
- README.txt
|
38
|
+
- Rakefile
|
39
|
+
- lib/taglob.rb
|
40
|
+
- spec/spec_taglob.rb
|
41
|
+
- spec/tagged_files/foo.rb
|
42
|
+
- spec/tagged_files/foo_bar_buttz.rb
|
43
|
+
- spec/tagged_files/epic_lulz.rb
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://taglob.rubyforge.org
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --main
|
49
|
+
- README.txt
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project: taglob
|
67
|
+
rubygems_version: 1.1.0
|
68
|
+
signing_key:
|
69
|
+
specification_version: 2
|
70
|
+
summary: Dir.taglob selects tagged Ruby files
|
71
|
+
test_files: []
|
72
|
+
|