Sha256: 9354b8bc03a9ca0d590ff7d6b508205fa07c0a35297c539d722eb96fa29c4282

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

class Object
    # Throw a TypeError unless this object's type is cls
    #
    # @param cls The class this object should be
    def should_be_a(cls)
        raise(TypeError, "#{self.to_s} must be of type #{cls.to_s}") unless self.is_a?(cls)
    end
end

module Martin
    module DSL
        # This is just an Array that checks the type of the object being pushed to it
        class TypeList < Array
            def <<(obj)
                obj.should_be_a(@containing_type || Object)
                super
            end
        end
        
        class Method
            attr_accessor :block
            def initialize(block)
                block.should_be_a(Proc)
                @block = block
            end
        end
        
        class Configure < Method; end
        class Command < Method
            attr_accessor :regexp
            def initialize(regexp, block)
                super(block)
                regexp.should_be_a(Regexp)
                @regexp = regexp
            end
        end
        class Error < Method; end
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
martin-0.1.2 lib/martin/dsl.rb
martin-0.1.1 lib/martin/dsl.rb