mactag 0.5.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +35 -30
- data/Rakefile +10 -8
- data/VERSION +1 -1
- data/lib/generators/mactag/templates/mactag.rb +26 -85
- data/lib/mactag.rb +7 -1
- data/lib/mactag/builder.rb +4 -6
- data/lib/mactag/bundler.rb +21 -19
- data/lib/mactag/config.rb +22 -16
- data/lib/mactag/ctags.rb +2 -0
- data/lib/mactag/dsl.rb +197 -32
- data/lib/mactag/indexer.rb +9 -0
- data/lib/mactag/indexer/app.rb +22 -0
- data/lib/mactag/indexer/gem.rb +72 -0
- data/lib/mactag/{tag → indexer}/plugin.rb +10 -9
- data/lib/mactag/indexer/rails.rb +46 -0
- data/spec/mactag/builder_spec.rb +11 -11
- data/spec/mactag/config_spec.rb +24 -29
- data/spec/mactag/ctags_spec.rb +4 -4
- data/spec/mactag/dsl_spec.rb +179 -47
- data/spec/mactag/indexer/app_spec.rb +20 -0
- data/spec/mactag/indexer/gem_spec.rb +180 -0
- data/spec/mactag/{tag → indexer}/plugin_spec.rb +32 -23
- data/spec/mactag/indexer/rails_spec.rb +112 -0
- data/spec/spec_helper.rb +18 -0
- metadata +53 -28
- data/.gemtest +0 -0
- data/lib/mactag/tag.rb +0 -9
- data/lib/mactag/tag/app.rb +0 -30
- data/lib/mactag/tag/gem.rb +0 -80
- data/lib/mactag/tag/rails.rb +0 -86
- data/spec/mactag/tag/app_spec.rb +0 -9
- data/spec/mactag/tag/gem_spec.rb +0 -117
- data/spec/mactag/tag/rails_spec.rb +0 -105
- data/spec/mactag/tag_spec.rb +0 -5
data/lib/mactag/dsl.rb
CHANGED
@@ -4,70 +4,235 @@ module Mactag
|
|
4
4
|
# Mactag DSL.
|
5
5
|
#
|
6
6
|
class Dsl
|
7
|
+
attr_reader :builder
|
8
|
+
|
7
9
|
def initialize(builder)
|
8
10
|
@builder = builder
|
9
11
|
end
|
10
12
|
|
11
13
|
##
|
12
14
|
#
|
13
|
-
#
|
15
|
+
# This is the method used to index. Three different things can be
|
16
|
+
# indexed: the current project, gems and Rails (which really is a
|
17
|
+
# collection of gems).
|
14
18
|
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
# = App
|
20
|
+
#
|
21
|
+
# App indexes files in the current project.
|
22
|
+
#
|
23
|
+
# == Examples
|
24
|
+
#
|
25
|
+
# Mactag do
|
26
|
+
# # Index single file.
|
27
|
+
# index 'lib/super_duper.rb'
|
28
|
+
#
|
29
|
+
# # Index all ruby files in lib, recursive.
|
30
|
+
# index 'lib/**/*.rb'
|
31
|
+
#
|
32
|
+
# # Index all helper and model ruby files.
|
33
|
+
# index 'app/helpers/*.rb', 'app/models/*.rb'
|
34
|
+
#
|
35
|
+
# # Same as above
|
36
|
+
# index 'app/{models,helpers}/*.rb'
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
#
|
40
|
+
# = Gem
|
41
|
+
#
|
42
|
+
# Index Ruby gems.
|
43
|
+
#
|
44
|
+
# == Examples
|
45
|
+
#
|
46
|
+
# Mactag do
|
47
|
+
# # Index all gems specified in Gemfile.
|
48
|
+
# index :gems
|
49
|
+
#
|
50
|
+
# # Index the gem whenever, latest version.
|
51
|
+
# index 'whenever'
|
52
|
+
#
|
53
|
+
# # Index the thinking-sphinx and carrierwave gems, latest versions.
|
54
|
+
# index 'thinking-sphinx', 'carrierwave'
|
55
|
+
#
|
56
|
+
# # Index the gem simple_form, version 1.5.2.
|
57
|
+
# index 'simple_form', :version => '1.5.2'
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
#
|
61
|
+
# = Rails
|
62
|
+
#
|
63
|
+
# Index Rails.
|
64
|
+
#
|
65
|
+
# == Packages
|
66
|
+
#
|
67
|
+
# These are the packages that can be indexed. Naming does not
|
68
|
+
# matter, so <tt>activerecord</tt> and <tt>active_record</tt> are
|
69
|
+
# the same.
|
70
|
+
#
|
71
|
+
# * actionmailer
|
72
|
+
# * actionpack
|
73
|
+
# * activemodel
|
74
|
+
# * activerecord
|
75
|
+
# * activeresource
|
76
|
+
# * railties
|
77
|
+
# * activesupport
|
78
|
+
#
|
79
|
+
#
|
80
|
+
# == Examples
|
81
|
+
#
|
82
|
+
# Mactag do
|
83
|
+
# # Index all packages, same version as application
|
84
|
+
# index :rails
|
85
|
+
#
|
86
|
+
# # Index all packages, version 3.1.3
|
87
|
+
# index :rails, :version => '3.1.3'
|
88
|
+
#
|
89
|
+
# # Index all packages except activerecord, same version as application
|
90
|
+
# index :rails, :except => :activerecord
|
91
|
+
#
|
92
|
+
# # Index only activerecord and actionview, same version as application
|
93
|
+
# index :rails, :only => [:activerecord, :action_view]
|
94
|
+
#
|
95
|
+
# # Index all packages except activerecord and actionview,
|
96
|
+
# # same version as application
|
97
|
+
# index :rails, :except => ['activerecord', :action_controller]
|
98
|
+
#
|
99
|
+
# # Index all packages except actionmailer, version 3.1.3
|
100
|
+
# index :rails, :except => :actionmailer, :version => '3.1.3'
|
101
|
+
# end
|
102
|
+
#
|
103
|
+
def index(*args)
|
104
|
+
if args.first == :app
|
105
|
+
app_private
|
106
|
+
elsif args.first == :gems
|
107
|
+
gem_private
|
108
|
+
elsif args.first == :rails
|
109
|
+
rails_private(*args)
|
110
|
+
else
|
111
|
+
options = args.last
|
112
|
+
|
113
|
+
if options[:version] && args.size > 2
|
114
|
+
raise ArgumentError.new('The :version option is not valid when specifying more than one gem')
|
115
|
+
end
|
116
|
+
|
117
|
+
if options.is_a?(Hash) || args.all? { |arg| Mactag::Indexer::Gem.exist?(arg) }
|
118
|
+
gem_private(*args)
|
119
|
+
else
|
120
|
+
app_private(*args)
|
121
|
+
end
|
22
122
|
end
|
23
123
|
end
|
24
124
|
|
25
125
|
##
|
26
126
|
#
|
27
|
-
#
|
127
|
+
# <b>DEPRECATED:</b> Please use '#index' instead.
|
28
128
|
#
|
29
|
-
def
|
30
|
-
|
31
|
-
plugins = Mactag::Tag::Plugin.all
|
32
|
-
end
|
129
|
+
def app(*args)
|
130
|
+
$stderr.puts '[DEPRECATION] Please use #index instead of #app.'
|
33
131
|
|
34
|
-
|
35
|
-
|
132
|
+
if args.empty?
|
133
|
+
index(:app)
|
134
|
+
else
|
135
|
+
index(*args)
|
36
136
|
end
|
37
137
|
end
|
38
|
-
alias :plugins :plugin
|
39
138
|
|
40
139
|
##
|
41
140
|
#
|
42
|
-
#
|
141
|
+
# <b>DEPRECATED:</b> Please use '#index' instead.
|
43
142
|
#
|
44
|
-
def gem(*
|
45
|
-
|
46
|
-
|
47
|
-
if options[:version] && gems.size > 1
|
48
|
-
raise ArgumentError.new('The :version option is not valid when specifying more than one gem')
|
49
|
-
end
|
143
|
+
def gem(*args)
|
144
|
+
$stderr.puts '[DEPRECATION] Please use #index instead of #gems.'
|
50
145
|
|
51
|
-
if
|
52
|
-
|
146
|
+
if args.empty?
|
147
|
+
index(:gems)
|
53
148
|
else
|
54
|
-
|
55
|
-
@builder << Mactag::Tag::Gem.new(gem, options[:version])
|
56
|
-
end
|
149
|
+
index(*args)
|
57
150
|
end
|
58
151
|
end
|
59
152
|
alias :gems :gem
|
60
153
|
|
61
154
|
##
|
62
155
|
#
|
63
|
-
#
|
156
|
+
# <b>DEPRECATED:</b> Please use '#index' instead.
|
157
|
+
#
|
158
|
+
def rails(*args)
|
159
|
+
$stderr.puts '[DEPRECATION] Please use #index instead of #rails.'
|
160
|
+
|
161
|
+
if args.empty?
|
162
|
+
index(:rails)
|
163
|
+
else
|
164
|
+
index(*args)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
##
|
170
|
+
#
|
171
|
+
# <b>DEPRECATED:</b> Please use gems instead.
|
172
|
+
#
|
173
|
+
# @see Mactag::Indexer::Plugin
|
64
174
|
#
|
65
|
-
def
|
175
|
+
def plugin(*plugins)
|
176
|
+
$stderr.puts '[DEPRECATION] Please use gems instead of plugins.'
|
177
|
+
|
178
|
+
plugin_private(*plugins)
|
179
|
+
end
|
180
|
+
alias :plugins :plugin
|
181
|
+
|
182
|
+
|
183
|
+
private
|
184
|
+
|
185
|
+
def app_private(*tags)
|
186
|
+
if tags.empty?
|
187
|
+
@builder << Mactag::Indexer::App.all
|
188
|
+
else
|
189
|
+
tags.each do |tag|
|
190
|
+
@builder << Mactag::Indexer::App.new(tag)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def gem_private(*args)
|
196
|
+
if args.empty?
|
197
|
+
@builder << Mactag::Indexer::Gem.all
|
198
|
+
else
|
199
|
+
options = args.last
|
200
|
+
|
201
|
+
if version = options[:version]
|
202
|
+
@builder << Mactag::Indexer::Gem.new(args.first, version)
|
203
|
+
else
|
204
|
+
args.each do |arg|
|
205
|
+
@builder << Mactag::Indexer::Gem.new(arg)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def rails_private(*args)
|
212
|
+
args.shift
|
213
|
+
|
214
|
+
if args.size.zero?
|
215
|
+
options = {}
|
216
|
+
else
|
217
|
+
options = args.first
|
218
|
+
end
|
219
|
+
|
66
220
|
if options[:only] && options[:except]
|
67
221
|
raise ArgumentError.new('Can not specify options :only and :except at the same time')
|
68
222
|
end
|
69
|
-
|
70
|
-
@builder << Mactag::
|
223
|
+
|
224
|
+
@builder << Mactag::Indexer::Rails.new(options)
|
225
|
+
end
|
226
|
+
|
227
|
+
def plugin_private(*plugins)
|
228
|
+
if plugins.empty?
|
229
|
+
@builder << Mactag::Indexer::Plugin.all
|
230
|
+
else
|
231
|
+
plugins.each do |plugin|
|
232
|
+
@builder << Mactag::Indexer::Plugin.new(plugin)
|
233
|
+
end
|
234
|
+
end
|
71
235
|
end
|
72
236
|
end
|
73
237
|
end
|
238
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Mactag
|
2
|
+
module Indexer
|
3
|
+
class App
|
4
|
+
attr_reader :tag
|
5
|
+
|
6
|
+
PATTERNS = ['app/**/*.rb', 'lib/**/*.rb']
|
7
|
+
|
8
|
+
def initialize(tag)
|
9
|
+
@tag = tag
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def all
|
15
|
+
PATTERNS.map do |pattern|
|
16
|
+
new(pattern)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Mactag
|
2
|
+
module Indexer
|
3
|
+
class Gem
|
4
|
+
attr_accessor :name
|
5
|
+
attr_writer :version
|
6
|
+
|
7
|
+
def initialize(name, version = nil)
|
8
|
+
@name = name
|
9
|
+
@version = version
|
10
|
+
end
|
11
|
+
|
12
|
+
def tag
|
13
|
+
if exist?
|
14
|
+
File.join(Mactag::Config.gem_home, combo, 'lib', '**', '*.rb')
|
15
|
+
else
|
16
|
+
raise GemNotFoundError.new(self)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def exist?
|
21
|
+
dirs.size > 0
|
22
|
+
end
|
23
|
+
|
24
|
+
def version
|
25
|
+
@version || most_recent
|
26
|
+
end
|
27
|
+
|
28
|
+
def most_recent
|
29
|
+
unless dirs.empty?
|
30
|
+
if dirs.size == 1
|
31
|
+
gem = dirs.first
|
32
|
+
else
|
33
|
+
gem = dirs.sort.last
|
34
|
+
end
|
35
|
+
regex = /#{escaped_name}-([^\/]+)/
|
36
|
+
|
37
|
+
if match = regex.match(gem)
|
38
|
+
match[1]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def dirs
|
44
|
+
@dirs ||= Dir.glob(File.join(Mactag::Config.gem_home, "#{name}-*"))
|
45
|
+
end
|
46
|
+
|
47
|
+
class << self
|
48
|
+
def all
|
49
|
+
gems = Mactag::Bundler.gems
|
50
|
+
gems.map do |name, version|
|
51
|
+
new(name, version)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def exist?(name)
|
56
|
+
new(name).exist?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def combo
|
64
|
+
"#{name}-#{version}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def escaped_name
|
68
|
+
Regexp.escape(name)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -1,18 +1,19 @@
|
|
1
1
|
module Mactag
|
2
|
-
module
|
2
|
+
module Indexer
|
3
3
|
##
|
4
4
|
#
|
5
5
|
# Tag plugins in Rails project.
|
6
6
|
#
|
7
7
|
# ==== Examples
|
8
|
+
#
|
8
9
|
# Mactag do
|
9
|
-
# #
|
10
|
+
# # Index single plugin.
|
10
11
|
# plugin 'whenever'
|
11
12
|
#
|
12
|
-
# #
|
13
|
+
# # Index multiple plugins.
|
13
14
|
# plugins 'thinking-sphinx', 'formtastic'
|
14
15
|
#
|
15
|
-
# #
|
16
|
+
# # Index all plugins.
|
16
17
|
# plugins
|
17
18
|
# do
|
18
19
|
#
|
@@ -26,14 +27,14 @@ module Mactag
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def tag
|
29
|
-
if
|
30
|
-
|
30
|
+
if exist?
|
31
|
+
File.join(PLUGIN_PATH, name, 'lib', '**', '*.rb')
|
31
32
|
else
|
32
33
|
raise PluginNotFoundError.new(self)
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
36
|
-
def
|
37
|
+
def exist?
|
37
38
|
File.directory?(path)
|
38
39
|
end
|
39
40
|
|
@@ -43,8 +44,8 @@ module Mactag
|
|
43
44
|
|
44
45
|
def self.all
|
45
46
|
pattern = File.join(PLUGIN_PATH, '*')
|
46
|
-
Dir.glob(pattern).map do |
|
47
|
-
File.basename(
|
47
|
+
Dir.glob(pattern).map do |file|
|
48
|
+
new(File.basename(file))
|
48
49
|
end
|
49
50
|
end
|
50
51
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Mactag
|
2
|
+
module Indexer
|
3
|
+
class Rails
|
4
|
+
|
5
|
+
PACKAGES = %w(actionmailer actionpack activemodel activerecord activeresource activesupport railties)
|
6
|
+
|
7
|
+
attr_accessor :only, :except, :version
|
8
|
+
|
9
|
+
def initialize(options)
|
10
|
+
@only = packagize(options[:only])
|
11
|
+
@except = packagize(options[:except])
|
12
|
+
@version = options[:version]
|
13
|
+
end
|
14
|
+
|
15
|
+
def tag
|
16
|
+
packages.inject([]) do |array, package|
|
17
|
+
array << Gem.new(package, version).tag
|
18
|
+
array
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def packages
|
23
|
+
if only || except
|
24
|
+
only || PACKAGES - except
|
25
|
+
else
|
26
|
+
PACKAGES
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def version
|
31
|
+
@version || ::Rails.version
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def packagize(pkgs)
|
38
|
+
return nil if pkgs.blank?
|
39
|
+
|
40
|
+
Array(pkgs).map do |pkg|
|
41
|
+
"#{pkg}".gsub(/[^a-z]/, '')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|