## Ruby and Rails Rules Engine Framework # More detailed documentation at http://www.r3ef.com ## Installation Guide ###################################### # 1. Install the Gem sudo gem install rules_engine sudo gem install rspec cucumber ###################################### # 2. Create the Rails App rails MyCoolNewApp cd MyCoolNewApp rm ./public/index.html ./script/generate rspec ./script/generate cucumber --rspec ./script/generate rules_engine ###################################### # 3. Setup the Rails Environments - ./config/environment.rb Rails::Initializer.run do |config| ... config.gem 'rules_engine' config.gem 'will_paginate' config.gem 'acts_as_list' ... end - ./config/environments/production.rb - ./config/environments/development.rb RulesEngine::Cache.cache_store = :mem_cache_store, "localhost:11210" # RulesEngine::Cache.cache_store = :memory_store # RulesEngine::Cache.cache_store = :file_store, "/path/to/cache/directory" # RulesEngine::Cache.cache_store = :drb_store, "druby://localhost:9192" # RulesEngine::Cache.cache_store = :mem_cache_store, "localhost" # RulesEngine::Cache.cache_store = MyOwnStore.new("parameter") - ./config/environments/test.rb - ./config/environments/cucumber.rb config.gem "rspec", :version => '>=1.3.0', :lib => false config.gem "rspec-rails", :version => '>=1.3.2', :lib => false config.gem "faker", :version => '>=0.3.1', :lib => false config.gem "machinist", :version => '>=1.0.6', :lib => false config.gem 'rcov', :version => '>=0.9.8', :lib => false config.gem 'remarkable_rails', :version => '>=3.1.13', :lib => false require 'machinist/active_record' require 'sham' require 'faker' require 'remarkable_rails' ###################################### # 4. Add the Routes - ./config/routes.rb ActionController::Routing::Routes.draw do |map| ... ### remove map.root if already defined map.root :controller => :re_plans, :action => 'template' map.resources :re_plans, :member => {:change => :get, :preview => :get, :publish => :put, :revert => :put, :re_process => :get, :copy => :get, :duplicate => :post} do |re_map| re_map.resources :workflows, :controller => :re_plan_workflows, :except => [:index], :member => {:change => :get, :default => :put, :add => :put, :remove => :put, :copy => :get, :duplicate => :post} do |re_pipeline| re_pipeline.resources :rules, :controller => :re_plan_workflow_rules, :except => [:index, :show], :collection => {:help => :get, :error => :get}, :member => {:move_up => :put, :move_down => :put} end end map.resources :re_workflows, :collection => {:add => :get}, :member => {:plan => :get, :change => :get, :preview => :get, :copy => :get, :duplicate => :post} do |re_pipeline| re_pipeline.resources :rules, :controller => :re_workflow_rules, :except => [:index, :show], :collection => {:help => :get, :error => :get}, :member => {:move_up => :put, :move_down => :put} end map.resources :re_history, :only => [:index, :show] map.resources :re_publications, :only => [:show] ... ###################################### # 5. Define the Access Levels - ./app/controllers/application_controller.rb class ApplicationController < ActionController::Base helper_method :rules_engine_reader?, :rules_engine_editor? def rules_engine_reader? # why cookies[:rules_engine_reader] ? It's a workaround for cucumber testing return cookies[:rules_engine_reader].nil? ? true : cookies[:rules_engine_reader].downcase == 'true' end def rules_engine_editor? # why cookies[:rules_engine_editor] ? It's a workaround for cucumber testing return cookies[:rules_engine_editor].nil? ? true : cookies[:rules_engine_editor].downcase == 'true' end def rules_engine_reader_access_required unless rules_engine_reader? redirect_to(root_path) flash[:success] = 'Rules Engine Access Denied.' end end def rules_engine_editor_access_required unless rules_engine_editor? redirect_to(root_path) flash[:success] = 'Rules Engine Editor Access Denied.' end end ###################################### # 6. Install the Required Gems rake gems:install rake gems:install RAILS_ENV=test ###################################### # 7. Migrate the Database rake db:migrate rake db:migrate RAILS_ENV=test ###################################### # 8. Create a Simple Rule ./script/generate rules_engine simple does_nothing ###################################### # 9. Create a Complex Rule ./script/generate rules_engine complex match_words ###################################### # 10. Run the Tests rake spec rake spec:rcov rake cucumber open coverage/index.html ###################################### # 11. Start the Server ./script/server open http://localhost:3000/re_plans ###################################### # 12. Create Pipelines and Rules Watch the demo at "TODO":http://www.r3ef.com/