class Fbe::Conclude

License
MIT
Copyright
Copyright © 2024-2025 Zerocracy
Author

Yegor Bugayenko (yegor256@gmail.com)
new facts, letting the block in the {Fbe::Conclude#draw} deal with them.
This snippet will find all facts that have bad property and then create
end
end
n.good = ‘yes!’
draw on |n, b|
follow ‘when’
on ‘(exist bad)’
conclude do
require ‘fbe/conclude’
For example, you want to make a new good fact for every bad fact found:
and possibly creating new facts from them.
of facts in the factbase, applying certain algorithm to each of them
You may want to use this class when you want to go through a number
A concluding block.

def consider(&)

Returns:
  • (Integer) - The count of the facts processed

Other tags:
    Yield: - The next fact found by the query
def consider(&)
  roll do |_fbt, a|
    yield a
    nil
  end
end

def draw(&)

Returns:
  • (Integer) - The count of the facts processed

Other tags:
    Yield: - New fact and seen fact
def draw(&)
  roll do |fbt, a|
    n = fbt.insert
    fill(n, a, &)
    n
  end
end

def fill(fact, prev)

Returns:
  • (nil) -

Other tags:
    Yield: - New fact and the previous fact

Parameters:
  • prev (Factbase::Fact) -- The previous fact to copy from
  • fact (Factbase::Fact) -- The fact to populate
def fill(fact, prev)
  @follows.each do |follow|
    v = prev.send(follow)
    fact.send(:"#{follow}=", v)
  end
  r = yield fact, prev
  return unless r.is_a?(String)
  fact.details = r
  fact.what = @judge
end

def follow(props)

Returns:
  • (nil) - Nothing

Parameters:
  • props (Array) -- List of property names
def follow(props)
  @follows = props.strip.split.compact
end

def initialize(fb:, judge:, global:, options:, loog:)

Parameters:
  • loog (Loog) -- The logging facility
  • options (Judges::Options) -- The options coming from the +judges+ tool
  • global (Hash) -- The hash for global caching
  • judge (String) -- The name of the judge, from the +judges+ tool
  • fb (Factbase) -- The factbase
def initialize(fb:, judge:, global:, options:, loog:)
  @fb = fb
  @judge = judge
  @loog = loog
  @options = options
  @global = global
  @query = nil
  @follows = []
  @quota_aware = false
  @timeout = 60
end

def on(query)

Returns:
  • (nil) - Nothing is returned

Parameters:
  • query (String) -- The query to execute
def on(query)
  raise 'Query is already set' unless @query.nil?
  @query = query
end

def quota_aware

Returns:
  • (nil) - Nothing is returned
def quota_aware
  @quota_aware = true
end

def roll(&)

Returns:
  • (Integer) - The count of facts processed

Other tags:
    Yield: - Transaction and the matching fact
def roll(&)
  passed = 0
  start = Time.now
  oct = Fbe.octo(loog: @loog, options: @options, global: @global)
  @fb.txn do |fbt|
    fbt.query(@query).each do |a|
      if @quota_aware && oct.off_quota
        @loog.debug('We ran out of GitHub quota, must stop here')
        throw :commit
      end
      if Time.now > start + @timeout
        @loog.debug("We've spent more than #{start.ago}, must stop here")
        throw :commit
      end
      n = yield fbt, a
      @loog.info("#{n.what}: #{n.details}") unless n.nil?
      passed += 1
    end
  end
  @loog.debug("Found and processed #{passed} facts by: #{@query}")
  passed
end

def timeout(sec)

Returns:
  • (nil) - Nothing is returned

Parameters:
  • sec (Float) -- Seconds
def timeout(sec)
  @timeout = sec
end