Sha256: d90698dc39b45de387c8efb82e2ac2e3154065dcd2afa1381543389a8cdb1424

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

require 'active_record'  
require 'rules_engine'

desc "run a rules engine plan"   
task :rules_engine do

  if ENV['re_plan'].blank?
    raise "usage: rake rules_engine re_plan=[plan code] re_param='[value]'"
  end    
        
  environment = ENV["RAILS_ENV"] || "development"

  dbconfig = YAML::load(File.open("#{File.dirname(__FILE__)}/../../config/database.yml"))[environment]    
  ActiveRecord::Base.establish_connection(dbconfig)
        
  RulesEngine::Publish.publisher = :db_publisher
  RulesEngine::Process.runner = :db_runner
  RulesEngine::Process.auditor = :db_auditor
  RulesEngine::Process.auditor.audit_level = RulesEngine::Process::AUDIT_INFO
  RulesEngine::Discovery.rules_path = File.expand_path(File.join(File.dirname(__FILE__), '/../../app/rules'))
  RulesEngine::Discovery.discover! 
  
  plan = RulesEngine::Publish.publisher.get(ENV['re_plan'])
  if plan.nil?
    raise "published plan \"ENV['re_plan']\" not found"
  end    
    
  data = ENV.inject({}){ |data, value| data[value[0].sub(/^re_/, '').to_sym] = value[1] if value[0] =~ /^re_/; data }  
  process_id = RulesEngine::Process.runner.create  
  success = RulesEngine::Process.runner.run(process_id, plan, data)
  
  # process = RulesEngine::Process.open(process.re_process.id)
      
  puts "plan #{success ? 'succeeded' : 'failed'} : process_id = #{process_id} : data = #{data.inspect}"
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rules_engine-0.1.6 rails_generators/templates/lib/tasks/rules_engine.rake
rules_engine-0.1.5 rails_generators/templates/lib/tasks/rules_engine.rake
rules_engine-0.1.4 rails_generators/templates/lib/tasks/rules_engine.rake
rules_engine-0.1.3 rails_generators/templates/lib/tasks/rules_engine.rake