class Como::RuleCheck
Set of methods which represent option combination checking. In effect this is a meta language (DSL) for option combinations.
Example:
RuleCheck.check( opt ) do one( incr( "gcov", "exclude", "refreshed" ), "manifest", "pairs", "files" ) end
Public Class Methods
check( opt, &rule )
click to toggle source
Perform rule checking options.
@param opt [Object] Options to check. @yield rule Checking conditions.
# File lib/como.rb, line 2242 def RuleCheck.check( opt, &rule ) rc = RuleCheck.new( opt ) rc.instance_eval( &rule ) end
new( opt, &rule )
click to toggle source
Build Rule checker.
# File lib/como.rb, line 2249 def initialize( opt, &rule ) @opt = opt end
Public Instance Methods
all( *args )
click to toggle source
All are given.
# File lib/como.rb, line 2327 def all( *args ) getScore( *args ) == args.length end
any( *args )
click to toggle source
At least one is given.
# File lib/como.rb, line 2322 def any( *args ) getScore( *args ) > 0 end
follow( *args )
click to toggle source
Incremental options in order i.e. have to have all later if had first.
# File lib/como.rb, line 2308 def follow( *args ) if getScore( args[0] ) getScore( *args ) == args.length else false end end
getScore( *args )
click to toggle source
Get given count.
# File lib/como.rb, line 2255 def getScore( *args ) score = 0 args.each do |i| if i.class == TrueClass || i.class == FalseClass score += 1 if i else score += 1 if @opt.argById(i).given end end score end
incr( *args )
click to toggle source
Incremental options in order i.e. have to have previous to have later.
# File lib/como.rb, line 2276 def incr( *args ) # Opts given consecutive. consecutiveCnt = 0 # Consecutive flag. consecutive = true # All given opts. givenCnt = 0 i = 0 while args[i] score = getScore( args[i] ) # Still consecutive. consecutiveCnt += 1 if ( score == 1 ) && consecutive # No more consecutives. consecutive = false if ( score == 0 ) # Count all given. givenCnt += score i += 1 end ( consecutiveCnt == givenCnt ) && ( givenCnt > 0 ) end
inv( *args )
click to toggle source
Logical inversion.
# File lib/como.rb, line 2332 def inv( *args ) getScore( *args ) == 0 end
meh( *args )
click to toggle source
Dont care.
# File lib/como.rb, line 2337 def meh( *args ) true end
none()
click to toggle source
Special condition when no options are given.
# File lib/como.rb, line 2270 def none @opt.givenCount == 0 end
one( *args )
click to toggle source
One of list given.
# File lib/como.rb, line 2317 def one( *args ) getScore( *args ) == 1 end