module Factree::FactSource::ClassMethods

Public Instance Methods

def_fact(fact_name, &block) click to toggle source

Defines a named fact along with a block used to compute the fact's value.

@param [Symbol] fact_name The new fact's name

# File lib/factree/fact_source.rb, line 15
def def_fact(fact_name, &block)
  raise ArgumentError, "block required" unless block_given?

  all_fact_procs = fact_procs.merge(fact_name => block).freeze
  class_variable_set(:@@_fact_procs, all_fact_procs)
  fact_name
end
defined?(fact_name) click to toggle source

@return [Boolean] True if the fact has been defined (using {FactSource.def_fact})

# File lib/factree/fact_source.rb, line 36
def defined?(fact_name)
  fact_procs.include? fact_name
end
fact_names() click to toggle source

@return [Array<Symbol>] Names for all of the defined facts, whether their values are known or not.

# File lib/factree/fact_source.rb, line 24
def fact_names
  fact_procs.keys.freeze
end
fact_procs() click to toggle source

@api private

# File lib/factree/fact_source.rb, line 29
def fact_procs
  class_variable_defined?(:@@_fact_procs) ?
    class_variable_get(:@@_fact_procs) :
    {}.freeze
end