mactag 0.4.0 → 0.5.3
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 +0 -0
 - data/README.markdown +36 -65
 - data/Rakefile +12 -0
 - data/VERSION +1 -1
 - data/lib/generators/mactag/templates/mactag.rb +43 -19
 - data/lib/mactag.rb +2 -8
 - data/lib/mactag/builder.rb +24 -22
 - data/lib/mactag/bundler.rb +36 -0
 - data/lib/mactag/config.rb +6 -13
 - data/lib/mactag/ctags.rb +2 -2
 - data/lib/mactag/dsl.rb +16 -4
 - data/lib/mactag/errors.rb +32 -0
 - data/lib/mactag/tag.rb +3 -1
 - data/lib/mactag/tag/app.rb +3 -3
 - data/lib/mactag/tag/gem.rb +33 -33
 - data/lib/mactag/tag/plugin.rb +21 -15
 - data/lib/mactag/tag/rails.rb +22 -29
 - data/lib/tasks/mactag.rake +3 -16
 - data/spec/mactag/builder_spec.rb +68 -49
 - data/spec/mactag/bundler_spec.rb +4 -0
 - data/spec/mactag/config_spec.rb +13 -19
 - data/spec/mactag/ctags_spec.rb +11 -11
 - data/spec/mactag/dsl_spec.rb +46 -19
 - data/spec/mactag/tag/app_spec.rb +4 -9
 - data/spec/mactag/tag/gem_spec.rb +61 -65
 - data/spec/mactag/tag/plugin_spec.rb +42 -31
 - data/spec/mactag/tag/rails_spec.rb +54 -43
 - data/spec/mactag/tag_spec.rb +5 -0
 - metadata +23 -41
 - data/lib/mactag/event_handler.rb +0 -22
 - data/lib/mactag/server.rb +0 -48
 - data/lib/mactag/tags_file.rb +0 -31
 - data/spec/mactag/server_spec.rb +0 -4
 - data/spec/mactag/tags_file_spec.rb +0 -39
 
| 
         @@ -0,0 +1,32 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Mactag
         
     | 
| 
      
 2 
     | 
    
         
            +
              class MactagError < StandardError
         
     | 
| 
      
 3 
     | 
    
         
            +
              end
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              class PluginNotFoundError < MactagError
         
     | 
| 
      
 6 
     | 
    
         
            +
                attr_reader :plugin
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                def initialize(plugin)
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @plugin = plugin
         
     | 
| 
      
 10 
     | 
    
         
            +
                end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                def to_s
         
     | 
| 
      
 13 
     | 
    
         
            +
                  "Plugin #{plugin.name} not found"
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              class GemNotFoundError < MactagError
         
     | 
| 
      
 18 
     | 
    
         
            +
                attr_reader :gem
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def initialize(gem)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  @gem = gem
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                def to_s
         
     | 
| 
      
 25 
     | 
    
         
            +
                  if gem.version
         
     | 
| 
      
 26 
     | 
    
         
            +
                    "Gem #{gem.name} with version #{gem.version} not found"
         
     | 
| 
      
 27 
     | 
    
         
            +
                  else
         
     | 
| 
      
 28 
     | 
    
         
            +
                    "Gem #{gem.name} not found"
         
     | 
| 
      
 29 
     | 
    
         
            +
                  end
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/mactag/tag.rb
    CHANGED
    
    
    
        data/lib/mactag/tag/app.rb
    CHANGED
    
    | 
         @@ -2,17 +2,17 @@ module Mactag 
     | 
|
| 
       2 
2 
     | 
    
         
             
              module Tag
         
     | 
| 
       3 
3 
     | 
    
         
             
                ##
         
     | 
| 
       4 
4 
     | 
    
         
             
                #
         
     | 
| 
       5 
     | 
    
         
            -
                #  
     | 
| 
      
 5 
     | 
    
         
            +
                # Tag files in Rails project.
         
     | 
| 
       6 
6 
     | 
    
         
             
                #
         
     | 
| 
       7 
7 
     | 
    
         
             
                # ==== Examples
         
     | 
| 
       8 
8 
     | 
    
         
             
                #   Mactag do
         
     | 
| 
       9 
9 
     | 
    
         
             
                #     # Tag single file
         
     | 
| 
       10 
10 
     | 
    
         
             
                #     app 'lib/super_duper.rb'
         
     | 
| 
       11 
11 
     | 
    
         
             
                #
         
     | 
| 
       12 
     | 
    
         
            -
                #     # Tag all files in lib, recursive
         
     | 
| 
      
 12 
     | 
    
         
            +
                #     # Tag all ruby files in lib, recursive
         
     | 
| 
       13 
13 
     | 
    
         
             
                #     app 'lib/**/*.rb'
         
     | 
| 
       14 
14 
     | 
    
         
             
                #
         
     | 
| 
       15 
     | 
    
         
            -
                #     # Tag all  
     | 
| 
      
 15 
     | 
    
         
            +
                #     # Tag all helper and model ruby files
         
     | 
| 
       16 
16 
     | 
    
         
             
                #     app 'app/helpers/*.rb', 'app/models/*.rb'
         
     | 
| 
       17 
17 
     | 
    
         
             
                #
         
     | 
| 
       18 
18 
     | 
    
         
             
                #     # Same as above
         
     | 
    
        data/lib/mactag/tag/gem.rb
    CHANGED
    
    | 
         @@ -20,6 +20,8 @@ module Mactag 
     | 
|
| 
       20 
20 
     | 
    
         
             
                #   do
         
     | 
| 
       21 
21 
     | 
    
         
             
                #
         
     | 
| 
       22 
22 
     | 
    
         
             
                class Gem
         
     | 
| 
      
 23 
     | 
    
         
            +
                  attr_accessor :name, :version
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
       23 
25 
     | 
    
         
             
                  def initialize(name, version = nil)
         
     | 
| 
       24 
26 
     | 
    
         
             
                    @name = name
         
     | 
| 
       25 
27 
     | 
    
         
             
                    @version = version
         
     | 
| 
         @@ -27,53 +29,51 @@ module Mactag 
     | 
|
| 
       27 
29 
     | 
    
         | 
| 
       28 
30 
     | 
    
         
             
                  def tag
         
     | 
| 
       29 
31 
     | 
    
         
             
                    if exists?
         
     | 
| 
       30 
     | 
    
         
            -
                       
     | 
| 
       31 
     | 
    
         
            -
                         
     | 
| 
       32 
     | 
    
         
            -
                      else
         
     | 
| 
       33 
     | 
    
         
            -
                        gem = Gem.most_recent(@name)
         
     | 
| 
      
 32 
     | 
    
         
            +
                      unless version
         
     | 
| 
      
 33 
     | 
    
         
            +
                        @version = Mactag::Tag::Gem.last(name)
         
     | 
| 
       34 
34 
     | 
    
         
             
                      end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                      File.join(Mactag::Config.gem_home, combo, 'lib', '**', '*.rb')
         
     | 
| 
       36 
37 
     | 
    
         
             
                    else
         
     | 
| 
       37 
     | 
    
         
            -
                       
     | 
| 
      
 38 
     | 
    
         
            +
                      raise GemNotFoundError.new(self)
         
     | 
| 
       38 
39 
     | 
    
         
             
                    end
         
     | 
| 
       39 
40 
     | 
    
         
             
                  end
         
     | 
| 
       40 
41 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
                  def  
     | 
| 
       42 
     | 
    
         
            -
                     
     | 
| 
       43 
     | 
    
         
            -
                    Bundler.load.specs.each do |spec|
         
     | 
| 
       44 
     | 
    
         
            -
                      gems[spec.name] = spec.version.to_s
         
     | 
| 
       45 
     | 
    
         
            -
                    end
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
                    default = Bundler.load.dependencies.select { |dependency| dependency.groups.include?(:default) }.collect(&:name)
         
     | 
| 
       48 
     | 
    
         
            -
                    default.delete('rails')
         
     | 
| 
       49 
     | 
    
         
            -
                    default.collect { |tmp| Gem.new(tmp, gems[tmp]) }
         
     | 
| 
      
 42 
     | 
    
         
            +
                  def exists?
         
     | 
| 
      
 43 
     | 
    
         
            +
                    Mactag::Tag::Gem.dirs(name).size > 0
         
     | 
| 
       50 
44 
     | 
    
         
             
                  end
         
     | 
| 
       51 
45 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
                   
     | 
| 
       53 
     | 
    
         
            -
                     
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
                       
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
| 
       59 
64 
     | 
    
         
             
                      end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
      
 65 
     | 
    
         
            +
                    end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                    def dirs(name)
         
     | 
| 
      
 68 
     | 
    
         
            +
                      Dir.glob(File.join(Mactag::Config.gem_home, "#{name}-*"))
         
     | 
| 
       61 
69 
     | 
    
         
             
                    end
         
     | 
| 
       62 
70 
     | 
    
         
             
                  end
         
     | 
| 
       63 
71 
     | 
    
         | 
| 
       64 
72 
     | 
    
         | 
| 
       65 
73 
     | 
    
         
             
                  private
         
     | 
| 
       66 
74 
     | 
    
         | 
| 
       67 
     | 
    
         
            -
                  def  
     | 
| 
       68 
     | 
    
         
            -
                     
     | 
| 
       69 
     | 
    
         
            -
                      File.directory?(File.join(Mactag::Config.gem_home, splash))
         
     | 
| 
       70 
     | 
    
         
            -
                    else
         
     | 
| 
       71 
     | 
    
         
            -
                      Gem.most_recent(@name)
         
     | 
| 
       72 
     | 
    
         
            -
                    end
         
     | 
| 
       73 
     | 
    
         
            -
                  end
         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
                  def splash
         
     | 
| 
       76 
     | 
    
         
            -
                    "#{@name}-#{@version}"
         
     | 
| 
      
 75 
     | 
    
         
            +
                  def combo
         
     | 
| 
      
 76 
     | 
    
         
            +
                    "#{name}-#{version}"
         
     | 
| 
       77 
77 
     | 
    
         
             
                  end
         
     | 
| 
       78 
78 
     | 
    
         
             
                end
         
     | 
| 
       79 
79 
     | 
    
         
             
              end
         
     | 
    
        data/lib/mactag/tag/plugin.rb
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ module Mactag 
     | 
|
| 
       2 
2 
     | 
    
         
             
              module Tag
         
     | 
| 
       3 
3 
     | 
    
         
             
                ##
         
     | 
| 
       4 
4 
     | 
    
         
             
                #
         
     | 
| 
       5 
     | 
    
         
            -
                #  
     | 
| 
      
 5 
     | 
    
         
            +
                # Tag plugins in Rails project.
         
     | 
| 
       6 
6 
     | 
    
         
             
                #
         
     | 
| 
       7 
7 
     | 
    
         
             
                # ==== Examples
         
     | 
| 
       8 
8 
     | 
    
         
             
                #   Mactag do
         
     | 
| 
         @@ -17,29 +17,35 @@ module Mactag 
     | 
|
| 
       17 
17 
     | 
    
         
             
                #   do
         
     | 
| 
       18 
18 
     | 
    
         
             
                #
         
     | 
| 
       19 
19 
     | 
    
         
             
                class Plugin
         
     | 
| 
       20 
     | 
    
         
            -
                  PLUGIN_PATH =  
     | 
| 
      
 20 
     | 
    
         
            +
                  PLUGIN_PATH = %w(vendor plugins)
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
                   
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
      
 22 
     | 
    
         
            +
                  attr_accessor :name
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                  def initialize(name)
         
     | 
| 
      
 25 
     | 
    
         
            +
                    @name = name
         
     | 
| 
       24 
26 
     | 
    
         
             
                  end
         
     | 
| 
       25 
27 
     | 
    
         | 
| 
       26 
28 
     | 
    
         
             
                  def tag
         
     | 
| 
       27 
29 
     | 
    
         
             
                    if exists?
         
     | 
| 
       28 
     | 
    
         
            -
                      return File.join(PLUGIN_PATH,  
     | 
| 
      
 30 
     | 
    
         
            +
                      return File.join(PLUGIN_PATH, name, 'lib', '**', '*.rb')
         
     | 
| 
       29 
31 
     | 
    
         
             
                    else
         
     | 
| 
       30 
     | 
    
         
            -
                       
     | 
| 
      
 32 
     | 
    
         
            +
                      raise PluginNotFoundError.new(self)
         
     | 
| 
       31 
33 
     | 
    
         
             
                    end
         
     | 
| 
       32 
34 
     | 
    
         
             
                  end
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                  def self.all
         
     | 
| 
       35 
     | 
    
         
            -
                    Dir.glob(File.join(PLUGIN_PATH, '*')).collect { |f| File.basename(f) }
         
     | 
| 
       36 
     | 
    
         
            -
                  end
         
     | 
| 
       37 
     | 
    
         
            -
                  
         
     | 
| 
       38 
     | 
    
         
            -
                  
         
     | 
| 
       39 
     | 
    
         
            -
                  private
         
     | 
| 
       40 
     | 
    
         
            -
                  
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
       41 
36 
     | 
    
         
             
                  def exists?
         
     | 
| 
       42 
     | 
    
         
            -
                    File.directory?( 
     | 
| 
      
 37 
     | 
    
         
            +
                    File.directory?(path)
         
     | 
| 
      
 38 
     | 
    
         
            +
                  end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                  def path
         
     | 
| 
      
 41 
     | 
    
         
            +
                    File.join(PLUGIN_PATH, name)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                  def self.all
         
     | 
| 
      
 45 
     | 
    
         
            +
                    pattern = File.join(PLUGIN_PATH, '*')
         
     | 
| 
      
 46 
     | 
    
         
            +
                    Dir.glob(pattern).map do |f|
         
     | 
| 
      
 47 
     | 
    
         
            +
                      File.basename(f)
         
     | 
| 
      
 48 
     | 
    
         
            +
                    end
         
     | 
| 
       43 
49 
     | 
    
         
             
                  end
         
     | 
| 
       44 
50 
     | 
    
         
             
                end
         
     | 
| 
       45 
51 
     | 
    
         
             
              end
         
     | 
    
        data/lib/mactag/tag/rails.rb
    CHANGED
    
    | 
         @@ -41,52 +41,45 @@ module Mactag 
     | 
|
| 
       41 
41 
     | 
    
         
             
                #   do
         
     | 
| 
       42 
42 
     | 
    
         
             
                #
         
     | 
| 
       43 
43 
     | 
    
         
             
                class Rails
         
     | 
| 
       44 
     | 
    
         
            -
                  PACKAGES = [:actionmailer, :actionpack, :activemodel, :activerecord, :activeresource, :railties, :activesupport]
         
     | 
| 
       45 
44 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
                   
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
      
 45 
     | 
    
         
            +
                  PACKAGES = %w(actionmailer actionpack activemodel activerecord activeresource activesupport railties)
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                  attr_accessor :only, :except, :version
         
     | 
| 
       48 
48 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                    @ 
     | 
| 
      
 49 
     | 
    
         
            +
                  def initialize(options)
         
     | 
| 
      
 50 
     | 
    
         
            +
                    @only = packagize(options[:only])
         
     | 
| 
      
 51 
     | 
    
         
            +
                    @except = packagize(options[:except])
         
     | 
| 
      
 52 
     | 
    
         
            +
                    @version = options[:version]
         
     | 
| 
       51 
53 
     | 
    
         
             
                  end
         
     | 
| 
       52 
54 
     | 
    
         | 
| 
       53 
55 
     | 
    
         
             
                  def tag
         
     | 
| 
       54 
     | 
    
         
            -
                     
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
                       
     | 
| 
       57 
     | 
    
         
            -
                        result << Gem.new(package.to_s, version).tag
         
     | 
| 
       58 
     | 
    
         
            -
                      end
         
     | 
| 
      
 56 
     | 
    
         
            +
                    packages.inject([]) do |array, package|
         
     | 
| 
      
 57 
     | 
    
         
            +
                      array << Gem.new(package, version).tag
         
     | 
| 
      
 58 
     | 
    
         
            +
                      array
         
     | 
| 
       59 
59 
     | 
    
         
             
                    end
         
     | 
| 
       60 
     | 
    
         
            -
                    result
         
     | 
| 
       61 
60 
     | 
    
         
             
                  end
         
     | 
| 
       62 
61 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
                  private
         
     | 
| 
       65 
     | 
    
         
            -
                  
         
     | 
| 
       66 
62 
     | 
    
         
             
                  def packages
         
     | 
| 
       67 
     | 
    
         
            -
                     
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
                      result = PACKAGES
         
     | 
| 
      
 63 
     | 
    
         
            +
                    if only || except
         
     | 
| 
      
 64 
     | 
    
         
            +
                      only || PACKAGES - except
         
     | 
| 
       70 
65 
     | 
    
         
             
                    else
         
     | 
| 
       71 
     | 
    
         
            -
                       
     | 
| 
       72 
     | 
    
         
            -
                        result = @only
         
     | 
| 
       73 
     | 
    
         
            -
                      elsif @except
         
     | 
| 
       74 
     | 
    
         
            -
                        result = PACKAGES - @except
         
     | 
| 
       75 
     | 
    
         
            -
                      end
         
     | 
| 
      
 66 
     | 
    
         
            +
                      PACKAGES
         
     | 
| 
       76 
67 
     | 
    
         
             
                    end
         
     | 
| 
       77 
     | 
    
         
            -
                    result
         
     | 
| 
       78 
68 
     | 
    
         
             
                  end
         
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                  private
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                  def packagize(pkgs)
         
     | 
| 
       81 
74 
     | 
    
         
             
                    return nil if pkgs.blank?
         
     | 
| 
       82 
75 
     | 
    
         | 
| 
       83 
     | 
    
         
            -
                    Array(pkgs). 
     | 
| 
       84 
     | 
    
         
            -
                      "#{pkg}".gsub(/[^a-z]/, '') 
     | 
| 
      
 76 
     | 
    
         
            +
                    Array(pkgs).map do |pkg|
         
     | 
| 
      
 77 
     | 
    
         
            +
                      "#{pkg}".gsub(/[^a-z]/, '')
         
     | 
| 
       85 
78 
     | 
    
         
             
                    end
         
     | 
| 
       86 
79 
     | 
    
         
             
                  end
         
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
       88 
81 
     | 
    
         
             
                  def version
         
     | 
| 
       89 
     | 
    
         
            -
                    @ 
     | 
| 
      
 82 
     | 
    
         
            +
                    @version || ::Rails.version
         
     | 
| 
       90 
83 
     | 
    
         
             
                  end
         
     | 
| 
       91 
84 
     | 
    
         
             
                end
         
     | 
| 
       92 
85 
     | 
    
         
             
              end
         
     | 
    
        data/lib/tasks/mactag.rake
    CHANGED
    
    | 
         @@ -1,21 +1,8 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            task :environment
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            desc 'Creates a Ctags file'
         
     | 
| 
      
 4 
     | 
    
         
            +
            task :mactag => :environment do
         
     | 
| 
       4 
5 
     | 
    
         
             
              require File.join(Rails.root, 'config', 'mactag')
         
     | 
| 
       5 
     | 
    
         
            -
            end
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
            namespace :mactag do
         
     | 
| 
       8 
     | 
    
         
            -
              desc 'Creates Ctags file'
         
     | 
| 
       9 
     | 
    
         
            -
              task :create => :environment do
         
     | 
| 
       10 
     | 
    
         
            -
                load_configuration
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                Mactag::Builder.create
         
     | 
| 
       13 
     | 
    
         
            -
              end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
              desc 'Starts the Mactag server'
         
     | 
| 
       16 
     | 
    
         
            -
              task :server => :environment do
         
     | 
| 
       17 
     | 
    
         
            -
                load_configuration
         
     | 
| 
       18 
6 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
              end
         
     | 
| 
      
 7 
     | 
    
         
            +
              Mactag::Builder.create
         
     | 
| 
       21 
8 
     | 
    
         
             
            end
         
     | 
    
        data/spec/mactag/builder_spec.rb
    CHANGED
    
    | 
         @@ -10,124 +10,143 @@ describe Mactag::Builder do 
     | 
|
| 
       10 
10 
     | 
    
         
             
                  @tag = Mactag::Tag::App.new('app')
         
     | 
| 
       11 
11 
     | 
    
         
             
                end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
                it ' 
     | 
| 
      
 13 
     | 
    
         
            +
                it 'adds single tag' do
         
     | 
| 
       14 
14 
     | 
    
         
             
                  @builder << @tag
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                  @builder.instance_variable_get('@tags').should  
     | 
| 
      
 16 
     | 
    
         
            +
                  @builder.instance_variable_get('@tags').should eq([@tag])
         
     | 
| 
       17 
17 
     | 
    
         
             
                end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
                it ' 
     | 
| 
      
 19 
     | 
    
         
            +
                it 'adds multiple tags' do
         
     | 
| 
       20 
20 
     | 
    
         
             
                  @builder << [@tag, @tag]
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
                  @builder.instance_variable_get('@tags').should  
     | 
| 
      
 22 
     | 
    
         
            +
                  @builder.instance_variable_get('@tags').should eq([@tag, @tag])
         
     | 
| 
       23 
23 
     | 
    
         
             
                end
         
     | 
| 
       24 
24 
     | 
    
         
             
              end
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
26 
     | 
    
         
             
              describe '#files' do
         
     | 
| 
       27 
27 
     | 
    
         
             
                before do
         
     | 
| 
       28 
     | 
    
         
            -
                  Dir.stub 
     | 
| 
       29 
     | 
    
         
            -
                  File.stub 
     | 
| 
       30 
     | 
    
         
            -
                  File.stub 
     | 
| 
      
 28 
     | 
    
         
            +
                  Dir.stub(:glob) { |file| [file] }
         
     | 
| 
      
 29 
     | 
    
         
            +
                  File.stub(:expand_path) { |file| file }
         
     | 
| 
      
 30 
     | 
    
         
            +
                  File.stub(:directory?) { false }
         
     | 
| 
       31 
31 
     | 
    
         
             
                end
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
                it ' 
     | 
| 
       34 
     | 
    
         
            -
                  @builder.stub 
     | 
| 
       35 
     | 
    
         
            -
                  @builder.files.should  
     | 
| 
      
 33 
     | 
    
         
            +
                it 'flattens all files' do
         
     | 
| 
      
 34 
     | 
    
         
            +
                  @builder.stub(:all) { [['app'], 'lib'] }
         
     | 
| 
      
 35 
     | 
    
         
            +
                  @builder.files.should eq(['app', 'lib'])
         
     | 
| 
       36 
36 
     | 
    
         
             
                end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
                it ' 
     | 
| 
       39 
     | 
    
         
            -
                  @builder.stub 
     | 
| 
       40 
     | 
    
         
            -
                  @builder.files.should  
     | 
| 
      
 38 
     | 
    
         
            +
                it 'compacts all files' do
         
     | 
| 
      
 39 
     | 
    
         
            +
                  @builder.stub(:all) { [nil, 'app', nil, 'lib', nil] }
         
     | 
| 
      
 40 
     | 
    
         
            +
                  @builder.files.should eq(['app', 'lib'])
         
     | 
| 
       41 
41 
     | 
    
         
             
                end
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
                it ' 
     | 
| 
       44 
     | 
    
         
            -
                  @builder.stub 
     | 
| 
      
 43 
     | 
    
         
            +
                it 'expands all files' do
         
     | 
| 
      
 44 
     | 
    
         
            +
                  @builder.stub(:all) { ['app', 'lib'] }
         
     | 
| 
       45 
45 
     | 
    
         
             
                  File.should_receive(:expand_path).with('app')
         
     | 
| 
       46 
46 
     | 
    
         
             
                  File.should_receive(:expand_path).with('lib')
         
     | 
| 
       47 
47 
     | 
    
         
             
                  @builder.files
         
     | 
| 
       48 
48 
     | 
    
         
             
                end
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
                it ' 
     | 
| 
       51 
     | 
    
         
            -
                  @builder.stub 
     | 
| 
      
 50 
     | 
    
         
            +
                it 'globs all files' do
         
     | 
| 
      
 51 
     | 
    
         
            +
                  @builder.stub(:all) { ['app', 'lib'] }
         
     | 
| 
       52 
52 
     | 
    
         
             
                  Dir.should_receive(:glob).with('app')
         
     | 
| 
       53 
53 
     | 
    
         
             
                  Dir.should_receive(:glob).with('lib')
         
     | 
| 
       54 
54 
     | 
    
         
             
                  @builder.files
         
     | 
| 
       55 
55 
     | 
    
         
             
                end
         
     | 
| 
       56 
56 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
                it ' 
     | 
| 
       58 
     | 
    
         
            -
                  @builder.stub 
     | 
| 
       59 
     | 
    
         
            -
                  @builder.files.should  
     | 
| 
      
 57 
     | 
    
         
            +
                it 'uniquifies files' do
         
     | 
| 
      
 58 
     | 
    
         
            +
                  @builder.stub(:all) { ['app', 'lib', 'lib', 'app'] }
         
     | 
| 
      
 59 
     | 
    
         
            +
                  @builder.files.should eq(['app', 'lib'])
         
     | 
| 
       60 
60 
     | 
    
         
             
                end
         
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
                it ' 
     | 
| 
       63 
     | 
    
         
            -
                  @builder.stub 
     | 
| 
       64 
     | 
    
         
            -
                  Dir.stub 
     | 
| 
       65 
     | 
    
         
            -
                  File.stub 
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                it 'does not return directories' do
         
     | 
| 
      
 63 
     | 
    
         
            +
                  @builder.stub(:all) { ['app'] }
         
     | 
| 
      
 64 
     | 
    
         
            +
                  Dir.stub(:glob) { ['app'] }
         
     | 
| 
      
 65 
     | 
    
         
            +
                  File.stub(:directory?) { true }
         
     | 
| 
       66 
66 
     | 
    
         
             
                  @builder.files.should be_empty
         
     | 
| 
       67 
67 
     | 
    
         
             
                end
         
     | 
| 
       68 
68 
     | 
    
         
             
              end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
       70 
70 
     | 
    
         
             
              describe '#directories' do
         
     | 
| 
       71 
     | 
    
         
            -
                it ' 
     | 
| 
       72 
     | 
    
         
            -
                  @builder.stub 
     | 
| 
       73 
     | 
    
         
            -
                  @builder.directories.should  
     | 
| 
      
 71 
     | 
    
         
            +
                it 'returns all file dirnames' do
         
     | 
| 
      
 72 
     | 
    
         
            +
                  @builder.stub(:files) { ['app/models/user.rb', 'lib/validate.rb'] }
         
     | 
| 
      
 73 
     | 
    
         
            +
                  @builder.directories.should eq(['app/models', 'lib'])
         
     | 
| 
       74 
74 
     | 
    
         
             
                end
         
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
                it ' 
     | 
| 
       77 
     | 
    
         
            -
                  @builder.stub 
     | 
| 
       78 
     | 
    
         
            -
                  @builder.directories.should  
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                it 'returns uniq directories' do
         
     | 
| 
      
 77 
     | 
    
         
            +
                  @builder.stub(:files) { ['app/models/user.rb', 'app/models/post.rb'] }
         
     | 
| 
      
 78 
     | 
    
         
            +
                  @builder.directories.should eq(['app/models'])
         
     | 
| 
       79 
79 
     | 
    
         
             
                end
         
     | 
| 
       80 
80 
     | 
    
         
             
              end
         
     | 
| 
       81 
81 
     | 
    
         | 
| 
       82 
82 
     | 
    
         
             
              describe '#all' do
         
     | 
| 
       83 
     | 
    
         
            -
                it ' 
     | 
| 
      
 83 
     | 
    
         
            +
                it 'returns all files' do
         
     | 
| 
       84 
84 
     | 
    
         
             
                  @builder << Mactag::Tag::App.new('app')
         
     | 
| 
       85 
85 
     | 
    
         
             
                  @builder << Mactag::Tag::App.new('lib')
         
     | 
| 
       86 
86 
     | 
    
         | 
| 
       87 
     | 
    
         
            -
                  @builder.all.should  
     | 
| 
      
 87 
     | 
    
         
            +
                  @builder.all.should eq(['app', 'lib'])
         
     | 
| 
       88 
88 
     | 
    
         
             
                end
         
     | 
| 
       89 
89 
     | 
    
         | 
| 
       90 
     | 
    
         
            -
                it ' 
     | 
| 
      
 90 
     | 
    
         
            +
                it 'returns empty array when no tags' do
         
     | 
| 
       91 
91 
     | 
    
         
             
                  @builder.all.should be_empty
         
     | 
| 
       92 
92 
     | 
    
         
             
                end
         
     | 
| 
       93 
93 
     | 
    
         
             
              end
         
     | 
| 
       94 
94 
     | 
    
         | 
| 
       95 
95 
     | 
    
         
             
              describe '#gems?' do
         
     | 
| 
       96 
     | 
    
         
            -
                it ' 
     | 
| 
       97 
     | 
    
         
            -
                  @builder.stub 
     | 
| 
      
 96 
     | 
    
         
            +
                it 'is true when tags exists' do
         
     | 
| 
      
 97 
     | 
    
         
            +
                  @builder.stub(:all) { ['app'] }
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                  @builder.should have_gems
         
     | 
| 
      
 100 
     | 
    
         
            +
                end
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
                it 'is false when no tags exists' do
         
     | 
| 
      
 103 
     | 
    
         
            +
                  @builder.stub(:all) { [] }
         
     | 
| 
       98 
104 
     | 
    
         | 
| 
       99 
     | 
    
         
            -
                  @builder. 
     | 
| 
      
 105 
     | 
    
         
            +
                  @builder.should_not have_gems
         
     | 
| 
       100 
106 
     | 
    
         
             
                end
         
     | 
| 
      
 107 
     | 
    
         
            +
              end
         
     | 
| 
       101 
108 
     | 
    
         | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
      
 109 
     | 
    
         
            +
              describe '#create' do
         
     | 
| 
      
 110 
     | 
    
         
            +
                it 'raises error when gem home does not exist' do
         
     | 
| 
      
 111 
     | 
    
         
            +
                  Mactag::Builder.stub(:gem_home_exists?) { false }
         
     | 
| 
      
 112 
     | 
    
         
            +
                  proc {
         
     | 
| 
      
 113 
     | 
    
         
            +
                    Mactag::Builder.create
         
     | 
| 
      
 114 
     | 
    
         
            +
                  }.should raise_exception(Mactag::MactagError)
         
     | 
| 
      
 115 
     | 
    
         
            +
                end
         
     | 
| 
       104 
116 
     | 
    
         | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
      
 117 
     | 
    
         
            +
                it 'raises errors when gem home exists but there are no gems' do
         
     | 
| 
      
 118 
     | 
    
         
            +
                  Mactag::Builder.stub(:gem_home_exists?) { true }
         
     | 
| 
      
 119 
     | 
    
         
            +
                  Mactag::Builder.stub(:builder) { mock(:has_gems? => false) }
         
     | 
| 
      
 120 
     | 
    
         
            +
                  proc {
         
     | 
| 
      
 121 
     | 
    
         
            +
                    Mactag::Builder.create
         
     | 
| 
      
 122 
     | 
    
         
            +
                  }.should raise_exception(Mactag::MactagError)
         
     | 
| 
       106 
123 
     | 
    
         
             
                end
         
     | 
| 
       107 
124 
     | 
    
         
             
              end
         
     | 
| 
       108 
125 
     | 
    
         | 
| 
       109 
126 
     | 
    
         
             
              describe '#generate' do
         
     | 
| 
       110 
     | 
    
         
            -
                it ' 
     | 
| 
       111 
     | 
    
         
            -
                   
     | 
| 
      
 127 
     | 
    
         
            +
                it 'accepts a block as argument' do
         
     | 
| 
      
 128 
     | 
    
         
            +
                  proc {
         
     | 
| 
      
 129 
     | 
    
         
            +
                    Mactag::Builder.generate {}
         
     | 
| 
      
 130 
     | 
    
         
            +
                  }.should_not raise_exception
         
     | 
| 
       112 
131 
     | 
    
         
             
                end
         
     | 
| 
       113 
132 
     | 
    
         
             
              end
         
     | 
| 
       114 
133 
     | 
    
         | 
| 
       115 
134 
     | 
    
         
             
              describe '#gem_home_exists?' do
         
     | 
| 
       116 
     | 
    
         
            -
                it ' 
     | 
| 
       117 
     | 
    
         
            -
                  File.stub 
     | 
| 
      
 135 
     | 
    
         
            +
                it 'exists when directory exists' do
         
     | 
| 
      
 136 
     | 
    
         
            +
                  File.stub(:directory?) { true }
         
     | 
| 
       118 
137 
     | 
    
         | 
| 
       119 
138 
     | 
    
         
             
                  Mactag::Builder.gem_home_exists?.should be_true
         
     | 
| 
       120 
139 
     | 
    
         
             
                end
         
     | 
| 
       121 
140 
     | 
    
         | 
| 
       122 
     | 
    
         
            -
                it ' 
     | 
| 
      
 141 
     | 
    
         
            +
                it 'does not exist when directory does not exist' do
         
     | 
| 
       123 
142 
     | 
    
         
             
                  File.stub!(:directory?).and_return(false)
         
     | 
| 
       124 
143 
     | 
    
         | 
| 
       125 
144 
     | 
    
         
             
                  Mactag::Builder.gem_home_exists?.should be_false
         
     | 
| 
       126 
145 
     | 
    
         
             
                end
         
     | 
| 
       127 
146 
     | 
    
         
             
              end
         
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
       129 
148 
     | 
    
         
             
              describe '#builder' do
         
     | 
| 
       130 
     | 
    
         
            -
                it ' 
     | 
| 
      
 149 
     | 
    
         
            +
                it 'returns builder instance' do
         
     | 
| 
       131 
150 
     | 
    
         
             
                  Mactag::Builder.generate {}
         
     | 
| 
       132 
151 
     | 
    
         
             
                  Mactag::Builder.builder.should == Mactag::Builder.instance_variable_get('@builder')
         
     | 
| 
       133 
152 
     | 
    
         
             
                end
         
     |