Sha256: 6477c0fa3ad245851bd4848f83d93ee1d53fdec702c76d3f30c5b26ab2c8ac59

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 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 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

2 entries across 2 versions & 1 rubygems

Version Path
Checked-1.2.3 lib/Checked/Demand/File_Paths.rb
Checked-1.2.2 lib/Checked/Demand/File_Paths.rb