Class: Wongi::Engine::DSL::Rule

Inherits:
Object
  • Object
show all
Includes:
Generated
Defined in:
lib/wongi-engine/dsl/rule.rb

Direct Known Subclasses

NccSubrule, Query, VariantRule

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Generated

create_dsl_method

Constructor Details

#initialize(name) ⇒ Rule

Returns a new instance of Rule.



31
32
33
34
35
# File 'lib/wongi-engine/dsl/rule.rb', line 31

def initialize name
  @name = name
  @current_section = nil
    Rule.sections.each { |section| acceptors[section] ||= [] }
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/wongi-engine/dsl/rule.rb', line 5

def name
  @name
end

Class Method Details

.section(s, *aliases) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/wongi-engine/dsl/rule.rb', line 11

def section s, *aliases
  unless sections.include?(s)
    sections << s
    define_method s do |&d|
      @current_section = s
      instance_eval &d
    end
    aliases.each { |a| alias_method a, s }
  end
end

.sectionsObject



22
23
24
# File 'lib/wongi-engine/dsl/rule.rb', line 22

def sections
  @sections ||= []
end

Instance Method Details

#acceptorsObject



37
38
39
# File 'lib/wongi-engine/dsl/rule.rb', line 37

def acceptors
  @acceptors ||= {}
end

#actionsObject



49
50
51
# File 'lib/wongi-engine/dsl/rule.rb', line 49

def actions
  acceptors[:make] ||= []
end

#actions=(a) ⇒ Object



53
54
55
# File 'lib/wongi-engine/dsl/rule.rb', line 53

def actions= a
  acceptors[:make] = a
end

#conditionsObject



41
42
43
# File 'lib/wongi-engine/dsl/rule.rb', line 41

def conditions
  acceptors[:forall] ||= []
end

#conditions=(c) ⇒ Object



45
46
47
# File 'lib/wongi-engine/dsl/rule.rb', line 45

def conditions= c
  acceptors[:forall] = c
end

#import_into(rete) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/wongi-engine/dsl/rule.rb', line 57

def import_into rete
  self.class.new( @name ).tap do |copy|
    copy.conditions = conditions

    copy.actions = actions.map do |action|
      if action.respond_to? :import_into
        action.import_into(rete)
      else
        action
      end
    end
  end
end

#install(rete) ⇒ Object



71
72
73
# File 'lib/wongi-engine/dsl/rule.rb', line 71

def install( rete )
  rete.install_rule( self )
end