Class: Optout::Validator::File

Inherits:
Base
  • Object
show all
Defined in:
lib/optout.rb

Direct Known Subclasses

Dir

Constant Summary

RULES =
%w|under named permissions|;
MODES =
{ "x" => :executable?, "r" => :readable?, "w" => :writable? }

Instance Attribute Summary

Attributes inherited from Base

#setting

Instance Method Summary (collapse)

Instance Method Details

- (Object) exists(wanted = true)



563
564
565
566
# File 'lib/optout.rb', line 563

def exists(wanted = true)
  @exists = wanted
  self
end

- (Object) validate!(opt)

Raises:



568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
# File 'lib/optout.rb', line 568

def validate!(opt)
  return if opt.empty?

  @file = Pathname.new(opt.value.to_s)
  what  = self.class.name.split("::")[-1].downcase
  error = case
          when !under?
            "#{what} must be under '#{@under}'"
          when !named?
            "#{what} name must match '#{@named}'"
          when !permissions?
            "#{what} must have user permission of #{@permissions}"
          when !exists?
            "#{what} '#{@file}' does not exist"
          when !creatable?
            # TODO: Why can't it be created!?
            "can't create a #{what} at '#{@file}'"
          end
  raise OptionInvalid.new(opt.key, error) if error
end