mactag 0.5.4 → 0.6.0

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/.gemtest DELETED
File without changes
@@ -1,9 +0,0 @@
1
- require 'mactag/tag/app'
2
- require 'mactag/tag/plugin'
3
- require 'mactag/tag/gem'
4
- require 'mactag/tag/rails'
5
-
6
- module Mactag
7
- module Tag
8
- end
9
- end
@@ -1,30 +0,0 @@
1
- module Mactag
2
- module Tag
3
- ##
4
- #
5
- # Tag files in Rails project.
6
- #
7
- # ==== Examples
8
- # Mactag do
9
- # # Tag single file
10
- # app 'lib/super_duper.rb'
11
- #
12
- # # Tag all ruby files in lib, recursive
13
- # app 'lib/**/*.rb'
14
- #
15
- # # Tag all helper and model ruby files
16
- # app 'app/helpers/*.rb', 'app/models/*.rb'
17
- #
18
- # # Same as above
19
- # app 'app/{models,helpers}/*.rb'
20
- # do
21
- #
22
- class App
23
- attr_reader :tag
24
-
25
- def initialize(tag)
26
- @tag = tag
27
- end
28
- end
29
- end
30
- end
@@ -1,80 +0,0 @@
1
- module Mactag
2
- module Tag
3
- ##
4
- #
5
- # Tags ruby gems.
6
- #
7
- # ==== Examples
8
- # Mactag do
9
- # # Tags all gems specified in Gemfile.
10
- # gems
11
- #
12
- # # Tag the whenever gem, latest version
13
- # gem 'whenever'
14
- #
15
- # # Tag the thinking-sphinx and formtastic gems, latest versions
16
- # gems 'thinking-sphinx', 'formtastic'
17
- #
18
- # # Tag the formtastic gem, version 0.8.2
19
- # gem 'formtastic', :version => '0.8.2'
20
- # do
21
- #
22
- class Gem
23
- attr_accessor :name, :version
24
-
25
- def initialize(name, version = nil)
26
- @name = name
27
- @version = version
28
- end
29
-
30
- def tag
31
- if exists?
32
- unless version
33
- @version = Mactag::Tag::Gem.last(name)
34
- end
35
-
36
- File.join(Mactag::Config.gem_home, combo, 'lib', '**', '*.rb')
37
- else
38
- raise GemNotFoundError.new(self)
39
- end
40
- end
41
-
42
- def exists?
43
- Mactag::Tag::Gem.dirs(name).size > 0
44
- end
45
-
46
- class << self
47
- def all
48
- # Mactag::Bundler.gems
49
- bundler = Mactag::Bundler.new
50
- bundler.gems
51
- end
52
-
53
- def last(name)
54
- dirs = Mactag::Tag::Gem.dirs(name)
55
- unless dirs.empty?
56
- if dirs.size == 1
57
- gem = dirs.first
58
- else
59
- gem = dirs.sort.last
60
- end
61
- if /-([^\/]+)$/.match(gem)
62
- $1
63
- end
64
- end
65
- end
66
-
67
- def dirs(name)
68
- Dir.glob(File.join(Mactag::Config.gem_home, "#{name}-*"))
69
- end
70
- end
71
-
72
-
73
- private
74
-
75
- def combo
76
- "#{name}-#{version}"
77
- end
78
- end
79
- end
80
- end
@@ -1,86 +0,0 @@
1
- module Mactag
2
- module Tag
3
- ##
4
- #
5
- # Tags Rails gem.
6
- #
7
- # ==== Packages
8
- # Naming does not matter, so *activerecord* and *active_record* are the same.
9
- #
10
- # * actionmailer
11
- # * actionpack
12
- # * activemodel
13
- # * activerecord
14
- # * activeresource
15
- # * railties
16
- # * activesupport
17
- #
18
- #
19
- # ==== Examples
20
- # Mactag do
21
- # # Tag all rails packages, same rails version as application
22
- # rails
23
- #
24
- # # Tag all rails packages, version 2.3.5
25
- # rails :version => '2.3.5'
26
- #
27
- # # Tag only activerecord, same rails version as application
28
- # rails :only => :active_record
29
- #
30
- # # Tag all packages except activerecord, same rails version as application
31
- # rails :except => :activerecord
32
- #
33
- # # Tag only activerecord and actionview, same rails version as application
34
- # rails :only => [:activerecord, :action_view]
35
- #
36
- # # Tag all packages except activerecord and actionview, same rails version as application
37
- # rails :except => ['activerecord', :action_controller]
38
- #
39
- # # Tag all packages except actionmailer, version 2.3.4
40
- # rails :except => :actionmailer, :version => '2.3.4'
41
- # do
42
- #
43
- class Rails
44
-
45
- PACKAGES = %w(actionmailer actionpack activemodel activerecord activeresource activesupport railties)
46
-
47
- attr_accessor :only, :except, :version
48
-
49
- def initialize(options)
50
- @only = packagize(options[:only])
51
- @except = packagize(options[:except])
52
- @version = options[:version]
53
- end
54
-
55
- def tag
56
- packages.inject([]) do |array, package|
57
- array << Gem.new(package, version).tag
58
- array
59
- end
60
- end
61
-
62
- def packages
63
- if only || except
64
- only || PACKAGES - except
65
- else
66
- PACKAGES
67
- end
68
- end
69
-
70
-
71
- private
72
-
73
- def packagize(pkgs)
74
- return nil if pkgs.blank?
75
-
76
- Array(pkgs).map do |pkg|
77
- "#{pkg}".gsub(/[^a-z]/, '')
78
- end
79
- end
80
-
81
- def version
82
- @version || ::Rails.version
83
- end
84
- end
85
- end
86
- end
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Mactag::Tag::App do
4
- subject do
5
- Mactag::Tag::App.new('app')
6
- end
7
-
8
- it_should_behave_like 'tagger'
9
- end
@@ -1,117 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Mactag::Tag::Gem do
4
- subject do
5
- Mactag::Tag::Gem.new('devise')
6
- end
7
-
8
- it_should_behave_like 'tagger'
9
-
10
- before do
11
- Mactag::Config.stub(:gem_home) { 'GEM_HOME' }
12
-
13
- @gem = Mactag::Tag::Gem.new('devise')
14
- end
15
-
16
- describe '#tag' do
17
- context 'when gem exists' do
18
- before do
19
- @gem.stub(:exists?) { true }
20
- end
21
-
22
- context 'without version' do
23
- before do
24
- Mactag::Tag::Gem.stub(:last) { '1.1.1' }
25
- end
26
-
27
- it 'returns path to gem' do
28
- @gem.tag.should eq('GEM_HOME/devise-1.1.1/lib/**/*.rb')
29
- end
30
- end
31
-
32
- context 'with version' do
33
- before do
34
- @gem.stub(:version) { '1.1.1' }
35
- end
36
-
37
- it 'returns path to gem' do
38
- @gem.tag.should eq('GEM_HOME/devise-1.1.1/lib/**/*.rb')
39
- end
40
- end
41
- end
42
-
43
- context 'when gem does not exist' do
44
- before do
45
- @gem.stub(:exists?) { false }
46
- end
47
-
48
- it 'raises exception' do
49
- proc {
50
- @gem.tag
51
- }.should raise_exception(Mactag::GemNotFoundError)
52
- end
53
- end
54
- end
55
-
56
- describe '#exists?' do
57
- context 'without version' do
58
- it 'is true when single version of gem exists' do
59
- Dir.stub(:glob) { ['devise-1.1.1'] }
60
- @gem.exists?.should be_true
61
- end
62
-
63
- it 'is true when multiple versions of gem exists' do
64
- Dir.stub(:glob) { %w(devise-1.1.0 devise-1.1.1) }
65
- @gem.exists?.should be_true
66
- end
67
-
68
- it 'is false when gem does not exist' do
69
- Dir.stub(:glob) { [] }
70
- @gem.exists?.should be_false
71
- end
72
- end
73
- end
74
-
75
- describe '#last' do
76
- context 'when no gems exists' do
77
- before do
78
- Mactag::Tag::Gem.stub(:dirs) { [] }
79
- end
80
-
81
- it 'returns nil' do
82
- Mactag::Tag::Gem.last('devise').should be_nil
83
- end
84
- end
85
-
86
- context 'when single version of gem exist' do
87
- before do
88
- Mactag::Tag::Gem.stub(:dirs) { ['devise-1.1.1'] }
89
- end
90
-
91
- it 'returns nil' do
92
- Mactag::Tag::Gem.last('devise').should eq('1.1.1')
93
- end
94
- end
95
-
96
- context 'when multiple versions of gem exist' do
97
- before do
98
- Mactag::Tag::Gem.stub(:dirs) { ['devise-1.1.0', 'devise-1.1.1'] }
99
- end
100
-
101
- it 'returns nil' do
102
- Mactag::Tag::Gem.last('devise').should eq('1.1.1')
103
- end
104
- end
105
-
106
- context 'when the path contains other version numbers' do
107
- before do
108
- Mactag::Tag::Gem.stub(:dirs) { ['/Users/user/.rvm/gems/ree-1.8.7-2011.03@project/gems/simple_form-1.3.1'] }
109
- end
110
-
111
- it 'extract correct version' do
112
- Mactag::Tag::Gem.last('simple_form').should eq('1.3.1')
113
- end
114
- end
115
-
116
- end
117
- end
@@ -1,105 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Mactag::Tag::Rails do
4
- subject do
5
- Mactag::Tag::Rails.new({})
6
- end
7
-
8
- it_should_behave_like 'tagger'
9
-
10
- before do
11
- @rails = Mactag::Tag::Rails.new({})
12
- end
13
-
14
- it 'has correct default packages' do
15
- Mactag::Tag::Rails::PACKAGES.should eq(['actionmailer', 'actionpack', 'activemodel', 'activerecord', 'activeresource', 'activesupport', 'railties'])
16
- end
17
-
18
- describe '#tag' do
19
- before do
20
- Mactag::Tag::Gem.stub(:new) { mock(:tag => 'tag') }
21
- end
22
-
23
- it 'returns empty array if no packages' do
24
- @rails.stub(:packages) { [] }
25
-
26
- @rails.tag.should eq([])
27
- end
28
-
29
- it 'returns array with gem tags when packages' do
30
- @rails.stub(:packages) { ['activemodel', 'activerecord'] }
31
-
32
- @rails.tag.should eq(['tag', 'tag'])
33
- end
34
- end
35
-
36
- describe '#packages' do
37
- it 'returns all packages unless only and except' do
38
- @rails.packages.should eq(Mactag::Tag::Rails::PACKAGES)
39
- end
40
-
41
- it 'returns some packages when only specified' do
42
- @rails = Mactag::Tag::Rails.new(:only => [:active_support, :activerecord])
43
-
44
- @rails.packages.should eq(['activesupport', 'activerecord'])
45
- end
46
-
47
- it 'returns some packages when except specified' do
48
- @rails = Mactag::Tag::Rails.new(:except => [:active_support, :activerecord])
49
-
50
- @rails.packages.should eq(['actionmailer', 'actionpack', 'activemodel', 'activeresource', 'railties'])
51
- end
52
- end
53
-
54
- describe '#packagize' do
55
- it 'returns empty array when no packages' do
56
- @rails.send(:packagize, []).should be_nil
57
- end
58
-
59
- context 'single package' do
60
- it 'packagizes when symbol' do
61
- @rails.send(:packagize, [:activerecord]).should eq(['activerecord'])
62
- end
63
-
64
- it 'packagizes when string' do
65
- @rails.send(:packagize, ['activerecord']).should eq(['activerecord'])
66
- end
67
-
68
- it 'packagizes when underscore' do
69
- @rails.send(:packagize, [:active_record]).should eq(['activerecord'])
70
- end
71
- end
72
-
73
- context 'multiples packages' do
74
- it 'packagizes when symbols' do
75
- @rails.send(:packagize, [:activerecord, :activemodel]).should eq(['activerecord', 'activemodel'])
76
- end
77
-
78
- it 'packagizes when string' do
79
- @rails.send(:packagize, ['activerecord', 'activemodel']).should eq(['activerecord', 'activemodel'])
80
- end
81
-
82
- it 'packagizes when underscore' do
83
- @rails.send(:packagize, [:active_record, :active_model]).should eq(['activerecord', 'activemodel'])
84
- end
85
-
86
- it 'packagizes when mixed' do
87
- @rails.send(:packagize, [:active_record, 'activemodel']).should eq(['activerecord', 'activemodel'])
88
- end
89
- end
90
- end
91
-
92
- describe '#version' do
93
- it 'returns specified version when version option' do
94
- @rails = Mactag::Tag::Rails.new(:version => '3.0.0')
95
-
96
- @rails.send(:version).should eq('3.0.0')
97
- end
98
-
99
- it 'returns same version as rails application when version option is not specified' do
100
- Rails.stub(:version) { '3.0.0' }
101
-
102
- @rails.send(:version).should eq('3.0.0')
103
- end
104
- end
105
- end
@@ -1,5 +0,0 @@
1
- describe 'Tag' do
2
- it 'does not pollute the global namespace' do
3
- Object.const_defined?(:Tag).should be_false
4
- end
5
- end