Sha256: 2171fe799625aa40792958dcb5c0c52f4a4b81407be959916a12ca73b55b270d

Contents?: true

Size: 1.88 KB

Versions: 12

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

# MIT License
#
# Copyright (c) 2024 Zerocracy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'loog'
require 'judges'
require 'factbase'
require 'factbase/looged'
require 'factbase/pre'
require 'factbase/rules'
require_relative '../fbe'

def Fbe.fb(fb: $fb, global: $global, options: $options, loog: $loog)
  global[:fb] ||=
    begin
      rules = Dir.glob(File.join('rules', '*.fe')).map { |f| File.read(f) }
      fbe = Factbase::Rules.new(
        fb,
        "(and \n#{rules.join("\n")}\n)",
        uid: '_id'
      )
      fbe =
        Factbase::Pre.new(fbe) do |f|
          max = fb.query('(eq _id (max _id))').each.to_a.first
          f._id = (max.nil? ? 0 : max._id) + 1
          f._time = Time.now
          f._version = "#{Factbase::VERSION}/#{Judges::VERSION}/#{options.judges_action_version}"
        end
      Factbase::Looged.new(fbe, loog)
    end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
fbe-0.0.47 lib/fbe/fb.rb
fbe-0.0.46 lib/fbe/fb.rb
fbe-0.0.45 lib/fbe/fb.rb
fbe-0.0.44 lib/fbe/fb.rb
fbe-0.0.43 lib/fbe/fb.rb
fbe-0.0.42 lib/fbe/fb.rb
fbe-0.0.41 lib/fbe/fb.rb
fbe-0.0.40 lib/fbe/fb.rb
fbe-0.0.39 lib/fbe/fb.rb
fbe-0.0.38 lib/fbe/fb.rb
fbe-0.0.37 lib/fbe/fb.rb
fbe-0.0.36 lib/fbe/fb.rb