Sha256: 3d4f5d8ecb5321fbf8a378543407c8dea3c7d586171edeba83638909c0171598
Contents?: true
Size: 673 Bytes
Versions: 4
Compression:
Stored size: 673 Bytes
Contents
module Validatable module Requireable #:nodoc: module ClassMethods def requires(*args) required_options.concat args end def required_options @required_options ||= [] end end def self.included(klass) klass.extend ClassMethods end def requires(options) required_options = self.class.required_options.inject([]) do |errors, attribute| errors << attribute.to_s unless options.has_key?(attribute) errors end raise ArgumentError.new("#{self.class} requires options: #{required_options.join(', ')}") if required_options.any? true end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
validatable-1.3.4 | lib/requireable.rb |
validatable-1.3.0 | lib/requireable.rb |
validatable-1.4.0 | lib/requireable.rb |
validatable-1.3.2 | lib/requireable.rb |