Sha256: d955b58c01bc75ba60a4d1c4f4a042b394e58b3502bd9a3617f1d7146b3d4fc3

Contents?: true

Size: 910 Bytes

Versions: 1

Compression:

Stored size: 910 Bytes

Contents


module Checked
  class Demand

    Failed = Class.new(RuntimeError)
    
    module Base
      
      include Checked::Base
        
      route "/!w!!/check!/"
      def check!
        # do nothing
      end
    
      def err_msg msg = "...is invalid."
        message = if msg.strip[ %r!^\.\.\.! ]
                    msg.sub('...', '').strip
                  else
                    msg
                  end
      
        @err_msg || "#{target_name}, #{original_target.inspect}, #{message}"
      end

      def err_msg= msg
        demand! msg, :string!, :not_empty!
        @err_msg = msg
      end
      
      private # ==========================================

      def fail! msg
        raise Failed, err_msg(msg)
      end

    end # === module Base
    
    def initialize *args
      raise "Demand not allowed to be used."
    end
    
  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/Demand.rb