Sha256: b8718bdf996ad2165ff212a2744acd30a0bd7dfdc89d9c742beaee8220650e08
Contents?: true
Size: 1.35 KB
Versions: 1
Compression:
Stored size: 1.35 KB
Contents
module Trigga module ParamFu def self.included(base) base.extend(ClassMethods) base.send(:include, InstanceMethods) end module ClassMethods def require_obj_or_id(opts, key) obj_or_id(opts,key) raise ArgumentError.new("#{key} or #{key_with_id(key)} are required") unless opts[key_with_id(key)] opts end def require_param(opts, *keys) keys.to_a.each do |k| raise ArgumentError.new("#{k} is required") unless opts[k] end opts end def obj_or_id(opts, key) opts[key_with_id(key)] ||= opts[key].id if opts[key] end def key_with_id(key) (key.to_s + '_id').to_sym end def require_one_of( opts, *keys ) present = (opts.keys & keys) raise ArgumentError.new( "at least one of the arguments #{keys.inspect} is required" ) if present.empty? return present end end module InstanceMethods def require_obj_or_id(opts,key) self.class.require_obj_or_id(opts, key) end def obj_or_id(opts, key) self.class.obj_or_id(opts, key) end def require_param(opts, *keys) self.class.require_param(opts, *keys) end def require_one_of( opts, *keys ) self.class.require_one_of( opts, *keys ) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
itrigga-param_fu-0.0.1 | lib/trigga/param_fu/param_fu.rb |