Sha256: 9c81a74497cb19ac52d77c1327a9775fe3c1a87758934ad613e12bd884f99f72

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

module Checked
  class Demand
    class File_Paths
      
      include Uni_Arch::Base
      include Demand::Base
      namespace '/file_path!'
      
      route
      def check!
        fail!('...must be a String.') unless target.is_a?(String)
        
        strip_target
        not_empty!
        validate_format!
        expand_target if fs_path?
      end

      route
      def hostname!
        fail!("...has invalid characters: #{$1.inspect}") if target[ %r!([^\dA-Za-z_-]+)! ]
      end

      route
      def not_dir!
        if File.directory?(target)
          fail! "...can't be an existing directory."
        end
      end

      route
      def not_file!
        fail! "...can't be a file." if File.file?(target)
      end

      route
      def dir!
        fail! "...must be an existing directory." unless File.directory?(target)
      end

      private 

      def validate_format!
        if target[%r!([^a-zA-Z0-9\.\_\-\/~,]+)!]
          fail! "...has invalid characters: #{$1.inspect}"
        end
      end
      
      def expand_target
        request.response.body= File.expand_path(target)
      end

      # 
      # fs_path => File system object path
      # 
      def fs_path?
        request.path[%r!(_|/)(dir|file|check)[^a-zA-Z]+\Z!]
      end

    end # === class File_Addresses
  end # === class Demand
end # === module Checked

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
Checked-1.2.1 lib/Checked/Demand/File_Paths.rb
Checked-1.2.0 lib/Checked/Demand/File_Paths.rb
Checked-1.1.0 lib/Checked/Demand/File_Paths.rb