Sha256: f66e22642dde2e7a5410f90d117fcde2aaf9f78f898cc9d4751686aa5a1038a9
Contents?: true
Size: 1.62 KB
Versions: 1
Compression:
Stored size: 1.62 KB
Contents
module Checked class Demand class Arrays include Demand::Base namespace '/array!' before def validate_target_class fail! "...is not an Array." unless array?(target) end route def no_nils! if target.include?(nil) fail!("...can't contain nils.") end end route def no_empty_strings! target.each { |s| if s.respond_to?(:rewind) s.rewind end final = if s.respond_to?(:readlines) s.readlines else s end if !final.is_a?(::String) fail!("Array contains unknown class: #{final.inspect}") end if final.is_a?(String) && final.strip.empty? fail!("...can't contain empty strings.") end } end route def symbols! not_empty! if !target.all? { |v| v.is_a?(Symbol) } fail! "...contains a non-symbol." end end route def include! return true if target.include?(matcher) fail!("...must contain: #{matcher.inspect}") end route def exclude! raise_e = val.include?(matcher) return true unless raise_e fail!("...can't contain #{matcher.inspect}") end route def matches_only! arr = target.reject { |val| val == matcher } fail!( "...invalid elements: #{arr.inspect}" ) if !arr.empty? end private end # === class Arrays 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/Arrays.rb |