Sha256: 7f871a955b7075e1a9ad2ce42d60dcd7e70d2be3b0bdbcda5b767c295884d8d8

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

module Checked
  class Demand
    class Strings

      include Demand::Base

      namespace '/string!'
      
      before
      def validate
        case target
        when String
        when StringIO
          target.rewind
          request.response.body= target.readlines
          target.rewind
        else
          fail! "...must be a String or StringIO"
        end
      end

      route
      def include!
        included = target[matcher]
        return true if included
        fail!("...must contain: #{matcher.inspect}")
      end

      route
      def exclude! matcher
        raise_e = val[matcher]
        return true unless raise_e
        fail!("...can't contain #{matcher.inspect}")
      end

      route
      def matches_only!
        str = target.gsub(matcher, '')
        if !str.empty?
          fail!( "...has invalid characters: #{str.inspect}" ) 
        end
      end

      route
      def not_empty!
        if target.strip.empty? 
          fail!("...can't be empty.") 
        end
      end

      route
      def file_read!
        request.response.body= target.gsub("\r\n", "\n")
      end

      route
      def file_content! 
        not_empty!   
        file_read!
      end

    end # === class String
  end # === class Demand
end # === module Checked

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
Checked-1.0.0 lib/Checked/Demand/Strings.rb