Class: PyrRules::RuleContext

Inherits:
Object
  • Object
show all
Defined in:
app/rules/pyr_rules/rule_context.rb

Instance Method Summary collapse

Constructor Details

#initialize(event_hash, extras = {}) ⇒ RuleContext

Returns a new instance of RuleContext.



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/rules/pyr_rules/rule_context.rb', line 2

def initialize(event_hash, extras = {})
  event_hash.each do |key, value|
    define_singleton_method(key.to_sym) {value}
  end
  extras.each do |key, value|
    define_singleton_method(key.to_sym) {value}
  end
  define_singleton_method(:system) {:system_messaging_user}
  target = event_hash[:klazz].constantize.find event_hash[:id].to_i rescue nil
  actor = User.find event_hash[:user][:id].to_i rescue nil
  actor ||= target.try(:user) rescue nil
  define_singleton_method(:target) {target}
  define_singleton_method(:actor) {actor}
end

Instance Method Details

#get_bindingObject



16
17
18
# File 'app/rules/pyr_rules/rule_context.rb', line 16

def get_binding
  return binding
end