Class: Optout::Validator::File

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

Direct Known Subclasses

Dir

Constant Summary collapse

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

#exists(wanted = true) ⇒ Object



591
592
593
594
# File 'lib/optout.rb', line 591

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

#validate!(opt) ⇒ Object

Raises:



596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
# File 'lib/optout.rb', line 596

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