sugar-high 0.5.5 → 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/README.textile +2 -29
 - data/VERSION +1 -1
 - data/lib/sugar-high/class_ext.rb +2 -133
 - data/lib/sugar-high/file.rb +10 -11
 - data/lib/sugar-high/file_ext.rb +13 -11
 - data/lib/sugar-high/rails/concerns.rb +10 -4
 - data/spec/sugar-high/file_spec.rb +26 -28
 - data/spec/sugar-high/rails/concerns_spec.rb +31 -1
 - data/spec/sugar-high/rails/fixture_user/scopes.rb +4 -0
 - data/spec/sugar-high/rails/fixture_user/validations.rb +4 -0
 - data/spec/sugar-high/rails/shared/associations.rb +1 -0
 - data/spec/sugar-high/rails/shared/caching.rb +4 -0
 - data/sugar-high.gemspec +6 -42
 - metadata +19 -55
 - data/lib/sugar-high/file_mutate.rb +0 -2
 - data/lib/sugar-high/file_mutate/append_content.rb +0 -17
 - data/lib/sugar-high/file_mutate/delete.rb +0 -29
 - data/lib/sugar-high/file_mutate/insert_content.rb +0 -62
 - data/lib/sugar-high/file_mutate/mutate.rb +0 -57
 - data/lib/sugar-high/file_mutate/overwrite_content.rb +0 -17
 - data/lib/sugar-high/file_mutate/remove_content.rb +0 -33
 - data/lib/sugar-high/file_mutate/replace_content.rb +0 -45
 - data/lib/sugar-high/file_mutation.rb +0 -58
 - data/sandbox/test_routes_mutate.rb +0 -8
 - data/spec/auto_load_blank_root.rb +0 -3
 - data/spec/autoload_blank_root.rb +0 -3
 - data/spec/autoload_blank_root/hello.rb +0 -6
 - data/spec/autoload_blank_root/sailor.rb +0 -7
 - data/spec/fixtures/application_file.rb +0 -6
 - data/spec/fixtures/autoload_modules.rb +0 -3
 - data/spec/fixtures/autoload_modules/subdir/first.rb +0 -7
 - data/spec/fixtures/autoload_modules/subdir/second.rb +0 -5
 - data/spec/fixtures/autoload_modules/subdir/third.rb +0 -4
 - data/spec/fixtures/autoload_modules_root.rb +0 -3
 - data/spec/fixtures/autoload_modules_root/first.rb +0 -7
 - data/spec/fixtures/autoload_modules_root/second.rb +0 -4
 - data/spec/fixtures/autoload_modules_root/third.rb +0 -7
 - data/spec/fixtures/autoload_modulez.rb +0 -4
 - data/spec/fixtures/autoload_modulez/first.rb +0 -7
 - data/spec/fixtures/autoload_modulez/second.rb +0 -5
 - data/spec/fixtures/autoload_modulez/third_one_here.rb +0 -4
 - data/spec/fixtures/class_file.rb +0 -22
 - data/spec/fixtures/class_file.txt +0 -0
 - data/spec/fixtures/content_file.txt +0 -1
 - data/spec/fixtures/routes_file.rb +0 -85
 - data/spec/sugar-high/class_ext_spec.rb +0 -189
 - data/spec/sugar-high/file/file_dsl_spec.rb +0 -4
 - data/spec/sugar-high/file_mutate/append_content_spec.rb +0 -61
 - data/spec/sugar-high/file_mutate/delete_spec.rb +0 -47
 - data/spec/sugar-high/file_mutate/insert_before_last_spec.rb +0 -56
 - data/spec/sugar-high/file_mutate/insert_content_spec.rb +0 -111
 - data/spec/sugar-high/file_mutate/overwrite_content_spec.rb +0 -80
 - data/spec/sugar-high/file_mutate/remove_content_spec.rb +0 -109
 - data/spec/sugar-high/file_mutate/replace_content_spec.rb +0 -33
 
| 
         @@ -1,17 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module SugarHigh
         
     | 
| 
       2 
     | 
    
         
            -
              module FileMutate
         
     | 
| 
       3 
     | 
    
         
            -
                module OverwriteContent      
         
     | 
| 
       4 
     | 
    
         
            -
                  def overwrite content=nil, &block           
         
     | 
| 
       5 
     | 
    
         
            -
                    File.overwrite self.path, content, &block
         
     | 
| 
       6 
     | 
    
         
            -
                  end
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
                  module ClassMethods
         
     | 
| 
       9 
     | 
    
         
            -
                    def overwrite file, content=nil, &block
         
     | 
| 
       10 
     | 
    
         
            -
                      File.open(get_filepath(file).path, 'w') do |f|
         
     | 
| 
       11 
     | 
    
         
            -
                        f.puts content ||= yield
         
     | 
| 
       12 
     | 
    
         
            -
                      end
         
     | 
| 
       13 
     | 
    
         
            -
                    end
         
     | 
| 
       14 
     | 
    
         
            -
                  end
         
     | 
| 
       15 
     | 
    
         
            -
                end
         
     | 
| 
       16 
     | 
    
         
            -
              end
         
     | 
| 
       17 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,33 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module SugarHigh
         
     | 
| 
       2 
     | 
    
         
            -
              module FileMutate
         
     | 
| 
       3 
     | 
    
         
            -
                module RemoveContent
         
     | 
| 
       4 
     | 
    
         
            -
                  def remove_content options=nil, &block
         
     | 
| 
       5 
     | 
    
         
            -
                    opt_str = case options
         
     | 
| 
       6 
     | 
    
         
            -
                    when String
         
     | 
| 
       7 
     | 
    
         
            -
                      options
         
     | 
| 
       8 
     | 
    
         
            -
                    when Hash
         
     | 
| 
       9 
     | 
    
         
            -
                      content = options[:content] || options[:where]
         
     | 
| 
       10 
     | 
    
         
            -
                      raise ArgumentError, "Bad :content value in Hash" if !content || content.strip.empty?
         
     | 
| 
       11 
     | 
    
         
            -
                      content.strip
         
     | 
| 
       12 
     | 
    
         
            -
                    else
         
     | 
| 
       13 
     | 
    
         
            -
                      raise ArgumentError, "non-block argument must be either String or Hash with a :content option" if !block
         
     | 
| 
       14 
     | 
    
         
            -
                    end    
         
     | 
| 
       15 
     | 
    
         
            -
                    content = block ? yield : opt_str
         
     | 
| 
       16 
     | 
    
         
            -
                
         
     | 
| 
       17 
     | 
    
         
            -
                    File.remove_content_from self.path, :content => content, :with => '', &block
         
     | 
| 
       18 
     | 
    
         
            -
                  end
         
     | 
| 
       19 
     | 
    
         
            -
                  alias_method :remove, :remove_content
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                  module ClassMethods
         
     | 
| 
       22 
     | 
    
         
            -
                    def remove_from file_name, content=nil, &block
         
     | 
| 
       23 
     | 
    
         
            -
                      content ||= yield
         
     | 
| 
       24 
     | 
    
         
            -
                      replace_content_from file_name, :content => content, :with => '', &block
         
     | 
| 
       25 
     | 
    
         
            -
                    end
         
     | 
| 
       26 
     | 
    
         
            -
               
         
     | 
| 
       27 
     | 
    
         
            -
                    def remove_content_from file_name, options = {}, &block
         
     | 
| 
       28 
     | 
    
         
            -
                      replace_content_from file_name, options.merge(:with => ''), &block
         
     | 
| 
       29 
     | 
    
         
            -
                    end
         
     | 
| 
       30 
     | 
    
         
            -
                  end
         
     | 
| 
       31 
     | 
    
         
            -
                end
         
     | 
| 
       32 
     | 
    
         
            -
              end
         
     | 
| 
       33 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,45 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module SugarHigh
         
     | 
| 
       2 
     | 
    
         
            -
              module FileMutate
         
     | 
| 
       3 
     | 
    
         
            -
                module ReplaceContent
         
     | 
| 
       4 
     | 
    
         
            -
                  def replace_content options = {}, &block
         
     | 
| 
       5 
     | 
    
         
            -
                    File.replace_content_from self.path, options, &block
         
     | 
| 
       6 
     | 
    
         
            -
                  end
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
                  module ClassMethods
         
     | 
| 
       9 
     | 
    
         
            -
                    # replaces content found at replacement_expr with content resulting from yielding block
         
     | 
| 
       10 
     | 
    
         
            -
                    # File.replace_content_from 'myfile.txt', where => /HelloWorld/, with => 'GoodBye'
         
     | 
| 
       11 
     | 
    
         
            -
                    def replace_content_from file_name, options = {}, &block
         
     | 
| 
       12 
     | 
    
         
            -
                      replacement_expr = options[:where] || options[:content]
         
     | 
| 
       13 
     | 
    
         
            -
                      new_content = options[:with]
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                      begin
         
     | 
| 
       16 
     | 
    
         
            -
                        replacement_expr = replacement_expr.to_regexp
         
     | 
| 
       17 
     | 
    
         
            -
                      rescue
         
     | 
| 
       18 
     | 
    
         
            -
                        raise ArgumentError, "Content to be replaced must be specified as either a String or Regexp in a :where or :content option"
         
     | 
| 
       19 
     | 
    
         
            -
                      end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                      file = get_file file_name
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                      # get existing file content
         
     | 
| 
       24 
     | 
    
         
            -
                      content = file.read
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                      # return nil if no mathing replacement found
         
     | 
| 
       27 
     | 
    
         
            -
                      return nil if !(content =~ replacement_expr)
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                      new_content ||= yield if block
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                      raise ArgumentError, "Content to be replaced with must be specified as a :with option or as a block" if !new_content
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                      # remove content that matches expr, by replacing with empty
         
     | 
| 
       34 
     | 
    
         
            -
                      mutated_content = content.gsub replacement_expr, new_content
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                      # write mutated content as new file
         
     | 
| 
       37 
     | 
    
         
            -
                      file.overwrite mutated_content
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                      true # signal success!
         
     | 
| 
       40 
     | 
    
         
            -
                    end
         
     | 
| 
       41 
     | 
    
         
            -
                    alias_method :replace_content_in, :replace_content_from
         
     | 
| 
       42 
     | 
    
         
            -
                  end
         
     | 
| 
       43 
     | 
    
         
            -
                end
         
     | 
| 
       44 
     | 
    
         
            -
              end
         
     | 
| 
       45 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,58 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'sugar-high/blank'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'sugar-high/arguments'
         
     | 
| 
       3 
     | 
    
         
            -
            require 'sugar-high/path'
         
     | 
| 
       4 
     | 
    
         
            -
            require 'sugar-high/regexp'
         
     | 
| 
       5 
     | 
    
         
            -
            require 'sugar-high/string'
         
     | 
| 
       6 
     | 
    
         
            -
            require 'sugar-high/file'
         
     | 
| 
       7 
     | 
    
         
            -
            require 'sugar-high/array'
         
     | 
| 
       8 
     | 
    
         
            -
                                     
         
     | 
| 
       9 
     | 
    
         
            -
            require 'sugar-high/file_mutate/delete'
         
     | 
| 
       10 
     | 
    
         
            -
            require 'sugar-high/file_mutate/overwrite_content'
         
     | 
| 
       11 
     | 
    
         
            -
            require 'sugar-high/file_mutate/append_content'
         
     | 
| 
       12 
     | 
    
         
            -
            require 'sugar-high/file_mutate/remove_content'
         
     | 
| 
       13 
     | 
    
         
            -
            require 'sugar-high/file_mutate/replace_content'
         
     | 
| 
       14 
     | 
    
         
            -
            require 'sugar-high/file_mutate/insert_content'
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
            require 'sugar-high/class_ext'
         
     | 
| 
       17 
     | 
    
         
            -
            require 'active_support/inflector'
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
            module SugarHigh
         
     | 
| 
       20 
     | 
    
         
            -
              module FileMutate
         
     | 
| 
       21 
     | 
    
         
            -
                autoload :Mutate,             'sugar-high/file_mutate/mutate'    
         
     | 
| 
       22 
     | 
    
         
            -
                autoload :Delete,             'sugar-high/file_mutate/delete'    
         
     | 
| 
       23 
     | 
    
         
            -
                autoload :AppendContent,      'sugar-high/file_mutate/append_content'
         
     | 
| 
       24 
     | 
    
         
            -
                autoload :InsertContent,      'sugar-high/file_mutate/insert_content'    
         
     | 
| 
       25 
     | 
    
         
            -
                autoload :OverwriteContent,   'sugar-high/file_mutate/overwrite_content'
         
     | 
| 
       26 
     | 
    
         
            -
                autoload :RemoveContent,      'sugar-high/file_mutate/remove_content'
         
     | 
| 
       27 
     | 
    
         
            -
                autoload :ReplaceContent,     'sugar-high/file_mutate/replace_content'    
         
     | 
| 
       28 
     | 
    
         
            -
              end
         
     | 
| 
       29 
     | 
    
         
            -
            end
         
     | 
| 
       30 
     | 
    
         
            -
                        
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
            class File  
         
     | 
| 
       33 
     | 
    
         
            -
              def self.mutate_ext name
         
     | 
| 
       34 
     | 
    
         
            -
                if name == :all
         
     | 
| 
       35 
     | 
    
         
            -
                  add_mutate_exts mutate_apis
         
     | 
| 
       36 
     | 
    
         
            -
                  return
         
     | 
| 
       37 
     | 
    
         
            -
                end
         
     | 
| 
       38 
     | 
    
         
            -
                raise ArgumentError, "Unknown FileMutate API: #{name}, must be one of: #{mutate_apis}" if !mutate_apis.include? name
         
     | 
| 
       39 
     | 
    
         
            -
                add_mutate_exts [:mutate, name]
         
     | 
| 
       40 
     | 
    
         
            -
              end
         
     | 
| 
       41 
     | 
    
         
            -
              
         
     | 
| 
       42 
     | 
    
         
            -
              protected
         
     | 
| 
       43 
     | 
    
         
            -
              
         
     | 
| 
       44 
     | 
    
         
            -
              def self.mutate_apis  
         
     | 
| 
       45 
     | 
    
         
            -
                [:delete, :mutate, :append_content, :insert_content, :overwrite_content, :remove_content, :replace_content]
         
     | 
| 
       46 
     | 
    
         
            -
              end  
         
     | 
| 
       47 
     | 
    
         
            -
              
         
     | 
| 
       48 
     | 
    
         
            -
              def self.add_mutate_exts *names
         
     | 
| 
       49 
     | 
    
         
            -
                names.flat_uniq.each do |api| 
         
     | 
| 
       50 
     | 
    
         
            -
                  ns = "SugarHigh::FileMutate::#{api.to_s.camelize}"
         
     | 
| 
       51 
     | 
    
         
            -
                  begin
         
     | 
| 
       52 
     | 
    
         
            -
                    self.send :include, ns.constantize
         
     | 
| 
       53 
     | 
    
         
            -
                    self.extend "#{ns}::ClassMethods".constantize
         
     | 
| 
       54 
     | 
    
         
            -
                  end
         
     | 
| 
       55 
     | 
    
         
            -
                end
         
     | 
| 
       56 
     | 
    
         
            -
              end
         
     | 
| 
       57 
     | 
    
         
            -
              
         
     | 
| 
       58 
     | 
    
         
            -
            end
         
     | 
    
        data/spec/autoload_blank_root.rb
    DELETED
    
    
    
        data/spec/fixtures/class_file.rb
    DELETED
    
    
| 
         
            File without changes
         
     | 
| 
         @@ -1 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            {:with=>"New content"}
         
     | 
| 
         @@ -1,85 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            Fixtures::Application.routes.draw do
         
     | 
| 
       2 
     | 
    
         
            -
              
         
     | 
| 
       3 
     | 
    
         
            -
              
         
     | 
| 
       4 
     | 
    
         
            -
              
         
     | 
| 
       5 
     | 
    
         
            -
              
         
     | 
| 
       6 
     | 
    
         
            -
              
         
     | 
| 
       7 
     | 
    
         
            -
              
         
     | 
| 
       8 
     | 
    
         
            -
              
         
     | 
| 
       9 
     | 
    
         
            -
              
         
     | 
| 
       10 
     | 
    
         
            -
              
         
     | 
| 
       11 
     | 
    
         
            -
              
         
     | 
| 
       12 
     | 
    
         
            -
              
         
     | 
| 
       13 
     | 
    
         
            -
              
         
     | 
| 
       14 
     | 
    
         
            -
              
         
     | 
| 
       15 
     | 
    
         
            -
              
         
     | 
| 
       16 
     | 
    
         
            -
              
         
     | 
| 
       17 
     | 
    
         
            -
              
         
     | 
| 
       18 
     | 
    
         
            -
              
         
     | 
| 
       19 
     | 
    
         
            -
              
         
     | 
| 
       20 
     | 
    
         
            -
              
         
     | 
| 
       21 
     | 
    
         
            -
              
         
     | 
| 
       22 
     | 
    
         
            -
              
         
     | 
| 
       23 
     | 
    
         
            -
              
         
     | 
| 
       24 
     | 
    
         
            -
              
         
     | 
| 
       25 
     | 
    
         
            -
              
         
     | 
| 
       26 
     | 
    
         
            -
              
         
     | 
| 
       27 
     | 
    
         
            -
              resources :users
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
              # The priority is based upon order of creation:
         
     | 
| 
       30 
     | 
    
         
            -
              # first created -> highest priority.
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
              # Sample of regular route:
         
     | 
| 
       33 
     | 
    
         
            -
              #   match 'products/:id' => 'catalog#view'
         
     | 
| 
       34 
     | 
    
         
            -
              # Keep in mind you can assign values other than :controller and :action
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
              # Sample of named route:
         
     | 
| 
       37 
     | 
    
         
            -
              #   match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
         
     | 
| 
       38 
     | 
    
         
            -
              # This route can be invoked with purchase_url(:id => product.id)
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
              # Sample resource route (maps HTTP verbs to controller actions automatically):
         
     | 
| 
       41 
     | 
    
         
            -
              #   resources :products
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
              # Sample resource route with options:
         
     | 
| 
       44 
     | 
    
         
            -
              #   resources :products do
         
     | 
| 
       45 
     | 
    
         
            -
              #     member do
         
     | 
| 
       46 
     | 
    
         
            -
              #       get 'short'
         
     | 
| 
       47 
     | 
    
         
            -
              #       post 'toggle'
         
     | 
| 
       48 
     | 
    
         
            -
              #     end
         
     | 
| 
       49 
     | 
    
         
            -
              #
         
     | 
| 
       50 
     | 
    
         
            -
              #     collection do
         
     | 
| 
       51 
     | 
    
         
            -
              #       get 'sold'
         
     | 
| 
       52 
     | 
    
         
            -
              #     end
         
     | 
| 
       53 
     | 
    
         
            -
              #   end
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
              # Sample resource route with sub-resources:
         
     | 
| 
       56 
     | 
    
         
            -
              #   resources :products do
         
     | 
| 
       57 
     | 
    
         
            -
              #     resources :comments, :sales
         
     | 
| 
       58 
     | 
    
         
            -
              #     resource :seller
         
     | 
| 
       59 
     | 
    
         
            -
              #   end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
              # Sample resource route with more complex sub-resources
         
     | 
| 
       62 
     | 
    
         
            -
              #   resources :products do
         
     | 
| 
       63 
     | 
    
         
            -
              #     resources :comments
         
     | 
| 
       64 
     | 
    
         
            -
              #     resources :sales do
         
     | 
| 
       65 
     | 
    
         
            -
              #       get 'recent', :on => :collection
         
     | 
| 
       66 
     | 
    
         
            -
              #     end
         
     | 
| 
       67 
     | 
    
         
            -
              #   end
         
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
              # Sample resource route within a namespace:
         
     | 
| 
       70 
     | 
    
         
            -
              #   namespace :admin do
         
     | 
| 
       71 
     | 
    
         
            -
              #     # Directs /admin/products/* to Admin::ProductsController
         
     | 
| 
       72 
     | 
    
         
            -
              #     # (app/controllers/admin/products_controller.rb)
         
     | 
| 
       73 
     | 
    
         
            -
              #     resources :products
         
     | 
| 
       74 
     | 
    
         
            -
              #   end
         
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
              # You can have the root of your site routed with "root"
         
     | 
| 
       77 
     | 
    
         
            -
              # just remember to delete public/index.html.
         
     | 
| 
       78 
     | 
    
         
            -
              # root :to => "welcome#index"
         
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
              # See how all your routes lay out with "rake routes"
         
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
              # This is a legacy wild controller route that's not recommended for RESTful applications.
         
     | 
| 
       83 
     | 
    
         
            -
              # Note: This route will make all actions in every controller accessible via GET requests.
         
     | 
| 
       84 
     | 
    
         
            -
              # match ':controller(/:action(/:id(.:format)))'
         
     | 
| 
       85 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,189 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'sugar-high/class_ext'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            class Trial
         
     | 
| 
       5 
     | 
    
         
            -
              include ClassExt
         
     | 
| 
       6 
     | 
    
         
            -
            end
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
            class Hello
         
     | 
| 
       9 
     | 
    
         
            -
            end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            module GoodBye
         
     | 
| 
       12 
     | 
    
         
            -
              module Alpha
         
     | 
| 
       13 
     | 
    
         
            -
                module Beta
         
     | 
| 
       14 
     | 
    
         
            -
                end
         
     | 
| 
       15 
     | 
    
         
            -
              end
         
     | 
| 
       16 
     | 
    
         
            -
            end
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
            module First 
         
     | 
| 
       19 
     | 
    
         
            -
              module ClassMethods
         
     | 
| 
       20 
     | 
    
         
            -
                def class_method
         
     | 
| 
       21 
     | 
    
         
            -
                end
         
     | 
| 
       22 
     | 
    
         
            -
              end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
              module InstanceMethods
         
     | 
| 
       25 
     | 
    
         
            -
                def instance_method
         
     | 
| 
       26 
     | 
    
         
            -
                end
         
     | 
| 
       27 
     | 
    
         
            -
              end
         
     | 
| 
       28 
     | 
    
         
            -
            end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
            module Second
         
     | 
| 
       31 
     | 
    
         
            -
              include_and_extend First
         
     | 
| 
       32 
     | 
    
         
            -
            end
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
            class Third
         
     | 
| 
       35 
     | 
    
         
            -
              include_and_extend Second
         
     | 
| 
       36 
     | 
    
         
            -
            end
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
            def trial
         
     | 
| 
       39 
     | 
    
         
            -
              @trial ||= Trial.new
         
     | 
| 
       40 
     | 
    
         
            -
            end
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
            describe Module do
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
              describe "#include_and_extend" do
         
     | 
| 
       45 
     | 
    
         
            -
                it "should include class methods directly" do
         
     | 
| 
       46 
     | 
    
         
            -
                  Second.should respond_to(:class_method)
         
     | 
| 
       47 
     | 
    
         
            -
                end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                it "should not include class methods indirectly" do
         
     | 
| 
       51 
     | 
    
         
            -
                  Third.should_not respond_to(:class_method)
         
     | 
| 
       52 
     | 
    
         
            -
                end
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
                it "should include class methods" do
         
     | 
| 
       55 
     | 
    
         
            -
                  Third.new.should respond_to(:instance_method)
         
     | 
| 
       56 
     | 
    
         
            -
                end
         
     | 
| 
       57 
     | 
    
         
            -
              end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
              describe "#autoload_modules" do
         
     | 
| 
       60 
     | 
    
         
            -
                it "should autoload modules using :from => path" do
         
     | 
| 
       61 
     | 
    
         
            -
                  require 'fixtures/autoload_modules'
         
     | 
| 
       62 
     | 
    
         
            -
                  AutoloadModules::Third.should respond_to(:test)
         
     | 
| 
       63 
     | 
    
         
            -
                end
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
                it "should autoload modules from __FILE__'s dir if :from is omitted'" do
         
     | 
| 
       66 
     | 
    
         
            -
                  require 'fixtures/autoload_modulez'
         
     | 
| 
       67 
     | 
    
         
            -
                  AutoloadModulez::ThirdOneHere.should respond_to(:test)
         
     | 
| 
       68 
     | 
    
         
            -
                end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
                context 'using AutoLoader.root' do
         
     | 
| 
       71 
     | 
    
         
            -
                  it 'empty root' do
         
     | 
| 
       72 
     | 
    
         
            -
                    AutoLoader.root = ''
         
     | 
| 
       73 
     | 
    
         
            -
                    require 'autoload_blank_root'
         
     | 
| 
       74 
     | 
    
         
            -
                    AutoloadBlankRoot::Hello.should respond_to(:test)
         
     | 
| 
       75 
     | 
    
         
            -
                  end
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
                  it 'should autoload modules using ClassExt#autoload_root' do
         
     | 
| 
       78 
     | 
    
         
            -
                    AutoLoader.root = 'fixtures'
         
     | 
| 
       79 
     | 
    
         
            -
                    require 'fixtures/autoload_modules_root'
         
     | 
| 
       80 
     | 
    
         
            -
                    AutoloadModulesRoot::Third.should respond_to(:test)
         
     | 
| 
       81 
     | 
    
         
            -
                  end
         
     | 
| 
       82 
     | 
    
         
            -
                end
         
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
                context 'using AutoLoader.namespaces' do
         
     | 
| 
       85 
     | 
    
         
            -
                  it 'empty root' do
         
     | 
| 
       86 
     | 
    
         
            -
                    AutoLoader.root = ''
         
     | 
| 
       87 
     | 
    
         
            -
                    AutoLoader.namespaces= {:AutoLoadBlankRoot => 'autoload_blank_root', :HelloSailor => 'sailor'}
         
     | 
| 
       88 
     | 
    
         
            -
                    require 'auto_load_blank_root'
         
     | 
| 
       89 
     | 
    
         
            -
                    AutoLoadBlankRoot::HelloSailor.should respond_to(:test)
         
     | 
| 
       90 
     | 
    
         
            -
                  end
         
     | 
| 
       91 
     | 
    
         
            -
                end
         
     | 
| 
       92 
     | 
    
         
            -
              end
         
     | 
| 
       93 
     | 
    
         
            -
            end
         
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
            describe ClassExt do
         
     | 
| 
       96 
     | 
    
         
            -
              describe '#try_module' do
         
     | 
| 
       97 
     | 
    
         
            -
                it "should return false if no module found" do
         
     | 
| 
       98 
     | 
    
         
            -
                  trial.try_module('Blip').should be_false
         
     | 
| 
       99 
     | 
    
         
            -
                  trial.try_module(:Blip).should be_false
         
     | 
| 
       100 
     | 
    
         
            -
                  trial.try_module(nil).should be_false
         
     | 
| 
       101 
     | 
    
         
            -
                end
         
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
                it "should return module if found" do
         
     | 
| 
       104 
     | 
    
         
            -
                  trial.try_module('GoodBye').should be_a(Module)
         
     | 
| 
       105 
     | 
    
         
            -
                  trial.try_module(:GoodBye).should be_a(Module)       
         
     | 
| 
       106 
     | 
    
         
            -
                end
         
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
                it "should return namespaced module if found" do
         
     | 
| 
       109 
     | 
    
         
            -
                  trial.try_module('GoodBye::Alpha::Beta').should be_a(Module)
         
     | 
| 
       110 
     | 
    
         
            -
                end
         
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
                it "should return false if only class of that name is found" do
         
     | 
| 
       113 
     | 
    
         
            -
                  trial.try_module('Hello').should be_true
         
     | 
| 
       114 
     | 
    
         
            -
                end
         
     | 
| 
       115 
     | 
    
         
            -
              end
         
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
              describe '#try_class' do
         
     | 
| 
       118 
     | 
    
         
            -
                it "should return false if no class found" do
         
     | 
| 
       119 
     | 
    
         
            -
                  trial.try_class('Blip').should be_false
         
     | 
| 
       120 
     | 
    
         
            -
                  trial.try_class(:Blip).should be_false
         
     | 
| 
       121 
     | 
    
         
            -
                  trial.try_class(nil).should be_false
         
     | 
| 
       122 
     | 
    
         
            -
                end
         
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
                it "should return class if found" do
         
     | 
| 
       125 
     | 
    
         
            -
                  trial.try_class('Hello').should be_a(Class)
         
     | 
| 
       126 
     | 
    
         
            -
                  trial.try_class(:Hello).should be_a(Class)
         
     | 
| 
       127 
     | 
    
         
            -
                end
         
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
                it "should return false if only class of that name is found" do
         
     | 
| 
       130 
     | 
    
         
            -
                  trial.try_class('GoodBye').should be_false
         
     | 
| 
       131 
     | 
    
         
            -
                end
         
     | 
| 
       132 
     | 
    
         
            -
              end
         
     | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
              describe '#class_exists?' do
         
     | 
| 
       135 
     | 
    
         
            -
                it "should return false if no class found" do
         
     | 
| 
       136 
     | 
    
         
            -
                  trial.class_exists?('Blip').should be_false
         
     | 
| 
       137 
     | 
    
         
            -
                end
         
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
       139 
     | 
    
         
            -
                it "should return true if class found" do
         
     | 
| 
       140 
     | 
    
         
            -
                  trial.class_exists?('Hello').should be_true
         
     | 
| 
       141 
     | 
    
         
            -
                end
         
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
                it "should return false if module found" do
         
     | 
| 
       144 
     | 
    
         
            -
                  trial.class_exists?('GoodBye').should be_false
         
     | 
| 
       145 
     | 
    
         
            -
                end
         
     | 
| 
       146 
     | 
    
         
            -
              end
         
     | 
| 
       147 
     | 
    
         
            -
             
     | 
| 
       148 
     | 
    
         
            -
              describe '#module_exists?' do
         
     | 
| 
       149 
     | 
    
         
            -
                it "should return false if no module found" do
         
     | 
| 
       150 
     | 
    
         
            -
                  trial.module_exists?('Blip').should be_false
         
     | 
| 
       151 
     | 
    
         
            -
                end
         
     | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
     | 
    
         
            -
                it "should return true if module found" do
         
     | 
| 
       154 
     | 
    
         
            -
                  trial.module_exists?('GoodBye').should be_true
         
     | 
| 
       155 
     | 
    
         
            -
                end
         
     | 
| 
       156 
     | 
    
         
            -
             
     | 
| 
       157 
     | 
    
         
            -
                it "should return false if only class found" do
         
     | 
| 
       158 
     | 
    
         
            -
                  trial.module_exists?('Hello').should be_false
         
     | 
| 
       159 
     | 
    
         
            -
                end
         
     | 
| 
       160 
     | 
    
         
            -
              end
         
     | 
| 
       161 
     | 
    
         
            -
             
     | 
| 
       162 
     | 
    
         
            -
              describe '#try_module_only' do
         
     | 
| 
       163 
     | 
    
         
            -
                it 'should find module' do
         
     | 
| 
       164 
     | 
    
         
            -
                  trial.try_module_only('Hello').should be_false
         
     | 
| 
       165 
     | 
    
         
            -
                  trial.try_module_only('GoodBye').should be_true
         
     | 
| 
       166 
     | 
    
         
            -
                end
         
     | 
| 
       167 
     | 
    
         
            -
              end
         
     | 
| 
       168 
     | 
    
         
            -
             
     | 
| 
       169 
     | 
    
         
            -
              describe '#find_first_class' do
         
     | 
| 
       170 
     | 
    
         
            -
                it 'should find first class' do
         
     | 
| 
       171 
     | 
    
         
            -
                  trial.find_first_class('GoodBye', 'Hello').should == Hello
         
     | 
| 
       172 
     | 
    
         
            -
                end
         
     | 
| 
       173 
     | 
    
         
            -
             
     | 
| 
       174 
     | 
    
         
            -
                it 'should not find any module' do
         
     | 
| 
       175 
     | 
    
         
            -
                  lambda {trial.find_first_class('Good', 'Bye') }.should raise_error
         
     | 
| 
       176 
     | 
    
         
            -
                end
         
     | 
| 
       177 
     | 
    
         
            -
              end
         
     | 
| 
       178 
     | 
    
         
            -
             
     | 
| 
       179 
     | 
    
         
            -
              describe '#find_first_module' do
         
     | 
| 
       180 
     | 
    
         
            -
                it 'should find first module' do
         
     | 
| 
       181 
     | 
    
         
            -
                  first_module = trial.find_first_module('GoodBye::Alpha::Beta', 'Hello')
         
     | 
| 
       182 
     | 
    
         
            -
                  first_module.should == GoodBye::Alpha::Beta
         
     | 
| 
       183 
     | 
    
         
            -
                end
         
     | 
| 
       184 
     | 
    
         
            -
             
     | 
| 
       185 
     | 
    
         
            -
                it 'should not find any module' do
         
     | 
| 
       186 
     | 
    
         
            -
                  lambda {trial.find_first_module('Good', 'Bye') }.should raise_error
         
     | 
| 
       187 
     | 
    
         
            -
                end
         
     | 
| 
       188 
     | 
    
         
            -
              end
         
     | 
| 
       189 
     | 
    
         
            -
            end
         
     |