mactag 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +68 -0
- data/VERSION +1 -0
- data/features/app.feature +35 -0
- data/features/gem.feature +59 -0
- data/features/plugin.feature +41 -0
- data/features/rails/actionmailer/lib/action_mailer/base.rb +9 -0
- data/features/rails/actionpack/lib/action_controller/caching/actions.rb +11 -0
- data/features/rails/actionpack/lib/action_view/action_view/helpers/form_tag_helper.rb +9 -0
- data/features/rails/activerecord/lib/active_record/associations.rb +9 -0
- data/features/rails/activeresource/lib/active_resource/connection.rb +7 -0
- data/features/rails/activesupport/lib/active_support/core_ext/hash/diff.rb +5 -0
- data/features/rails_gem.feature +69 -0
- data/features/rails_vendor.feature +46 -0
- data/features/step_definitions/app_steps.rb +11 -0
- data/features/step_definitions/gem_steps.rb +40 -0
- data/features/step_definitions/mactab_steps.rb +53 -0
- data/features/step_definitions/plugin_steps.rb +34 -0
- data/features/step_definitions/rails_steps.rb +62 -0
- data/features/support/core_ext.rb +5 -0
- data/features/support/env.rb +10 -0
- data/features/support/rails_app.rb +74 -0
- data/features/support/tags_file.rb +21 -0
- data/generators/mactag/mactag_generator.rb +10 -0
- data/generators/mactag/templates/mactag.rb +11 -0
- data/lib/mactag.rb +6 -0
- data/lib/mactag/config.rb +20 -0
- data/lib/mactag/table.rb +45 -0
- data/lib/mactag/tag.rb +8 -0
- data/lib/mactag/tag/app.rb +30 -0
- data/lib/mactag/tag/gem.rb +46 -0
- data/lib/mactag/tag/parser.rb +33 -0
- data/lib/mactag/tag/plugin.rb +32 -0
- data/lib/mactag/tag/rails.rb +138 -0
- data/lib/mactag/tasks.rb +10 -0
- data/tasks/mactag_tasks.rake +1 -0
- data/test/mactag/config_test.rb +10 -0
- data/test/mactag/tag/app_test.rb +16 -0
- data/test/mactag/tag/gem_test.rb +42 -0
- data/test/mactag/tag/plugin_test.rb +40 -0
- data/test/mactag/tag/rails_test.rb +182 -0
- data/test/mactag_test.rb +4 -0
- metadata +94 -0
@@ -0,0 +1,138 @@
|
|
1
|
+
module Mactag
|
2
|
+
module Tag
|
3
|
+
|
4
|
+
# Tag for the Rails source.
|
5
|
+
#
|
6
|
+
# ==== Packages
|
7
|
+
# Naming does not matter. So *activerecord* and *active_record* are the same.
|
8
|
+
#
|
9
|
+
# * activesupport
|
10
|
+
# * activeresource
|
11
|
+
# * activerecord
|
12
|
+
# * actionmailer
|
13
|
+
# * actioncontroller
|
14
|
+
# * actionview
|
15
|
+
#
|
16
|
+
# ==== Examples
|
17
|
+
# Mactag::Table.generate do
|
18
|
+
# # Tag all rails packages, latest version
|
19
|
+
# rails
|
20
|
+
#
|
21
|
+
# # Tag all rails packages, version 2.3.5
|
22
|
+
# rails :version => "2.3.5"
|
23
|
+
#
|
24
|
+
# # Tag only activerecord, latest version
|
25
|
+
# rails :only => :active_record
|
26
|
+
#
|
27
|
+
# # Tag all packages except activerecord, latest version
|
28
|
+
# rails :except => :activerecord
|
29
|
+
#
|
30
|
+
# # Tag only activerecord and actionview, latest version
|
31
|
+
# rails :only => [:activerecord, :action_view]
|
32
|
+
#
|
33
|
+
# # Tag all packages except activerecord and actionview, latest version
|
34
|
+
# rails :except => ["activerecord", :action_controller]
|
35
|
+
#
|
36
|
+
# # Tag all packages except actionmailer, version 2.3.4
|
37
|
+
# rails :except => :actionmailer, :version => "2.3.4"
|
38
|
+
# do
|
39
|
+
class Rails
|
40
|
+
|
41
|
+
VENDOR = File.join("vendor", "rails")
|
42
|
+
|
43
|
+
PACKAGES = {
|
44
|
+
:activesupport => ["activesupport", "active_support"],
|
45
|
+
:activeresource => ["activeresource", "active_resource"],
|
46
|
+
:activerecord => ["activerecord", "active_record"],
|
47
|
+
:actionmailer => ["actionmailer", "action_mailer"],
|
48
|
+
:actioncontroller => ["actionpack", "action_controller"],
|
49
|
+
:actionview => ["actionpack", "action_view"]
|
50
|
+
}
|
51
|
+
|
52
|
+
def initialize(options)
|
53
|
+
@options = options
|
54
|
+
|
55
|
+
@only = packagize!(options[:only])
|
56
|
+
@except = packagize!(options[:except])
|
57
|
+
end
|
58
|
+
|
59
|
+
def files
|
60
|
+
result = []
|
61
|
+
|
62
|
+
packages.each do |package|
|
63
|
+
path = []
|
64
|
+
path << rails_home
|
65
|
+
path << package_path(package)
|
66
|
+
path << "**"
|
67
|
+
path << "*.rb"
|
68
|
+
path.flatten!
|
69
|
+
|
70
|
+
result << Dir.glob(File.join(path))
|
71
|
+
end
|
72
|
+
|
73
|
+
result.flatten
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def packages
|
80
|
+
result = []
|
81
|
+
|
82
|
+
unless @only || @except
|
83
|
+
result = PACKAGES.keys
|
84
|
+
else
|
85
|
+
if @only
|
86
|
+
result = @only
|
87
|
+
elsif @except
|
88
|
+
result = PACKAGES.keys - @except
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
result
|
93
|
+
end
|
94
|
+
|
95
|
+
def package_path(package)
|
96
|
+
paths = PACKAGES[package].dup
|
97
|
+
paths.insert(1, "lib")
|
98
|
+
|
99
|
+
unless Mactag::Tag::Rails.vendor?
|
100
|
+
top = paths.first
|
101
|
+
if version = @options[:version]
|
102
|
+
top = "#{top}-#{version}"
|
103
|
+
else
|
104
|
+
versions = Dir.glob(File.join(Mactag::Config.gem_home, "#{top}-*"))
|
105
|
+
|
106
|
+
if versions.size == 1
|
107
|
+
top = versions.first
|
108
|
+
else
|
109
|
+
top = versions.sort.last
|
110
|
+
end
|
111
|
+
|
112
|
+
top = File.basename(top)
|
113
|
+
end
|
114
|
+
paths[0] = top
|
115
|
+
end
|
116
|
+
|
117
|
+
File.join(paths)
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.vendor?
|
121
|
+
File.exist?(VENDOR)
|
122
|
+
end
|
123
|
+
|
124
|
+
def rails_home
|
125
|
+
@rails_home ||= Mactag::Tag::Rails.vendor? ? VENDOR : Mactag::Config.gem_home
|
126
|
+
end
|
127
|
+
|
128
|
+
def packagize!(pkgs)
|
129
|
+
return nil if pkgs.blank?
|
130
|
+
|
131
|
+
Array(pkgs).collect do |pkg|
|
132
|
+
"#{pkg}".gsub(/[^a-z]/, '').to_sym
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
data/lib/mactag/tasks.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/../lib/mactag/tasks')
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AppTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
context "an app tag" do
|
6
|
+
setup do
|
7
|
+
@tags = [ "app/**/*.rb", "public/javascripts/*.js" ]
|
8
|
+
@app = Mactag::Tag::App.new(@tags)
|
9
|
+
end
|
10
|
+
|
11
|
+
should "return the correct files" do
|
12
|
+
assert_same_elements [@tags], @app.files
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class GemTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
context "gem with version" do
|
6
|
+
setup do
|
7
|
+
@gem = Mactag::Tag::Gem.new("thinking-sphinx", :version => "1.0.0")
|
8
|
+
end
|
9
|
+
|
10
|
+
should "return the gem with that version" do
|
11
|
+
assert_contains @gem.files, File.join(Mactag::Config.gem_home, "thinking-sphinx-1.0.0", "lib", "**", "*.rb")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "gem without version" do
|
16
|
+
context "one gem" do
|
17
|
+
setup do
|
18
|
+
Dir.stubs(:glob).returns("whenever")
|
19
|
+
|
20
|
+
@gem = Mactag::Tag::Gem.new("whenever")
|
21
|
+
end
|
22
|
+
|
23
|
+
should "return that gem" do
|
24
|
+
assert_contains @gem.files, "whenever/lib/**/*.rb"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "multiple gems" do
|
29
|
+
setup do
|
30
|
+
Dir.stubs(:glob).returns(["whenever-0.3.7", "whenever-0.3.6"])
|
31
|
+
|
32
|
+
@gem = Mactag::Tag::Gem.new("whenever")
|
33
|
+
end
|
34
|
+
|
35
|
+
should "return the gem with the latest version" do
|
36
|
+
assert_contains @gem.files, "whenever-0.3.7/lib/**/*.rb"
|
37
|
+
assert_does_not_contain @gem.files, "whenever-0.3.6/lib/**/*.rb"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PluginTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
should "have correct plugin path" do
|
6
|
+
assert_equal "vendor/plugins", Mactag::Tag::Plugin::PLUGIN_PATH
|
7
|
+
end
|
8
|
+
|
9
|
+
context "without arguments" do
|
10
|
+
setup do
|
11
|
+
@plugin = Mactag::Tag::Plugin.new
|
12
|
+
end
|
13
|
+
|
14
|
+
should "return all plugins as path" do
|
15
|
+
assert_equal @plugin.files, "vendor/plugins/*/lib/**/*.rb"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with one plugin argument" do
|
20
|
+
setup do
|
21
|
+
@plugin = Mactag::Tag::Plugin.new("thinking-sphinx")
|
22
|
+
end
|
23
|
+
|
24
|
+
should "return the path to that plugin" do
|
25
|
+
assert_equal ["vendor/plugins/thinking-sphinx/lib/**/*.rb"], @plugin.files
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with more thatn one plugin argument" do
|
30
|
+
setup do
|
31
|
+
@plugin = Mactag::Tag::Plugin.new("thinking-sphinx", "formtastic")
|
32
|
+
end
|
33
|
+
|
34
|
+
should "return the paths to those plugins" do
|
35
|
+
assert_contains @plugin.files, "vendor/plugins/thinking-sphinx/lib/**/*.rb"
|
36
|
+
assert_contains @plugin.files, "vendor/plugins/formtastic/lib/**/*.rb"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RailsTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
should "have correct vendor path" do
|
6
|
+
assert_equal "vendor/rails", Mactag::Tag::Rails::VENDOR
|
7
|
+
end
|
8
|
+
|
9
|
+
should "have correct packages" do
|
10
|
+
packages = Mactag::Tag::Rails::PACKAGES
|
11
|
+
keys = packages.keys
|
12
|
+
|
13
|
+
assert_contains keys, :activesupport
|
14
|
+
assert_contains keys, :activeresource
|
15
|
+
assert_contains keys, :activerecord
|
16
|
+
assert_contains keys, :actionmailer
|
17
|
+
assert_contains keys, :actioncontroller
|
18
|
+
assert_contains keys, :actionview
|
19
|
+
end
|
20
|
+
|
21
|
+
should "have the correct paths" do
|
22
|
+
packages = Mactag::Tag::Rails::PACKAGES
|
23
|
+
|
24
|
+
assert_equal ["activesupport", "active_support"] , packages[:activesupport]
|
25
|
+
assert_equal ["activeresource", "active_resource"], packages[:activeresource]
|
26
|
+
assert_equal ["activerecord", "active_record"] , packages[:activerecord]
|
27
|
+
assert_equal ["actionmailer", "action_mailer"] , packages[:actionmailer]
|
28
|
+
assert_equal ["actionpack", "action_controller"] , packages[:actioncontroller]
|
29
|
+
assert_equal ["actionpack", "action_view"] , packages[:actionview]
|
30
|
+
end
|
31
|
+
|
32
|
+
context "packages" do
|
33
|
+
context "without arguments" do
|
34
|
+
setup do
|
35
|
+
@rails = Mactag::Tag::Rails.new({})
|
36
|
+
end
|
37
|
+
|
38
|
+
should "return all packages" do
|
39
|
+
assert_same_elements Mactag::Tag::Rails::PACKAGES.keys, @rails.send(:packages)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with some packages only" do
|
44
|
+
setup do
|
45
|
+
@rails = Mactag::Tag::Rails.new(:only => [:active_support, :activerecord])
|
46
|
+
end
|
47
|
+
|
48
|
+
should "return only those packages" do
|
49
|
+
assert_same_elements [:activesupport, :activerecord], @rails.send(:packages)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "except some packages" do
|
54
|
+
setup do
|
55
|
+
@rails = Mactag::Tag::Rails.new(:except => [:active_support, :activerecord])
|
56
|
+
end
|
57
|
+
|
58
|
+
should "return all except those packages" do
|
59
|
+
assert_same_elements Mactag::Tag::Rails::PACKAGES.keys - [:activesupport, :activerecord], @rails.send(:packages)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "rails in vendor" do
|
65
|
+
setup do
|
66
|
+
File.stubs(:exist?).returns(true)
|
67
|
+
end
|
68
|
+
|
69
|
+
should "be in vendor since file exist" do
|
70
|
+
assert Mactag::Tag::Rails.send(:vendor?)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "rails home" do
|
75
|
+
context "when rails is in vendor" do
|
76
|
+
setup do
|
77
|
+
Mactag::Tag::Rails.stubs(:vendor?).returns(true)
|
78
|
+
|
79
|
+
@rails = Mactag::Tag::Rails.new({})
|
80
|
+
end
|
81
|
+
|
82
|
+
should "return vendor" do
|
83
|
+
assert_equal Mactag::Tag::Rails::VENDOR, @rails.send(:rails_home)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "when rails is installed as a gem" do
|
88
|
+
setup do
|
89
|
+
Mactag::Tag::Rails.stubs(:vendor?).returns(false)
|
90
|
+
|
91
|
+
@rails = Mactag::Tag::Rails.new({})
|
92
|
+
end
|
93
|
+
|
94
|
+
should "return gem home" do
|
95
|
+
assert_equal Mactag::Config.gem_home, @rails.send(:rails_home)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "packagize" do
|
101
|
+
setup do
|
102
|
+
@rails = Mactag::Tag::Rails.new({})
|
103
|
+
end
|
104
|
+
|
105
|
+
context "one package" do
|
106
|
+
setup do
|
107
|
+
@packagized = @rails.send(:packagize!, "active_record")
|
108
|
+
end
|
109
|
+
|
110
|
+
should "be packagized" do
|
111
|
+
assert_equal [:activerecord], @packagized
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "several packages" do
|
116
|
+
setup do
|
117
|
+
@packagized = @rails.send(:packagize!, ["_active_support_", "action_view"])
|
118
|
+
end
|
119
|
+
|
120
|
+
should "be packagized" do
|
121
|
+
assert_equal [:activesupport, :actionview], @packagized
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "package paths" do
|
127
|
+
context "when rails is in vendor" do
|
128
|
+
setup do
|
129
|
+
Mactag::Tag::Rails.stubs(:vendor?).returns(true)
|
130
|
+
|
131
|
+
@rails = Mactag::Tag::Rails.new({})
|
132
|
+
end
|
133
|
+
|
134
|
+
should "return the correct path" do
|
135
|
+
assert_equal "activerecord/lib/active_record", @rails.send(:package_path, :activerecord)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "when rails is installed as a gem" do
|
140
|
+
setup do
|
141
|
+
Mactag::Tag::Rails.stubs(:vendor?).returns(false)
|
142
|
+
end
|
143
|
+
|
144
|
+
context "and there is a specific version" do
|
145
|
+
setup do
|
146
|
+
@rails = Mactag::Tag::Rails.new(:version => "3.0.0")
|
147
|
+
end
|
148
|
+
|
149
|
+
should "return the correct path" do
|
150
|
+
assert_equal "activerecord-3.0.0/lib/active_record", @rails.send(:package_path, :activerecord)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context "and there is no version specified" do
|
155
|
+
setup do
|
156
|
+
@rails = Mactag::Tag::Rails.new({})
|
157
|
+
end
|
158
|
+
|
159
|
+
context "and there is only one version of rails" do
|
160
|
+
setup do
|
161
|
+
Dir.stubs(:glob).returns("activerecord-2.3.5")
|
162
|
+
end
|
163
|
+
|
164
|
+
should "return the correct path" do
|
165
|
+
assert_equal "activerecord-2.3.5/lib/active_record", @rails.send(:package_path, :activerecord)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context "and there are two versions of rails" do
|
170
|
+
setup do
|
171
|
+
Dir.stubs(:glob).returns(["activerecord-2.3.5", "activerecord-2.3.4"])
|
172
|
+
end
|
173
|
+
|
174
|
+
should "return the correct path" do
|
175
|
+
assert_equal "activerecord-2.3.5/lib/active_record", @rails.send(:package_path, :activerecord)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|