Sha256: 10209bae08fc081bd428ffbcf9ecd187d298118091904df2be768fc262a144ba

Contents?: true

Size: 817 Bytes

Versions: 47

Compression:

Stored size: 817 Bytes

Contents

module Validatable
  module Understandable #:nodoc:
    module ClassMethods #:nodoc:
      def understands(*args)
        understandings.concat args
      end

      def understandings
        @understandings ||= []
      end

      def all_understandings
        return understandings + self.superclass.all_understandings if self.superclass.respond_to? :all_understandings
        understandings
      end
    end

    def self.included(klass)
      klass.extend ClassMethods
    end

    def must_understand(hash)
      invalid_options = hash.inject([]) do |errors, (key, value)|
        errors << key.to_s unless self.class.all_understandings.include?(key)
        errors
      end
      raise ArgumentError.new("invalid options: #{invalid_options.join(', ')}") if invalid_options.any?
      true
    end
  end
end

Version data entries

47 entries across 47 versions & 13 rubygems

Version Path
jnunemaker-validatable-1.8.2 lib/validatable/understandable.rb
jnunemaker-validatable-1.1.10 lib/validatable/understandable.rb
jnunemaker-validatable-1.1.9 lib/validatable/understandable.rb
durran-validatable-2.0.1 lib/understandable.rb
durran-validatable-2.0.0 lib/understandable.rb
durran-validatable-1.8.4 lib/understandable.rb
durran-validatable-1.8.3 lib/understandable.rb
jnunemaker-validatable-1.8.1 lib/validatable/understandable.rb
durran-validatable-1.8.2 lib/understandable.rb
durran-validatable-1.8.1 lib/understandable.rb
durran-validatable-1.8.0 lib/understandable.rb
durran-validatable-1.7.5 lib/understandable.rb
jnunemaker-validatable-1.8.0 lib/validatable/understandable.rb
jnunemaker-validatable-1.7.4 lib/understandable.rb
jnunemaker-validatable-1.7.3 lib/understandable.rb
mack-notifier-0.8.2 lib/gems/validatable-1.6.7/lib/understandable.rb
mack-notifier-0.8.3 lib/gems/validatable-1.6.7/lib/understandable.rb
mack-notifier-0.8.3.1 lib/gems/validatable-1.6.7/lib/understandable.rb
validatable-1.5.0 lib/understandable.rb
validatable-1.6.3 lib/understandable.rb