Class: Como::RuleCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/como.rb

Overview

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

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (RuleCheck) initialize(opt, &rule)

A new instance of RuleCheck



1863
1864
1865
# File 'lib/como.rb', line 1863

def initialize( opt, &rule )
    @opt = opt
end

Class Method Details

+ (Object) check(opt, &rule)



1858
1859
1860
1861
# File 'lib/como.rb', line 1858

def RuleCheck.check( opt, &rule )
    rc = RuleCheck.new( opt )
    rc.instance_eval( &rule )
end

Instance Method Details

- (Object) all(*args)

All are given.



1925
1926
1927
# File 'lib/como.rb', line 1925

def all( *args )
    getScore( *args ) == args.length
end

- (Object) any(*args)

At least one is given.



1920
1921
1922
# File 'lib/como.rb', line 1920

def any( *args )
    getScore( *args ) > 0
end

- (Object) follow(*args)

Incremental options in order i.e. have to have all later if had first.



1906
1907
1908
1909
1910
1911
1912
# File 'lib/como.rb', line 1906

def follow( *args )
    if getScore( args[0] )
        getScore( *args ) == args.length
    else
        true
    end
end

- (Object) getScore(*args)

Get given count.



1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
# File 'lib/como.rb', line 1869

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

- (Object) incr(*args)

Incremental options in order i.e. have to have previous to have later.



1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
# File 'lib/como.rb', line 1888

def incr( *args )
    had = 0
    add = true
    scoreAll = 0
    i = 0
    while args[i]
        score = getScore( args[i] )
        had += 1 if ( score == 1 ) && add
        add = false if ( score == 0 )
        scoreAll += score
        i += 1
    end

    ( had == scoreAll && had > 0 )
end

- (Object) inv(*args)

Logical inversion.



1930
1931
1932
# File 'lib/como.rb', line 1930

def inv( *args )
    getScore( *args ) == 0
end

- (Object) meh(*args)

Dont care.



1935
1936
1937
# File 'lib/como.rb', line 1935

def meh( *args )
    true
end

- (Object) none

Special condition when no options are given.



1882
1883
1884
# File 'lib/como.rb', line 1882

def none
    @opt.givenCount == 0
end

- (Object) one(*args)

One of list given.



1915
1916
1917
# File 'lib/como.rb', line 1915

def one( *args )
    getScore( *args ) == 1
end