mactag 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/README.markdown +19 -16
  2. data/VERSION +1 -1
  3. data/features/app.feature +82 -16
  4. data/features/gem.feature +116 -36
  5. data/features/plugin.feature +86 -21
  6. data/features/rails.feature +6 -0
  7. data/features/step_definitions/mactag_steps.rb +43 -0
  8. data/features/support/env.rb +4 -0
  9. data/features/support/rails_app.rb +20 -48
  10. data/features/support/tags_file.rb +8 -5
  11. data/lib/generators/mactag/templates/mactag.rb +50 -9
  12. data/lib/mactag.rb +1 -1
  13. data/lib/mactag/config.rb +28 -7
  14. data/lib/mactag/table.rb +22 -9
  15. data/lib/mactag/tag/app.rb +10 -10
  16. data/lib/mactag/tag/gem.rb +51 -17
  17. data/lib/mactag/tag/parser.rb +12 -2
  18. data/lib/mactag/tag/plugin.rb +15 -12
  19. data/lib/mactag/tag/rails.rb +43 -67
  20. data/test/mactag/config_test.rb +33 -3
  21. data/test/mactag/tag/app_test.rb +3 -5
  22. data/test/mactag/tag/gem_test.rb +47 -20
  23. data/test/mactag/tag/plugin_test.rb +23 -25
  24. data/test/mactag/tag/rails_test.rb +18 -123
  25. metadata +105 -27
  26. data/TODO +0 -8
  27. data/features/rails/actionmailer/lib/action_mailer/base.rb +0 -9
  28. data/features/rails/actionpack/lib/action_controller/caching/actions.rb +0 -11
  29. data/features/rails/actionpack/lib/action_view/action_view/helpers/form_tag_helper.rb +0 -9
  30. data/features/rails/activerecord/lib/active_record/associations.rb +0 -9
  31. data/features/rails/activeresource/lib/active_resource/connection.rb +0 -7
  32. data/features/rails/activesupport/lib/active_support/core_ext/hash/diff.rb +0 -5
  33. data/features/rails_gem.feature +0 -89
  34. data/features/rails_vendor.feature +0 -57
  35. data/features/step_definitions/gem_steps.rb +0 -22
  36. data/features/step_definitions/mactab_steps.rb +0 -57
  37. data/features/step_definitions/plugin_steps.rb +0 -22
  38. data/features/step_definitions/rails_steps.rb +0 -20
  39. data/lib/mactag/tag/versioned.rb +0 -22
@@ -1,33 +1,43 @@
1
1
  module Mactag
2
2
  module Tag
3
3
  class Parser
4
-
5
4
  def initialize(table)
6
5
  @table = table
7
6
  end
8
7
 
8
+ ##
9
+ #
9
10
  # @see Mactag::Tag::App
11
+ #
10
12
  def app(*files)
11
13
  @table << Mactag::Tag::App.new(*files)
12
14
  end
13
15
 
16
+ ##
17
+ #
14
18
  # @see Mactag::Tag::Plugin
19
+ #
15
20
  def plugin(*plugins)
16
21
  @table << Mactag::Tag::Plugin.new(*plugins)
17
22
  end
18
23
  alias_method :plugins, :plugin
19
24
 
25
+ ##
26
+ #
20
27
  # @see Mactag::Tag::Gem
28
+ #
21
29
  def gem(*gems)
22
30
  @table << Mactag::Tag::Gem.new(*gems)
23
31
  end
24
32
  alias_method :gems, :gem
25
33
 
34
+ ##
35
+ #
26
36
  # @see Mactag::Tag::Rails
37
+ #
27
38
  def rails(options = {})
28
39
  @table << Mactag::Tag::Rails.new(options)
29
40
  end
30
-
31
41
  end
32
42
  end
33
43
  end
@@ -1,38 +1,41 @@
1
1
  module Mactag
2
2
  module Tag
3
-
4
- # Tag for the current project plugins.
3
+ ##
4
+ #
5
+ # Tags plugins in current Rails application.
5
6
  #
6
7
  # ==== Examples
7
8
  # Mactag::Table.generate do
8
- # # Tag the whenever plugin
9
- # plugin "whenever"
9
+ # # Tag single plugin
10
+ # plugin 'whenever'
11
+ #
12
+ # # Tag multiple plugins
13
+ # plugins 'thinking-sphinx', 'formtastic'
10
14
  #
11
- # # Tag the thinking-sphinx and formtastic plugins
12
- # plugins "thinking-sphinx", "formtastic"
15
+ # # Tag all plugins
16
+ # plugins
13
17
  # do
18
+ #
14
19
  class Plugin
15
-
16
- PLUGIN_PATH = File.join("vendor", "plugins")
20
+ PLUGIN_PATH = File.join('vendor', 'plugins')
17
21
 
18
22
  def initialize(*plugins)
19
23
  @plugins = plugins
20
24
  end
21
25
 
22
26
  def files
23
- return File.join(PLUGIN_PATH, "*", "lib", "**", "*.rb") if @plugins.empty?
27
+ return File.join(PLUGIN_PATH, '*', 'lib', '**', '*.rb') if @plugins.empty?
24
28
 
25
29
  result = []
26
30
  @plugins.each do |plugin|
27
31
  if File.exist?(File.join(PLUGIN_PATH, plugin))
28
- result << File.join(PLUGIN_PATH, plugin, "lib", "**", "*.rb")
32
+ result << File.join(PLUGIN_PATH, plugin, 'lib', '**', '*.rb')
29
33
  else
30
- $stderr.puts "Plugin #{plugin} not found"
34
+ Mactag.warn "Plugin #{plugin} not found"
31
35
  end
32
36
  end
33
37
  result
34
38
  end
35
-
36
39
  end
37
40
  end
38
41
  end
@@ -1,19 +1,20 @@
1
- require 'mactag/tag/versioned'
2
-
3
1
  module Mactag
4
2
  module Tag
5
-
6
- # Tag for the Rails source.
3
+ ##
4
+ #
5
+ # Tags Rails gem.
7
6
  #
8
7
  # ==== Packages
9
- # Naming does not matter. So *activerecord* and *active_record* are the same.
8
+ # Naming does not matter, so *activerecord* and *active_record* are the same.
10
9
  #
11
- # * activesupport
12
- # * activeresource
13
- # * activerecord
14
10
  # * actionmailer
15
- # * actioncontroller
16
- # * actionview
11
+ # * actionpack
12
+ # * activemodel
13
+ # * activerecord
14
+ # * activeresource
15
+ # * railties
16
+ # * activesupport
17
+ #
17
18
  #
18
19
  # ==== Examples
19
20
  # Mactag::Table.generate do
@@ -21,7 +22,7 @@ module Mactag
21
22
  # rails
22
23
  #
23
24
  # # Tag all rails packages, version 2.3.5
24
- # rails :version => "2.3.5"
25
+ # rails :version => '2.3.5'
25
26
  #
26
27
  # # Tag only activerecord, latest version
27
28
  # rails :only => :active_record
@@ -33,25 +34,22 @@ module Mactag
33
34
  # rails :only => [:activerecord, :action_view]
34
35
  #
35
36
  # # Tag all packages except activerecord and actionview, latest version
36
- # rails :except => ["activerecord", :action_controller]
37
+ # rails :except => ['activerecord', :action_controller]
37
38
  #
38
39
  # # Tag all packages except actionmailer, version 2.3.4
39
- # rails :except => :actionmailer, :version => "2.3.4"
40
+ # rails :except => :actionmailer, :version => '2.3.4'
40
41
  # do
42
+ #
41
43
  class Rails
42
-
43
- include Versioned
44
-
45
- VENDOR = File.join("vendor", "rails")
46
-
47
- PACKAGES = {
48
- :activesupport => ["activesupport", "active_support"],
49
- :activeresource => ["activeresource", "active_resource"],
50
- :activerecord => ["activerecord", "active_record"],
51
- :actionmailer => ["actionmailer", "action_mailer"],
52
- :actioncontroller => ["actionpack", "action_controller"],
53
- :actionview => ["actionpack", "action_view"]
54
- }
44
+ PACKAGES = [
45
+ :actionmailer,
46
+ :actionpack,
47
+ :activemodel,
48
+ :activerecord,
49
+ :activeresource,
50
+ :railties,
51
+ :activesupport
52
+ ]
55
53
 
56
54
  def initialize(options)
57
55
  @options = options
@@ -62,65 +60,44 @@ module Mactag
62
60
 
63
61
  def files
64
62
  result = []
65
-
66
63
  packages.each do |package|
67
- path = []
68
- path << rails_home
69
- path << package_path(package)
70
- path << "**"
71
- path << "*.rb"
72
- path.flatten!
73
-
74
- result << Dir.glob(File.join(path))
64
+ if PACKAGES.include?(package)
65
+ if version = @options[:version]
66
+ gem = Gem.new(package.to_s, :version => version)
67
+ else
68
+ gem = Gem.new(package.to_s)
69
+ end
70
+ result << gem.files
71
+ end
75
72
  end
76
-
77
- result.flatten
73
+ result
78
74
  end
79
75
 
80
76
 
81
77
  private
82
78
 
79
+ ##
80
+ #
81
+ # Returns a list of all packages that should be included.
82
+ #
83
83
  def packages
84
84
  result = []
85
-
86
85
  unless @only || @except
87
- result = PACKAGES.keys
86
+ result = PACKAGES
88
87
  else
89
88
  if @only
90
89
  result = @only
91
90
  elsif @except
92
- result = PACKAGES.keys - @except
91
+ result = PACKAGES - @except
93
92
  end
94
93
  end
95
-
96
94
  result
97
95
  end
98
96
 
99
- def package_path(package)
100
- paths = PACKAGES[package].dup
101
- paths.insert(1, "lib")
102
-
103
- unless Mactag::Tag::Rails.vendor?
104
- top = paths.first
105
- if version = @options[:version]
106
- top = "#{top}-#{version}"
107
- else
108
- top = File.basename(latest(top))
109
- end
110
- paths[0] = top
111
- end
112
-
113
- File.join(paths)
114
- end
115
-
116
- def self.vendor?
117
- File.exist?(VENDOR)
118
- end
119
-
120
- def rails_home
121
- @rails_home ||= Mactag::Tag::Rails.vendor? ? VENDOR : Mactag::Config.gem_home
122
- end
123
-
97
+ ##
98
+ #
99
+ # Packagizes all +pkgs+.
100
+ #
124
101
  def packagize!(pkgs)
125
102
  return nil if pkgs.blank?
126
103
 
@@ -128,7 +105,6 @@ module Mactag
128
105
  "#{pkg}".gsub(/[^a-z]/, '').to_sym
129
106
  end
130
107
  end
131
-
132
108
  end
133
109
  end
134
110
  end
@@ -1,10 +1,40 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class ConfigTest < ActiveSupport::TestCase
4
+ context 'binary' do
5
+ setup do
6
+ @binary = Mactag::Config.binary
7
+ end
4
8
 
5
- should "have correct default options" do
6
- assert_equal "ctags -o TAGS -e", Mactag::Config.binary
7
- assert_equal "/Library/Ruby/Gems/1.8/gems", Mactag::Config.gem_home
9
+ should 'be right command' do
10
+ assert_equal 'ctags -o TAGS -e', @binary
11
+ end
8
12
  end
9
13
 
14
+ context 'gem home' do
15
+ context 'when using RVM' do
16
+ setup do
17
+ Mactag::Config.stubs(:rvm).returns(true)
18
+ File.stubs(:join).returns('/path/to/rvm/gems')
19
+
20
+ @gem_home = Mactag::Config.gem_home
21
+ end
22
+
23
+ should 'correct' do
24
+ assert_equal '/path/to/rvm/gems', @gem_home
25
+ end
26
+ end
27
+
28
+ context 'when not using RVM' do
29
+ setup do
30
+ Mactag::Config.stubs(:rvm).returns(false)
31
+
32
+ @gem_home = Mactag::Config.gem_home
33
+ end
34
+
35
+ should 'correct' do
36
+ assert_equal '/Library/Ruby/Gems/1.8/gems', @gem_home
37
+ end
38
+ end
39
+ end
10
40
  end
@@ -1,16 +1,14 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class AppTest < ActiveSupport::TestCase
4
-
5
- context "an app tag" do
4
+ context 'application tag' do
6
5
  setup do
7
- @tags = [ "app/**/*.rb", "public/javascripts/*.js" ]
6
+ @tags = ['app/**/*.rb', 'public/javascripts/*.js']
8
7
  @app = Mactag::Tag::App.new(@tags)
9
8
  end
10
9
 
11
- should "return the correct files" do
10
+ should 'return the correct files' do
12
11
  assert_same_elements [@tags], @app.files
13
12
  end
14
13
  end
15
-
16
14
  end
@@ -1,56 +1,83 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class GemTest < ActiveSupport::TestCase
4
+ def setup
5
+ File.stubs(:directory?).returns(true)
6
+ end
4
7
 
5
- context "gem with version" do
8
+ context 'gem with version' do
6
9
  setup do
7
- @gem = Mactag::Tag::Gem.new("thinking-sphinx", :version => "1.0.0")
10
+ Mactag::Config.stubs(:gem_home).returns('GEM_HOME')
11
+
12
+ @gem = Mactag::Tag::Gem.new('thinking-sphinx', :version => '1.0.0')
8
13
  end
9
14
 
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")
15
+ should 'return the gem with that version' do
16
+ assert_contains @gem.files, File.join('GEM_HOME', 'thinking-sphinx-1.0.0', 'lib', '**', '*.rb')
12
17
  end
13
18
  end
14
19
 
15
- context "gem without version" do
16
- context "one gem" do
20
+ context 'gem without version' do
21
+ context 'single gem' do
17
22
  setup do
18
- Dir.stubs(:glob).returns("whenever")
23
+ Dir.stubs(:glob).returns(['whenever-0.3.7'])
19
24
 
20
- @gem = Mactag::Tag::Gem.new("whenever")
25
+ @gem = Mactag::Tag::Gem.new('whenever')
21
26
  end
22
27
 
23
- should "return that gem" do
24
- assert_contains @gem.files, "whenever/lib/**/*.rb"
28
+ should 'return that gem' do
29
+ assert_contains @gem.files, File.join('whenever-0.3.7', 'lib', '**', '*.rb')
25
30
  end
26
31
  end
27
32
 
28
- context "multiple gems" do
33
+ context 'multiple gems' do
29
34
  setup do
30
- Dir.stubs(:glob).returns(["whenever-0.3.7", "whenever-0.3.6"])
35
+ Dir.stubs(:glob).returns(['whenever-0.3.7', 'whenever-0.3.6'])
31
36
 
32
- @gem = Mactag::Tag::Gem.new("whenever")
37
+ @gem = Mactag::Tag::Gem.new('whenever')
33
38
  end
34
39
 
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"
40
+ should 'return the gem with the latest version' do
41
+ assert_contains @gem.files, File.join('whenever-0.3.7', 'lib', '**', '*.rb')
42
+ assert_does_not_contain @gem.files, File.join('whenever-0.3.6', 'lib', '**', '*.rb')
38
43
  end
39
44
  end
40
45
  end
41
46
 
42
- context "gem that does not exist" do
47
+ context 'gem that does not exist' do
43
48
  setup do
44
- Dir.stubs(:glob).returns([nil])
49
+ Dir.stubs(:glob).returns([])
50
+ File.stubs(:directory?).returns(false)
45
51
 
46
- @gem = Mactag::Tag::Gem.new("whenever")
52
+ @gem = Mactag::Tag::Gem.new('whenever')
47
53
  end
48
54
 
49
- should "not raise exception because no such gem" do
55
+ should 'not raise exception because no such gem' do
50
56
  assert_nothing_raised do
51
57
  assert_equal [], @gem.files
52
58
  end
53
59
  end
54
60
  end
55
61
 
62
+ context '#exists?' do
63
+ setup do
64
+ @gem = Mactag::Tag::Gem.new('whatever')
65
+ end
66
+
67
+ context 'with valid gem' do
68
+ setup do
69
+ File.stubs(:directory?).returns(true)
70
+ end
71
+
72
+ should 'exist' do
73
+ assert @gem.send(:exists?, 'whatever')
74
+ end
75
+ end
76
+
77
+ context 'with no gem' do
78
+ should 'exist' do
79
+ assert !@gem.send(:exists?, nil)
80
+ end
81
+ end
82
+ end
56
83
  end
@@ -1,60 +1,58 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class PluginTest < ActiveSupport::TestCase
4
-
5
- should "have correct plugin path" do
6
- assert_equal "vendor/plugins", Mactag::Tag::Plugin::PLUGIN_PATH
4
+ should 'have correct plugin path' do
5
+ assert_equal 'vendor/plugins', Mactag::Tag::Plugin::PLUGIN_PATH
7
6
  end
8
7
 
9
- context "without arguments" do
8
+ context 'with no arguments' do
10
9
  setup do
11
- File.stubs(:exist?).returns(true)
12
-
13
10
  @plugin = Mactag::Tag::Plugin.new
14
11
  end
15
12
 
16
- should "return all plugins as path" do
17
- assert_equal @plugin.files, "vendor/plugins/*/lib/**/*.rb"
13
+ should 'return all plugins as path' do
14
+ assert_equal @plugin.files, 'vendor/plugins/*/lib/**/*.rb'
18
15
  end
19
16
  end
20
17
 
21
- context "with one plugin argument" do
18
+ context 'with single plugin' do
22
19
  setup do
23
20
  File.stubs(:exist?).returns(true)
24
-
25
- @plugin = Mactag::Tag::Plugin.new("thinking-sphinx")
21
+
22
+ @plugin = Mactag::Tag::Plugin.new('thinking-sphinx')
26
23
  end
27
24
 
28
- should "return the path to that plugin" do
29
- assert_equal ["vendor/plugins/thinking-sphinx/lib/**/*.rb"], @plugin.files
25
+ should 'return the path to that plugin' do
26
+ assert_same_elements ['vendor/plugins/thinking-sphinx/lib/**/*.rb'], @plugin.files
30
27
  end
31
28
  end
32
29
 
33
- context "with more thatn one plugin argument" do
30
+ context 'with multiple plugins' do
34
31
  setup do
35
32
  File.stubs(:exist?).returns(true)
36
-
37
- @plugin = Mactag::Tag::Plugin.new("thinking-sphinx", "formtastic")
33
+
34
+ @plugin = Mactag::Tag::Plugin.new('thinking-sphinx', 'formtastic')
38
35
  end
39
36
 
40
- should "return the paths to those plugins" do
41
- assert_contains @plugin.files, "vendor/plugins/thinking-sphinx/lib/**/*.rb"
42
- assert_contains @plugin.files, "vendor/plugins/formtastic/lib/**/*.rb"
37
+ should 'return the paths to those plugins' do
38
+ assert_same_elements @plugin.files, [
39
+ 'vendor/plugins/thinking-sphinx/lib/**/*.rb',
40
+ 'vendor/plugins/formtastic/lib/**/*.rb'
41
+ ]
43
42
  end
44
43
  end
45
44
 
46
- context "plugin that does not exist" do
45
+ context 'plugin that does not exist' do
47
46
  setup do
48
47
  File.stubs(:exist?).returns(false)
49
-
50
- @plugin = Mactag::Tag::Plugin.new("typo")
48
+
49
+ @plugin = Mactag::Tag::Plugin.new('typo')
51
50
  end
52
51
 
53
- should "not raise exception because no such plugin" do
52
+ should 'not raise exception because no such plugin' do
54
53
  assert_nothing_raised do
55
- assert_equal [], @plugin.files
54
+ assert_same_elements [], @plugin.files
56
55
  end
57
56
  end
58
57
  end
59
-
60
58
  end