abstract_class 0.0.2 → 1.0.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.
- checksums.yaml +7 -0
 - data/.gitignore +2 -0
 - data/.rspec +2 -0
 - data/.travis.yml +5 -0
 - data/Gemfile +3 -0
 - data/Gemfile.lock +39 -0
 - data/{MIT-LICENSE → LICENSE} +2 -2
 - data/README.md +80 -0
 - data/abstract_class.gemspec +20 -0
 - data/lib/abstract_class.rb +24 -26
 - data/lib/abstract_class/version.rb +2 -16
 - data/spec/abstract_class_spec.rb +41 -0
 - data/spec/spec_helper.rb +95 -0
 - metadata +74 -61
 - data/README.rdoc +0 -65
 - data/Rakefile +0 -22
 - data/lib/abstract_class/test_helper.rb +0 -27
 - data/test/abstract_class_test.rb +0 -49
 - data/test/test_helper.rb +0 -7
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: bfcc784ab27947ac6d5e7935cf675406f64023b1
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: ddd41d3b70a4d2eaddfde81ff5682a4803198b3e
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 781f01d584bf096751bfa9e458aa23908a343d8a8d7b06c68b2fce5b29884745d608a47bca81c192a9a0c6319e46bb1e1b4253428765f91e581ad50f03179e15
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 983955c5a42dfcc77199d1a754ac2ae79788e37f05756a0e1cf9576ad2cecacc5071d8783ae5b3b62fe9e9e23c3850c66834fd7f812b5e0e0a095a638d164ef9
         
     | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.rspec
    ADDED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/Gemfile.lock
    ADDED
    
    | 
         @@ -0,0 +1,39 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            PATH
         
     | 
| 
      
 2 
     | 
    
         
            +
              remote: .
         
     | 
| 
      
 3 
     | 
    
         
            +
              specs:
         
     | 
| 
      
 4 
     | 
    
         
            +
                abstract_class (1.0.0)
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            GEM
         
     | 
| 
      
 7 
     | 
    
         
            +
              remote: https://rubygems.org/
         
     | 
| 
      
 8 
     | 
    
         
            +
              specs:
         
     | 
| 
      
 9 
     | 
    
         
            +
                codeclimate-test-reporter (0.4.6)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  simplecov (>= 0.7.1, < 1.0.0)
         
     | 
| 
      
 11 
     | 
    
         
            +
                diff-lcs (1.2.5)
         
     | 
| 
      
 12 
     | 
    
         
            +
                docile (1.1.5)
         
     | 
| 
      
 13 
     | 
    
         
            +
                multi_json (1.10.1)
         
     | 
| 
      
 14 
     | 
    
         
            +
                rspec (3.2.0)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  rspec-core (~> 3.2.0)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  rspec-expectations (~> 3.2.0)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  rspec-mocks (~> 3.2.0)
         
     | 
| 
      
 18 
     | 
    
         
            +
                rspec-core (3.2.1)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  rspec-support (~> 3.2.0)
         
     | 
| 
      
 20 
     | 
    
         
            +
                rspec-expectations (3.2.0)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  rspec-support (~> 3.2.0)
         
     | 
| 
      
 23 
     | 
    
         
            +
                rspec-mocks (3.2.1)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  rspec-support (~> 3.2.0)
         
     | 
| 
      
 26 
     | 
    
         
            +
                rspec-support (3.2.2)
         
     | 
| 
      
 27 
     | 
    
         
            +
                simplecov (0.9.2)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  docile (~> 1.1.0)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  multi_json (~> 1.0)
         
     | 
| 
      
 30 
     | 
    
         
            +
                  simplecov-html (~> 0.9.0)
         
     | 
| 
      
 31 
     | 
    
         
            +
                simplecov-html (0.9.0)
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            PLATFORMS
         
     | 
| 
      
 34 
     | 
    
         
            +
              ruby
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            DEPENDENCIES
         
     | 
| 
      
 37 
     | 
    
         
            +
              abstract_class!
         
     | 
| 
      
 38 
     | 
    
         
            +
              codeclimate-test-reporter
         
     | 
| 
      
 39 
     | 
    
         
            +
              rspec
         
     | 
    
        data/{MIT-LICENSE → LICENSE}
    RENAMED
    
    | 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            Copyright (c) 2011 Sean Huber - shuber 
     | 
| 
      
 1 
     | 
    
         
            +
            Copyright (c) 2011 Sean Huber - github@shuber.io
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            Permission is hereby granted, free of charge, to any person obtaining
         
     | 
| 
       4 
4 
     | 
    
         
             
            a copy of this software and associated documentation files (the
         
     | 
| 
         @@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
     | 
|
| 
       17 
17 
     | 
    
         
             
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         
     | 
| 
       18 
18 
     | 
    
         
             
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         
     | 
| 
       19 
19 
     | 
    
         
             
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         
     | 
| 
       20 
     | 
    
         
            -
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
| 
      
 20 
     | 
    
         
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
    
        data/README.md
    ADDED
    
    | 
         @@ -0,0 +1,80 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # abstract_class [](https://travis-ci.org/shuber/abstract_class) [](https://codeclimate.com/github/shuber/abstract_class) [](https://codeclimate.com/github/shuber/abstract_class)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            > Abstract classes in Ruby.
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Like modules, abstract classes **cannot be instantiated**.
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            Unlike modules, abstract classes can be inherited and their **derived classes can be instantiated**.
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            Check out the [java] or [php] implementations for additional examples.
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            [java]: http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html
         
     | 
| 
      
 12 
     | 
    
         
            +
            [php]: http://php.net/manual/en/language.oop5.abstract.php
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            ## Installation
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            ```
         
     | 
| 
      
 17 
     | 
    
         
            +
            gem install abstract_class
         
     | 
| 
      
 18 
     | 
    
         
            +
            ```
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            ## Usage
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            To make a class *abstract*, simply extend the `AbstractClass` module.
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 26 
     | 
    
         
            +
            module ActiveRecord
         
     | 
| 
      
 27 
     | 
    
         
            +
              class Base
         
     | 
| 
      
 28 
     | 
    
         
            +
                extend AbstractClass
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
            end
         
     | 
| 
      
 31 
     | 
    
         
            +
            ```
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            Any attempts to initialize or allocate an instance of an *abstract* class raises `AbstractClass::Error`.
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 36 
     | 
    
         
            +
            ActiveRecord::Base.new      #=> AbstractClass::Error - abstract class ActiveRecord::Base can't be instantiated
         
     | 
| 
      
 37 
     | 
    
         
            +
            ActiveRecord::Base.allocate #=> AbstractClass::Error - abstract class ActiveRecord::Base can't be allocated
         
     | 
| 
      
 38 
     | 
    
         
            +
            ```
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            Child classes can inherit from an *abstract* class.
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 43 
     | 
    
         
            +
            class User < ActiveRecord::Base
         
     | 
| 
      
 44 
     | 
    
         
            +
            end
         
     | 
| 
      
 45 
     | 
    
         
            +
            ```
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            Instantiation and allocation behaves like normal for descendants of *abstract* classes.
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 50 
     | 
    
         
            +
            User.new      #=> #<User:0x003d066d5a861d>
         
     | 
| 
      
 51 
     | 
    
         
            +
            User.allocate #=> #<User:0x007f87588491d0>
         
     | 
| 
      
 52 
     | 
    
         
            +
            ```
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            ## API
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
            [YARD Documentation](http://www.rubydoc.info/github/shuber/abstract_class/master)
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
            ## Testing
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
            ```
         
     | 
| 
      
 63 
     | 
    
         
            +
            bundle exec rspec
         
     | 
| 
      
 64 
     | 
    
         
            +
            ```
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
            ## Contributing
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
            * Fork the project.
         
     | 
| 
      
 70 
     | 
    
         
            +
            * Make your feature addition or bug fix.
         
     | 
| 
      
 71 
     | 
    
         
            +
            * Add tests for it. This is important so I don't break it in a future version unintentionally.
         
     | 
| 
      
 72 
     | 
    
         
            +
            * Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
         
     | 
| 
      
 73 
     | 
    
         
            +
            * Send me a pull request. Bonus points for topic branches.
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
            ## License
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
            [MIT] - Copyright © 2011 Sean Huber
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
            [MIT]: https://github.com/shuber/abstract_class/blob/master/LICENSE
         
     | 
| 
         @@ -0,0 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.expand_path('../lib/abstract_class/version', __FILE__)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Gem::Specification.new do |s|
         
     | 
| 
      
 4 
     | 
    
         
            +
              s.author           = 'Sean Huber'
         
     | 
| 
      
 5 
     | 
    
         
            +
              s.description      = 'An implementation of the "abstract class" design pattern in Ruby'
         
     | 
| 
      
 6 
     | 
    
         
            +
              s.email            = 'github@shuber.io'
         
     | 
| 
      
 7 
     | 
    
         
            +
              s.extra_rdoc_files = %w(LICENSE)
         
     | 
| 
      
 8 
     | 
    
         
            +
              s.files            = `git ls-files`.split("\n")
         
     | 
| 
      
 9 
     | 
    
         
            +
              s.homepage         = 'https://github.com/shuber/abstract_class'
         
     | 
| 
      
 10 
     | 
    
         
            +
              s.license          = 'MIT'
         
     | 
| 
      
 11 
     | 
    
         
            +
              s.name             = 'abstract_class'
         
     | 
| 
      
 12 
     | 
    
         
            +
              s.rdoc_options     = %w(--charset=UTF-8 --inline-source --line-numbers --main README.md)
         
     | 
| 
      
 13 
     | 
    
         
            +
              s.require_paths    = %w(lib)
         
     | 
| 
      
 14 
     | 
    
         
            +
              s.summary          = 'Abstract classes in Ruby'
         
     | 
| 
      
 15 
     | 
    
         
            +
              s.test_files       = `git ls-files -- spec/*`.split("\n")
         
     | 
| 
      
 16 
     | 
    
         
            +
              s.version          = AbstractClass::VERSION
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              s.add_development_dependency 'codeclimate-test-reporter'
         
     | 
| 
      
 19 
     | 
    
         
            +
              s.add_development_dependency 'rspec'
         
     | 
| 
      
 20 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/abstract_class.rb
    CHANGED
    
    | 
         @@ -1,38 +1,36 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
            module AbstractClass
         
     | 
| 
       3 
     | 
    
         
            -
              autoload :TestHelper, 'abstract_class/test_helper'
         
     | 
| 
       4 
     | 
    
         
            -
              autoload :Version,    'abstract_class/version'
         
     | 
| 
      
 1 
     | 
    
         
            +
            require 'abstract_class/version'
         
     | 
| 
       5 
2 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                  alias_method :allocate, :allocate_with_abstract_class
         
     | 
| 
      
 3 
     | 
    
         
            +
            # Declares a class as abstract which prevents instantiation or allocation.
         
     | 
| 
      
 4 
     | 
    
         
            +
            module AbstractClass
         
     | 
| 
      
 5 
     | 
    
         
            +
              # The exception raised when an abstract class is instantiated or allocated.
         
     | 
| 
      
 6 
     | 
    
         
            +
              Error = Class.new(RuntimeError)
         
     | 
| 
       11 
7 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
                end
         
     | 
| 
      
 8 
     | 
    
         
            +
              def self.extended(mod)
         
     | 
| 
      
 9 
     | 
    
         
            +
                mod.abstract_classes << mod
         
     | 
| 
       15 
10 
     | 
    
         
             
              end
         
     | 
| 
       16 
11 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
              #  
     | 
| 
       18 
     | 
    
         
            -
              def  
     | 
| 
       19 
     | 
    
         
            -
                 
     | 
| 
      
 12 
     | 
    
         
            +
              # Stores a collection of classes that have been declared as abstract.
         
     | 
| 
      
 13 
     | 
    
         
            +
              def abstract_classes
         
     | 
| 
      
 14 
     | 
    
         
            +
                @@abstract_classes ||= []
         
     | 
| 
       20 
15 
     | 
    
         
             
              end
         
     | 
| 
       21 
16 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
              #  
     | 
| 
       23 
     | 
    
         
            -
              def  
     | 
| 
       24 
     | 
    
         
            -
                 
     | 
| 
      
 17 
     | 
    
         
            +
              # Raises {AbstractClass::Error} if the class is abstract
         
     | 
| 
      
 18 
     | 
    
         
            +
              def allocate(*args)
         
     | 
| 
      
 19 
     | 
    
         
            +
                raise_if_abstract(:allocated) { super }
         
     | 
| 
       25 
20 
     | 
    
         
             
              end
         
     | 
| 
       26 
21 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
              # Raises  
     | 
| 
       28 
     | 
    
         
            -
              def  
     | 
| 
       29 
     | 
    
         
            -
                 
     | 
| 
      
 22 
     | 
    
         
            +
              # Raises {AbstractClass::Error} if the class is abstract
         
     | 
| 
      
 23 
     | 
    
         
            +
              def new(*args)
         
     | 
| 
      
 24 
     | 
    
         
            +
                raise_if_abstract(:instantiated) { super }
         
     | 
| 
       30 
25 
     | 
    
         
             
              end
         
     | 
| 
       31 
26 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
               
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
      
 27 
     | 
    
         
            +
              private
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              def raise_if_abstract(method)
         
     | 
| 
      
 30 
     | 
    
         
            +
                if abstract_classes.include?(self)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  raise Error, "abstract class #{self} can't be #{method}"
         
     | 
| 
      
 32 
     | 
    
         
            +
                else
         
     | 
| 
      
 33 
     | 
    
         
            +
                  yield
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
       35 
35 
     | 
    
         
             
              end
         
     | 
| 
       36 
36 
     | 
    
         
             
            end
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
            Class.send(:include, AbstractClass)
         
     | 
| 
         @@ -1,17 +1,3 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module AbstractClass
         
     | 
| 
       2 
     | 
    
         
            -
               
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
                MAJOR = 0
         
     | 
| 
       5 
     | 
    
         
            -
                MINOR = 0
         
     | 
| 
       6 
     | 
    
         
            -
                PATCH = 2
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
                # Returns a version string by joining <tt>MAJOR</tt>, <tt>MINOR</tt>, and <tt>PATCH</tt> with <tt>'.'</tt>
         
     | 
| 
       9 
     | 
    
         
            -
                #
         
     | 
| 
       10 
     | 
    
         
            -
                # Example
         
     | 
| 
       11 
     | 
    
         
            -
                #
         
     | 
| 
       12 
     | 
    
         
            -
                #   Version.string # '1.0.2'
         
     | 
| 
       13 
     | 
    
         
            -
                def self.string
         
     | 
| 
       14 
     | 
    
         
            -
                  [MAJOR, MINOR, PATCH].join('.')
         
     | 
| 
       15 
     | 
    
         
            -
                end
         
     | 
| 
       16 
     | 
    
         
            -
              end
         
     | 
| 
       17 
     | 
    
         
            -
            end
         
     | 
| 
      
 2 
     | 
    
         
            +
              VERSION = '1.0.0'
         
     | 
| 
      
 3 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,41 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative '../lib/abstract_class'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            RSpec.describe AbstractClass do
         
     | 
| 
      
 4 
     | 
    
         
            +
              let(:abstract) { Class.new.extend(described_class) }
         
     | 
| 
      
 5 
     | 
    
         
            +
              let(:derived)  { Class.new(abstract) }
         
     | 
| 
      
 6 
     | 
    
         
            +
              let(:error)    { described_class::Error }
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              describe '.abstract_classes' do
         
     | 
| 
      
 9 
     | 
    
         
            +
                it 'should include the abstract class' do
         
     | 
| 
      
 10 
     | 
    
         
            +
                  expect(abstract.abstract_classes).to include(abstract)
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                it 'should only include abstract derived classes' do
         
     | 
| 
      
 14 
     | 
    
         
            +
                  expect(abstract.abstract_classes).not_to include(derived)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  derived.extend(described_class)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  expect(abstract.abstract_classes).to include(derived)
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
              describe '.allocate' do
         
     | 
| 
      
 21 
     | 
    
         
            +
                it 'should not allow an abstract class to be allocated' do
         
     | 
| 
      
 22 
     | 
    
         
            +
                  initializer = -> { abstract.allocate }
         
     | 
| 
      
 23 
     | 
    
         
            +
                  expect(initializer).to raise_error(error)
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                it 'should allow a derived class to be allocated' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                  expect(derived.allocate).to be_is_a(derived)
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              describe '.new' do
         
     | 
| 
      
 32 
     | 
    
         
            +
                it 'should not allow an abstract class to be initialized' do
         
     | 
| 
      
 33 
     | 
    
         
            +
                  initializer = -> { abstract.new }
         
     | 
| 
      
 34 
     | 
    
         
            +
                  expect(initializer).to raise_error(error)
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                it 'should allow a derived class to be initialized' do
         
     | 
| 
      
 38 
     | 
    
         
            +
                  expect(derived.new).to be_is_a(derived)
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
              end
         
     | 
| 
      
 41 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | 
         @@ -0,0 +1,95 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            if ENV['CODECLIMATE_REPO_TOKEN']
         
     | 
| 
      
 2 
     | 
    
         
            +
              require 'codeclimate-test-reporter'
         
     | 
| 
      
 3 
     | 
    
         
            +
              CodeClimate::TestReporter.start
         
     | 
| 
      
 4 
     | 
    
         
            +
            end
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            # This file was generated by the `rspec --init` command. Conventionally, all
         
     | 
| 
      
 7 
     | 
    
         
            +
            # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
         
     | 
| 
      
 8 
     | 
    
         
            +
            # The generated `.rspec` file contains `--require spec_helper` which will cause
         
     | 
| 
      
 9 
     | 
    
         
            +
            # this file to always be loaded, without a need to explicitly require it in any
         
     | 
| 
      
 10 
     | 
    
         
            +
            # files.
         
     | 
| 
      
 11 
     | 
    
         
            +
            #
         
     | 
| 
      
 12 
     | 
    
         
            +
            # Given that it is always loaded, you are encouraged to keep this file as
         
     | 
| 
      
 13 
     | 
    
         
            +
            # light-weight as possible. Requiring heavyweight dependencies from this file
         
     | 
| 
      
 14 
     | 
    
         
            +
            # will add to the boot time of your test suite on EVERY test run, even for an
         
     | 
| 
      
 15 
     | 
    
         
            +
            # individual file that may not need all of that loaded. Instead, consider making
         
     | 
| 
      
 16 
     | 
    
         
            +
            # a separate helper file that requires the additional dependencies and performs
         
     | 
| 
      
 17 
     | 
    
         
            +
            # the additional setup, and require it from the spec files that actually need
         
     | 
| 
      
 18 
     | 
    
         
            +
            # it.
         
     | 
| 
      
 19 
     | 
    
         
            +
            #
         
     | 
| 
      
 20 
     | 
    
         
            +
            # The `.rspec` file also contains a few flags that are not defaults but that
         
     | 
| 
      
 21 
     | 
    
         
            +
            # users commonly want.
         
     | 
| 
      
 22 
     | 
    
         
            +
            #
         
     | 
| 
      
 23 
     | 
    
         
            +
            # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
         
     | 
| 
      
 24 
     | 
    
         
            +
            RSpec.configure do |config|
         
     | 
| 
      
 25 
     | 
    
         
            +
              # rspec-expectations config goes here. You can use an alternate
         
     | 
| 
      
 26 
     | 
    
         
            +
              # assertion/expectation library such as wrong or the stdlib/minitest
         
     | 
| 
      
 27 
     | 
    
         
            +
              # assertions if you prefer.
         
     | 
| 
      
 28 
     | 
    
         
            +
              config.expect_with :rspec do |expectations|
         
     | 
| 
      
 29 
     | 
    
         
            +
                # This option will default to `true` in RSpec 4. It makes the `description`
         
     | 
| 
      
 30 
     | 
    
         
            +
                # and `failure_message` of custom matchers include text for helper methods
         
     | 
| 
      
 31 
     | 
    
         
            +
                # defined using `chain`, e.g.:
         
     | 
| 
      
 32 
     | 
    
         
            +
                #     be_bigger_than(2).and_smaller_than(4).description
         
     | 
| 
      
 33 
     | 
    
         
            +
                #     # => "be bigger than 2 and smaller than 4"
         
     | 
| 
      
 34 
     | 
    
         
            +
                # ...rather than:
         
     | 
| 
      
 35 
     | 
    
         
            +
                #     # => "be bigger than 2"
         
     | 
| 
      
 36 
     | 
    
         
            +
                expectations.include_chain_clauses_in_custom_matcher_descriptions = true
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
              # rspec-mocks config goes here. You can use an alternate test double
         
     | 
| 
      
 40 
     | 
    
         
            +
              # library (such as bogus or mocha) by changing the `mock_with` option here.
         
     | 
| 
      
 41 
     | 
    
         
            +
              config.mock_with :rspec do |mocks|
         
     | 
| 
      
 42 
     | 
    
         
            +
                # Prevents you from mocking or stubbing a method that does not exist on
         
     | 
| 
      
 43 
     | 
    
         
            +
                # a real object. This is generally recommended, and will default to
         
     | 
| 
      
 44 
     | 
    
         
            +
                # `true` in RSpec 4.
         
     | 
| 
      
 45 
     | 
    
         
            +
                mocks.verify_partial_doubles = true
         
     | 
| 
      
 46 
     | 
    
         
            +
              end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
              # The settings below are suggested to provide a good initial experience
         
     | 
| 
      
 49 
     | 
    
         
            +
              # with RSpec, but feel free to customize to your heart's content.
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
              # These two settings work together to allow you to limit a spec run
         
     | 
| 
      
 52 
     | 
    
         
            +
              # to individual examples or groups you care about by tagging them with
         
     | 
| 
      
 53 
     | 
    
         
            +
              # `:focus` metadata. When nothing is tagged with `:focus`, all examples
         
     | 
| 
      
 54 
     | 
    
         
            +
              # get run.
         
     | 
| 
      
 55 
     | 
    
         
            +
              config.filter_run :focus
         
     | 
| 
      
 56 
     | 
    
         
            +
              config.run_all_when_everything_filtered = true
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
              # Limits the available syntax to the non-monkey patched syntax that is
         
     | 
| 
      
 59 
     | 
    
         
            +
              # recommended. For more details, see:
         
     | 
| 
      
 60 
     | 
    
         
            +
              #   - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
         
     | 
| 
      
 61 
     | 
    
         
            +
              #   - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
         
     | 
| 
      
 62 
     | 
    
         
            +
              #   - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
         
     | 
| 
      
 63 
     | 
    
         
            +
              config.disable_monkey_patching!
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
              # This setting enables warnings. It's recommended, but in some cases may
         
     | 
| 
      
 66 
     | 
    
         
            +
              # be too noisy due to issues in dependencies.
         
     | 
| 
      
 67 
     | 
    
         
            +
              config.warnings = true
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
              # Many RSpec users commonly either run the entire suite or an individual
         
     | 
| 
      
 70 
     | 
    
         
            +
              # file, and it's useful to allow more verbose output when running an
         
     | 
| 
      
 71 
     | 
    
         
            +
              # individual spec file.
         
     | 
| 
      
 72 
     | 
    
         
            +
              if config.files_to_run.one?
         
     | 
| 
      
 73 
     | 
    
         
            +
                # Use the documentation formatter for detailed output,
         
     | 
| 
      
 74 
     | 
    
         
            +
                # unless a formatter has already been configured
         
     | 
| 
      
 75 
     | 
    
         
            +
                # (e.g. via a command-line flag).
         
     | 
| 
      
 76 
     | 
    
         
            +
                config.default_formatter = 'doc'
         
     | 
| 
      
 77 
     | 
    
         
            +
              end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
              # Print the 10 slowest examples and example groups at the
         
     | 
| 
      
 80 
     | 
    
         
            +
              # end of the spec run, to help surface which specs are running
         
     | 
| 
      
 81 
     | 
    
         
            +
              # particularly slow.
         
     | 
| 
      
 82 
     | 
    
         
            +
              config.profile_examples = 10
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
              # Run specs in random order to surface order dependencies. If you find an
         
     | 
| 
      
 85 
     | 
    
         
            +
              # order dependency and want to debug it, you can fix the order by providing
         
     | 
| 
      
 86 
     | 
    
         
            +
              # the seed, which is printed after each run.
         
     | 
| 
      
 87 
     | 
    
         
            +
              #     --seed 1234
         
     | 
| 
      
 88 
     | 
    
         
            +
              config.order = :random
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
              # Seed global randomization in this process using the `--seed` CLI option.
         
     | 
| 
      
 91 
     | 
    
         
            +
              # Setting this allows you to use `--seed` to deterministically reproduce
         
     | 
| 
      
 92 
     | 
    
         
            +
              # test failures related to randomization by passing the same `--seed` value
         
     | 
| 
      
 93 
     | 
    
         
            +
              # as the one that triggered the failure.
         
     | 
| 
      
 94 
     | 
    
         
            +
              Kernel.srand config.seed
         
     | 
| 
      
 95 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,78 +1,91 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            --- !ruby/object:Gem::Specification 
     | 
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: abstract_class
         
     | 
| 
       3 
     | 
    
         
            -
            version: !ruby/object:Gem::Version 
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
       5 
     | 
    
         
            -
              prerelease: 
         
     | 
| 
       6 
     | 
    
         
            -
              segments: 
         
     | 
| 
       7 
     | 
    
         
            -
              - 0
         
     | 
| 
       8 
     | 
    
         
            -
              - 0
         
     | 
| 
       9 
     | 
    
         
            -
              - 2
         
     | 
| 
       10 
     | 
    
         
            -
              version: 0.0.2
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.0
         
     | 
| 
       11 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       12 
     | 
    
         
            -
            authors: 
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
       13 
7 
     | 
    
         
             
            - Sean Huber
         
     | 
| 
       14 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       15 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       16 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-03-09 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 13 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 14 
     | 
    
         
            +
              name: codeclimate-test-reporter
         
     | 
| 
      
 15 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 16 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 17 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 18 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 19 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 20 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 21 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 22 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 23 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 24 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 25 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 26 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 27 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 28 
     | 
    
         
            +
              name: rspec
         
     | 
| 
      
 29 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 30 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 31 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 32 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 33 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 34 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 35 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 36 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 37 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 38 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 39 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 40 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 41 
     | 
    
         
            +
            description: An implementation of the "abstract class" design pattern in Ruby
         
     | 
| 
      
 42 
     | 
    
         
            +
            email: github@shuber.io
         
     | 
| 
       24 
43 
     | 
    
         
             
            executables: []
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
44 
     | 
    
         
             
            extensions: []
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
      
 45 
     | 
    
         
            +
            extra_rdoc_files:
         
     | 
| 
      
 46 
     | 
    
         
            +
            - LICENSE
         
     | 
| 
      
 47 
     | 
    
         
            +
            files:
         
     | 
| 
      
 48 
     | 
    
         
            +
            - ".gitignore"
         
     | 
| 
      
 49 
     | 
    
         
            +
            - ".rspec"
         
     | 
| 
      
 50 
     | 
    
         
            +
            - ".travis.yml"
         
     | 
| 
      
 51 
     | 
    
         
            +
            - Gemfile
         
     | 
| 
      
 52 
     | 
    
         
            +
            - Gemfile.lock
         
     | 
| 
      
 53 
     | 
    
         
            +
            - LICENSE
         
     | 
| 
      
 54 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 55 
     | 
    
         
            +
            - abstract_class.gemspec
         
     | 
| 
       31 
56 
     | 
    
         
             
            - lib/abstract_class.rb
         
     | 
| 
       32 
     | 
    
         
            -
            - lib/abstract_class/test_helper.rb
         
     | 
| 
       33 
57 
     | 
    
         
             
            - lib/abstract_class/version.rb
         
     | 
| 
       34 
     | 
    
         
            -
            -  
     | 
| 
       35 
     | 
    
         
            -
            -  
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
            -  
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
            homepage: http://github.com/shuber/abstract_class
         
     | 
| 
       41 
     | 
    
         
            -
            licenses: []
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
      
 58 
     | 
    
         
            +
            - spec/abstract_class_spec.rb
         
     | 
| 
      
 59 
     | 
    
         
            +
            - spec/spec_helper.rb
         
     | 
| 
      
 60 
     | 
    
         
            +
            homepage: https://github.com/shuber/abstract_class
         
     | 
| 
      
 61 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 62 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 63 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
       43 
64 
     | 
    
         
             
            post_install_message: 
         
     | 
| 
       44 
     | 
    
         
            -
            rdoc_options: 
     | 
| 
       45 
     | 
    
         
            -
            - -- 
     | 
| 
       46 
     | 
    
         
            -
            - --inline-source
         
     | 
| 
       47 
     | 
    
         
            -
            - -- 
     | 
| 
       48 
     | 
    
         
            -
            -  
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
      
 65 
     | 
    
         
            +
            rdoc_options:
         
     | 
| 
      
 66 
     | 
    
         
            +
            - "--charset=UTF-8"
         
     | 
| 
      
 67 
     | 
    
         
            +
            - "--inline-source"
         
     | 
| 
      
 68 
     | 
    
         
            +
            - "--line-numbers"
         
     | 
| 
      
 69 
     | 
    
         
            +
            - "--main"
         
     | 
| 
      
 70 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 71 
     | 
    
         
            +
            require_paths:
         
     | 
| 
       50 
72 
     | 
    
         
             
            - lib
         
     | 
| 
       51 
     | 
    
         
            -
            required_ruby_version: !ruby/object:Gem::Requirement 
     | 
| 
       52 
     | 
    
         
            -
               
     | 
| 
       53 
     | 
    
         
            -
              requirements: 
         
     | 
| 
      
 73 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 74 
     | 
    
         
            +
              requirements:
         
     | 
| 
       54 
75 
     | 
    
         
             
              - - ">="
         
     | 
| 
       55 
     | 
    
         
            -
                - !ruby/object:Gem::Version 
     | 
| 
       56 
     | 
    
         
            -
                   
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                  version: "0"
         
     | 
| 
       60 
     | 
    
         
            -
            required_rubygems_version: !ruby/object:Gem::Requirement 
         
     | 
| 
       61 
     | 
    
         
            -
              none: false
         
     | 
| 
       62 
     | 
    
         
            -
              requirements: 
         
     | 
| 
      
 76 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 77 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 78 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 79 
     | 
    
         
            +
              requirements:
         
     | 
| 
       63 
80 
     | 
    
         
             
              - - ">="
         
     | 
| 
       64 
     | 
    
         
            -
                - !ruby/object:Gem::Version 
     | 
| 
       65 
     | 
    
         
            -
                   
     | 
| 
       66 
     | 
    
         
            -
                  segments: 
         
     | 
| 
       67 
     | 
    
         
            -
                  - 0
         
     | 
| 
       68 
     | 
    
         
            -
                  version: "0"
         
     | 
| 
      
 81 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 82 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
       69 
83 
     | 
    
         
             
            requirements: []
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
84 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       72 
     | 
    
         
            -
            rubygems_version:  
     | 
| 
      
 85 
     | 
    
         
            +
            rubygems_version: 2.4.5
         
     | 
| 
       73 
86 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       74 
     | 
    
         
            -
            specification_version:  
     | 
| 
       75 
     | 
    
         
            -
            summary: Abstract classes in  
     | 
| 
       76 
     | 
    
         
            -
            test_files: 
     | 
| 
       77 
     | 
    
         
            -
            -  
     | 
| 
       78 
     | 
    
         
            -
            -  
     | 
| 
      
 87 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 88 
     | 
    
         
            +
            summary: Abstract classes in Ruby
         
     | 
| 
      
 89 
     | 
    
         
            +
            test_files:
         
     | 
| 
      
 90 
     | 
    
         
            +
            - spec/abstract_class_spec.rb
         
     | 
| 
      
 91 
     | 
    
         
            +
            - spec/spec_helper.rb
         
     | 
    
        data/README.rdoc
    DELETED
    
    | 
         @@ -1,65 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            = abstract_class
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            Abstract classes in ruby
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
            == Installation
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
              gem install abstract_class
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            == Usage
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
              class ActiveRecord::Base
         
     | 
| 
       14 
     | 
    
         
            -
                abstract
         
     | 
| 
       15 
     | 
    
         
            -
              end
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
              class User < ActiveRecord::Base
         
     | 
| 
       18 
     | 
    
         
            -
              end
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
              # RuntimeError: abstract class ActiveRecord::Base can't be instantiated/allocated
         
     | 
| 
       21 
     | 
    
         
            -
              ActiveRecord::Base.new
         
     | 
| 
       22 
     | 
    
         
            -
              ActiveRecord::Base.allocate
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
              # instantiates/allocates like normal
         
     | 
| 
       25 
     | 
    
         
            -
              User.new
         
     | 
| 
       26 
     | 
    
         
            -
              User.allocate
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
              # returns true or false
         
     | 
| 
       29 
     | 
    
         
            -
              ActiveRecord::Base.abstract?
         
     | 
| 
       30 
     | 
    
         
            -
              User.abstract?
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
            == Testing abstract classes
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
            Include <tt>AbstractClass::TestHelper</tt> in your test framework
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
              Test::Unit::TestCase.send(:include, AbstractClass::TestHelper)
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
            Then you can use <tt>assert_abstract_class</tt> or <tt>assert_not_abstract_class</tt>) in your tests
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
              class AbstractClass
         
     | 
| 
       42 
     | 
    
         
            -
                abstract
         
     | 
| 
       43 
     | 
    
         
            -
              end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
              class NormalClass < AbstractClass
         
     | 
| 
       46 
     | 
    
         
            -
              end
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
              class AbstractClassTest < Test::Unit::TestCase
         
     | 
| 
       49 
     | 
    
         
            -
                def test_should_be_abstract_class
         
     | 
| 
       50 
     | 
    
         
            -
                  assert_abstract_class AbstractClass
         
     | 
| 
       51 
     | 
    
         
            -
                end
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
                def test_should_not_be_abstract_classes
         
     | 
| 
       54 
     | 
    
         
            -
                  assert_not_abstract_classes NormalClass, Hash
         
     | 
| 
       55 
     | 
    
         
            -
                end
         
     | 
| 
       56 
     | 
    
         
            -
              end
         
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
            == Patches and pull requests
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
            * Fork the project.
         
     | 
| 
       62 
     | 
    
         
            -
            * Make your feature addition or bug fix.
         
     | 
| 
       63 
     | 
    
         
            -
            * Add tests for it. This is important so I don't break it in a future version unintentionally.
         
     | 
| 
       64 
     | 
    
         
            -
            * Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
         
     | 
| 
       65 
     | 
    
         
            -
            * Send me a pull request. Bonus points for topic branches.
         
     | 
    
        data/Rakefile
    DELETED
    
    | 
         @@ -1,22 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'rake'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'rake/testtask'
         
     | 
| 
       3 
     | 
    
         
            -
            require 'rake/rdoctask'
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            desc 'Default: run unit tests.'
         
     | 
| 
       6 
     | 
    
         
            -
            task :default => :test
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
            desc 'Test the abstract_class gem.'
         
     | 
| 
       9 
     | 
    
         
            -
            Rake::TestTask.new(:test) do |t|
         
     | 
| 
       10 
     | 
    
         
            -
              t.libs += ['lib', 'test']
         
     | 
| 
       11 
     | 
    
         
            -
              t.pattern = 'test/**/*_test.rb'
         
     | 
| 
       12 
     | 
    
         
            -
              t.verbose = true
         
     | 
| 
       13 
     | 
    
         
            -
            end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
            desc 'Generate documentation for the abstract_class gem.'
         
     | 
| 
       16 
     | 
    
         
            -
            Rake::RDocTask.new(:rdoc) do |rdoc|
         
     | 
| 
       17 
     | 
    
         
            -
              rdoc.rdoc_dir = 'rdoc'
         
     | 
| 
       18 
     | 
    
         
            -
              rdoc.title    = 'abstract_class'
         
     | 
| 
       19 
     | 
    
         
            -
              rdoc.options << '--line-numbers' << '--inline-source'
         
     | 
| 
       20 
     | 
    
         
            -
              rdoc.rdoc_files.include('README*')
         
     | 
| 
       21 
     | 
    
         
            -
              rdoc.rdoc_files.include('lib/**/*.rb')
         
     | 
| 
       22 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,27 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module AbstractClass
         
     | 
| 
       2 
     | 
    
         
            -
              # Contains abstract class testing assertions to include in your test framework
         
     | 
| 
       3 
     | 
    
         
            -
              module TestHelper
         
     | 
| 
       4 
     | 
    
         
            -
                # Asserts that the specified <tt>classes</tt> have been declared as abstract
         
     | 
| 
       5 
     | 
    
         
            -
                def assert_abstract_classes(*classes)
         
     | 
| 
       6 
     | 
    
         
            -
                  result, message = abstract_class_test(classes.flatten, true)
         
     | 
| 
       7 
     | 
    
         
            -
                  assert_block(message) { result }
         
     | 
| 
       8 
     | 
    
         
            -
                end
         
     | 
| 
       9 
     | 
    
         
            -
                alias_method :assert_abstract_class, :assert_abstract_classes
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
                # Asserts that the specified <tt>classes</tt> have not been declared as abstract
         
     | 
| 
       12 
     | 
    
         
            -
                def assert_not_abstract_classes(*classes)
         
     | 
| 
       13 
     | 
    
         
            -
                  result, message = abstract_class_test(classes.flatten, false)
         
     | 
| 
       14 
     | 
    
         
            -
                  assert_block(message) { result }
         
     | 
| 
       15 
     | 
    
         
            -
                end
         
     | 
| 
       16 
     | 
    
         
            -
                alias_method :assert_not_abstract_class, :assert_not_abstract_classes
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                protected
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
                  def abstract_class_test(classes, abstract) # :nodoc:
         
     | 
| 
       21 
     | 
    
         
            -
                    failed_classes = classes.send(abstract ? :reject : :select) { |klass| klass.abstract? }
         
     | 
| 
       22 
     | 
    
         
            -
                    class_names = failed_classes.join(', ')
         
     | 
| 
       23 
     | 
    
         
            -
                    message = failed_classes.size > 1 ? 'were' : 'was' and (message << ' not' unless abstract)
         
     | 
| 
       24 
     | 
    
         
            -
                    [failed_classes.empty?, "#{class_names} #{message} expected to be abstract"]
         
     | 
| 
       25 
     | 
    
         
            -
                  end
         
     | 
| 
       26 
     | 
    
         
            -
              end
         
     | 
| 
       27 
     | 
    
         
            -
            end
         
     | 
    
        data/test/abstract_class_test.rb
    DELETED
    
    | 
         @@ -1,49 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'test_helper'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class BaseClass
         
     | 
| 
       4 
     | 
    
         
            -
              abstract
         
     | 
| 
       5 
     | 
    
         
            -
            end
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
            class DerivedClass < BaseClass
         
     | 
| 
       8 
     | 
    
         
            -
            end
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
            class AbstractClassTest < Test::Unit::TestCase
         
     | 
| 
       11 
     | 
    
         
            -
              def test_should_not_allow_abstract_class_to_be_initialized
         
     | 
| 
       12 
     | 
    
         
            -
                assert_raises(RuntimeError) { BaseClass.new }
         
     | 
| 
       13 
     | 
    
         
            -
              end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
              def test_should_not_allow_abstract_class_to_be_allocated
         
     | 
| 
       16 
     | 
    
         
            -
                assert_raises(RuntimeError) { BaseClass.allocate }
         
     | 
| 
       17 
     | 
    
         
            -
              end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
              def test_should_allow_derived_class_to_be_initialized
         
     | 
| 
       20 
     | 
    
         
            -
                assert DerivedClass.new.is_a?(DerivedClass)
         
     | 
| 
       21 
     | 
    
         
            -
              end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
              def test_should_allow_derived_class_to_be_allocated
         
     | 
| 
       24 
     | 
    
         
            -
                assert DerivedClass.allocate.is_a?(DerivedClass)
         
     | 
| 
       25 
     | 
    
         
            -
              end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
              def test_should_check_if_a_class_is_abstract
         
     | 
| 
       28 
     | 
    
         
            -
                assert BaseClass.abstract?
         
     | 
| 
       29 
     | 
    
         
            -
                assert !DerivedClass.abstract?
         
     | 
| 
       30 
     | 
    
         
            -
              end
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
              def test_should_bypass_instantiation_restrictions
         
     | 
| 
       33 
     | 
    
         
            -
                assert DerivedClass.new_without_abstract_class.is_a?(DerivedClass)
         
     | 
| 
       34 
     | 
    
         
            -
              end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
              def test_should_bypass_allocation_restrictions
         
     | 
| 
       37 
     | 
    
         
            -
                assert DerivedClass.allocate_without_abstract_class.is_a?(DerivedClass)
         
     | 
| 
       38 
     | 
    
         
            -
              end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
              def test_should_assert_class_is_abstract
         
     | 
| 
       41 
     | 
    
         
            -
                assert_abstract_class BaseClass
         
     | 
| 
       42 
     | 
    
         
            -
                assert_raises(Test::Unit::AssertionFailedError) { assert_abstract_class DerivedClass }
         
     | 
| 
       43 
     | 
    
         
            -
              end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
              def test_should_assert_class_is_not_abstract
         
     | 
| 
       46 
     | 
    
         
            -
                assert_not_abstract_class DerivedClass
         
     | 
| 
       47 
     | 
    
         
            -
                assert_raises(Test::Unit::AssertionFailedError) { assert_not_abstract_class BaseClass }
         
     | 
| 
       48 
     | 
    
         
            -
              end
         
     | 
| 
       49 
     | 
    
         
            -
            end
         
     |