icentris-rules 0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +33 -0
  5. data/app/assets/images/pyr_rules/ui-anim_basic_16x16.gif +0 -0
  6. data/app/assets/javascripts/pyr_rules/rules.js +135 -0
  7. data/app/assets/stylesheets/pyr_rules/rules.css.scss +258 -0
  8. data/app/assets/stylesheets/scaffold.css +57 -0
  9. data/app/controllers/pyr_rules/actions_controller.rb +22 -0
  10. data/app/controllers/pyr_rules/events_controller.rb +17 -0
  11. data/app/controllers/pyr_rules/rules_controller.rb +233 -0
  12. data/app/helpers/pyr_rules/actions_helper.rb +2 -0
  13. data/app/helpers/pyr_rules/events_helper.rb +95 -0
  14. data/app/helpers/pyr_rules/rules_helper.rb +10 -0
  15. data/app/models/pyr_rules.rb +3 -0
  16. data/app/models/pyr_rules/action.rb +116 -0
  17. data/app/models/pyr_rules/rule.rb +201 -0
  18. data/app/rules/pyr_rules/action_handler.rb +94 -0
  19. data/app/rules/pyr_rules/controller_event_emitter.rb +34 -0
  20. data/app/rules/pyr_rules/email_action_handler.rb +6 -0
  21. data/app/rules/pyr_rules/event_concerns.rb +23 -0
  22. data/app/rules/pyr_rules/event_config_loader.rb +97 -0
  23. data/app/rules/pyr_rules/event_subscriber.rb +36 -0
  24. data/app/rules/pyr_rules/model_creation_handler.rb +25 -0
  25. data/app/rules/pyr_rules/model_event_emitter.rb +80 -0
  26. data/app/rules/pyr_rules/rule_context.rb +20 -0
  27. data/app/rules/pyr_rules/rules_config.rb +87 -0
  28. data/app/rules/pyr_rules/rules_engine.rb +38 -0
  29. data/app/rules/pyr_rules/web_request_logger.rb +6 -0
  30. data/app/views/pyr_rules/actions/index.html.erb +12 -0
  31. data/app/views/pyr_rules/events/_sidebar.html.erb +8 -0
  32. data/app/views/pyr_rules/events/index.html.erb +72 -0
  33. data/app/views/pyr_rules/events/show.html.erb +11 -0
  34. data/app/views/pyr_rules/rules/_form.html.erb +28 -0
  35. data/app/views/pyr_rules/rules/_ready_headers.js.erb +11 -0
  36. data/app/views/pyr_rules/rules/_rule_context_field.html.erb +10 -0
  37. data/app/views/pyr_rules/rules/_rules.html.erb +34 -0
  38. data/app/views/pyr_rules/rules/add_action_mapping.js.erb +13 -0
  39. data/app/views/pyr_rules/rules/edit.html.erb +14 -0
  40. data/app/views/pyr_rules/rules/index.html.erb +5 -0
  41. data/app/views/pyr_rules/rules/lookup_sub_properties.js.erb +13 -0
  42. data/app/views/pyr_rules/rules/new.html.erb +11 -0
  43. data/app/views/pyr_rules/rules/remove_action_mapping.js.erb +15 -0
  44. data/app/views/pyr_rules/rules/show.html.erb +98 -0
  45. data/app/views/shared/_action.html.erb +41 -0
  46. data/app/views/shared/_action_field_mapping.html.erb +33 -0
  47. data/app/views/shared/_event.html.erb +21 -0
  48. data/app/views/shared/_rule.html.erb +27 -0
  49. data/config/routes.rb +32 -0
  50. data/config/security.yml +9 -0
  51. data/db/seeds.rb +1 -0
  52. data/lib/pyr_rules.rb +34 -0
  53. data/lib/pyr_rules/engine.rb +72 -0
  54. data/lib/pyr_rules/generators/dummy_generator.rb +27 -0
  55. data/lib/pyr_rules/version.rb +3 -0
  56. data/lib/tasks/pyr_rules_tasks.rake +57 -0
  57. metadata +224 -0
@@ -0,0 +1,27 @@
1
+ <div class="rules-widget" style="width:100%;">
2
+ <%= simple_form_for @pyr_rules_rule do %>
3
+ <% if rule.name %>
4
+ <div id="rule_title_<%= rule.id.to_s %>" class="title <%= "ready" if rule.ready? %>"><%= rule.name.titleize %></div>
5
+ <% else %>
6
+ <div class="title "><input type="text" name="pyr_rules_rule[name]" value="<%= rule.name.titleize %>"/></div>
7
+ <% end %>
8
+ <div class="text-area">
9
+ <div class="name">Conditional Criteria</div>
10
+ <textarea name="pyr_rules_rule[criteria]" class="criteria" placeholder="Enter rule criteria logic here..."><%= rule.criteria %></textarea>
11
+ <input type="submit" class="action-links btn btn-mini btn-primary" value="save"/>
12
+ </div>
13
+ <% end %>
14
+ <% context = rule.context %>
15
+ <% if context %>
16
+ <div class="collapse-group">
17
+ <a class="collapse-context" data-toggle='collapse' data-target='#rule_context_<%= rule.id %>'>Context</a>
18
+ <div id="rule_context_<%= rule.id %>" class="collapse in">
19
+ <% if context %>
20
+ <% context.each do |field, type| %>
21
+ <%= render 'pyr_rules/rules/rule_context_field', path: field, rule: rule, field: field, type: type %>
22
+ <% end %>
23
+ <% end %>
24
+ </div>
25
+ </div>
26
+ <% end %>
27
+ </div>
@@ -0,0 +1,32 @@
1
+ Rails.application.routes.draw do
2
+ namespace :pyr_rules do
3
+
4
+ resources :actions
5
+
6
+ resources :rules do
7
+ resources :actions
8
+ collection do
9
+ get :lookup_events
10
+ get :lookup_actions
11
+ get :lookup_sub_properties, defaults: {format: :js}
12
+ get :reload_rules_engine
13
+ end
14
+ member do
15
+ get :add_event
16
+ get :add_action
17
+ get :remove_event
18
+ get :remove_action
19
+ get :add_action_mapping
20
+ get :remove_action_mapping
21
+ end
22
+ end
23
+
24
+ resources :events, :only => [:index, :show] do
25
+ resources :rules do
26
+ resources :actions
27
+ end
28
+ end
29
+
30
+ # match "/events", to: "rules#events", as: "events"
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ roles:
2
+ rules_admin:
3
+ permissions:
4
+ - "pyr_rules*"
5
+
6
+ groups:
7
+ admin:
8
+ roles:
9
+ - rules_admin
@@ -0,0 +1 @@
1
+ # see pyr_rules_tasks.rake
@@ -0,0 +1,34 @@
1
+ require "pyr_rules/engine"
2
+
3
+ module PyrRules
4
+
5
+ mattr_accessor :table_name_prefix
6
+ @@table_name_prefix = "pyr_"
7
+
8
+ mattr_accessor :trash_icon
9
+ @@trash_icon = "icon-trash" # fa fa-trash-o
10
+
11
+ mattr_accessor :delete_icon
12
+ @@delete_icon = "icon-remove" # fa fa-times-circle-o
13
+
14
+ mattr_accessor :arrow_icon
15
+ @@arrow_icon = "icon-arrow-right" # fa fa-arrow-right
16
+
17
+ mattr_accessor :lookup_icon
18
+ @@lookup_icon = "icon-search" # fa fa-search
19
+
20
+ # Should we automatically stitch ModelEventEmitter into ActiveRecord::Base
21
+ mattr_accessor :active_record
22
+ @@active_record = true
23
+
24
+ # If you are using non-standard table mappings (if you use table_name_prefix), then you may
25
+ # need to actively load your classes here
26
+ mattr_accessor :development_model_paths
27
+ @@development_model_paths = []
28
+
29
+ # Default way to setup Rules
30
+ def self.setup
31
+ yield self
32
+ end
33
+
34
+ end
@@ -0,0 +1,72 @@
1
+ puts "Loading PyrRules::Engine"
2
+
3
+ module PyrRules
4
+ class Engine < ::Rails::Engine
5
+
6
+
7
+ config.generators do |g|
8
+
9
+ g.test_framework :rspec
10
+ # g.test_framework :rspec,
11
+ # fixtures: false,
12
+ # view_specs: true,
13
+ # helper_specs: true,
14
+ # routing_specs: true,
15
+ # controller_specs: true,
16
+ # request_specs: true
17
+ # g.fixture_replacement :factory_girl, :dir => "spec/factories"
18
+
19
+ # g.orm :active_record
20
+ g.orm :mongoid
21
+ end
22
+
23
+ config.generators.scaffold_controller = :scaffold_controller
24
+
25
+ rules_engine = self
26
+
27
+ initializer "before_#{self.name.underscore}_initializers1", after: :prepend_helpers_path, before: :load_config_initializers do |app|
28
+ puts "------------------------------------------------------------#{rules_engine.name} - I am CONFIG.AFTER HELPERS ------------------------------------------------------------"
29
+ rules_engine.load_extensions
30
+ end
31
+
32
+
33
+ config.to_prepare do |action_dispatcher|
34
+ # More importantly, will run upon every request in development, but only once (during boot-up) in production and test.
35
+ puts "------------------------------------------------------------4:#{rules_engine.name} - I am CONFIG.TO_PREPARE ------------------------------------------------------------"
36
+ puts "------------------------------------------------------------Done with all initializers (from all engines, railties and application. including the initializer files under config/initializers)"
37
+
38
+ if Rails.application.initialized?
39
+ rules_engine.load_extensions
40
+ end
41
+ end
42
+
43
+ def load_extensions
44
+ puts "\n--- Loading lib/pyr_rules for #{self.class.name} "
45
+ Dir.glob("#{self.root}/lib/#{self.class.name.underscore.split("/")[0]}/extensions/**/*.rb").sort.each do |entry|
46
+
47
+ puts "Reloading extension: #{entry}"
48
+ require_dependency "#{entry}"
49
+ end
50
+
51
+ # Dir.glob("#{self.root}/lib/#{self.class.name.split('::').first}/**/*.rb").sort.each do |entry|
52
+ # next if entry.end_with?("version.rb") || entry.end_with?("engine.rb")
53
+ # puts "Reloading lib: #{entry}"
54
+ # require_dependency "#{entry}"
55
+ # end
56
+
57
+ Dir.glob("#{self.root}/app/models/pyr_rules/**/*.rb").sort.each do |entry|
58
+ next if entry.end_with? "version.rb"
59
+ puts "Reloading models: #{entry}"
60
+ require_dependency "#{entry}"
61
+ end
62
+
63
+ Dir.glob("#{self.root}/app/rules/pyr_rules/**/*.rb").sort.each do |entry|
64
+ next if entry.end_with? "version.rb"
65
+ puts "Reloading rules: #{entry}"
66
+ require_dependency "#{entry}"
67
+ end
68
+ puts "--- Loaded lib/pyr_rules for #{self.class.name} \n"
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,27 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/rails/plugin_new/plugin_new_generator'
3
+
4
+ module MyEngine
5
+ class DummyGenerator < Rails::Generators::PluginNewGenerator
6
+
7
+ def self.default_source_root
8
+ Rails::Generators::PluginNewGenerator.default_source_root
9
+ end
10
+
11
+ def do_nothing
12
+ end
13
+
14
+ alias :create_root :do_nothing
15
+ alias :create_root_files :do_nothing
16
+ alias :create_app_files :do_nothing
17
+ alias :create_config_files :do_nothing
18
+ alias :create_lib_files :do_nothing
19
+ alias :create_public_stylesheets_files :do_nothing
20
+ alias :create_javascript_files :do_nothing
21
+ alias :create_script_files :do_nothing
22
+ alias :update_gemfile :do_nothing
23
+ alias :create_test_files :do_nothing
24
+ alias :finish_template :do_nothing
25
+
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module PyrRules
2
+ VERSION = 0.9
3
+ end
@@ -0,0 +1,57 @@
1
+ # desc "Explaining what the task does"
2
+ # task :pyr_rules do
3
+ # # Task goes here
4
+ # end
5
+ namespace :pyr do
6
+
7
+ desc "Set the Rules Engine configuration"
8
+ task :rules => :environment do
9
+ puts "Clean slate activated - deleting existing rules..."
10
+ PyrRules::RulesConfig.delete_rules
11
+
12
+
13
+ PyrRules::RulesConfig.add_rule({name:"New Lead Business Alert",
14
+ event_inclusion: /PyrCrm::Contact::create/,
15
+ criteria: "target.lead?",
16
+ action_configs: [
17
+ {title: "Business Feed", type: PyrCore::ActionHandler::Notification,
18
+ context_mapping: { "recipient:messaging_user" => "target.user:user"}},
19
+ {title: "Mobile Alert", type: PyrCore::ActionHandler::MobileAlertAutoDialer,
20
+ context_mapping: { "recipient:messaging_user" => "target.user:user",
21
+ "phone_number:string" => "target.phone:string"},
22
+ template: { subject: 'You have a new lead: #{first_name} #{last_name}',
23
+ body: "Call them and talk, try to act natural - Don't be shy!!!"
24
+ }
25
+ }
26
+ ]})
27
+
28
+ PyrRules::RulesConfig.add_rule({name:"Community Resource Activity Stream",
29
+ event_inclusion: /(?!.*Chat)(?!.*Controller)(?!.*Activity)(?!.*Abuse)(?!.*Visibility)PyrCommunity::.*::create/,
30
+ event_exclusion: /PyrCommunity::Post.*/ ,
31
+ action_configs: [{title: "Activity Feed", type: PyrCore::ActionHandler::ActivityStream}]})
32
+
33
+
34
+ PyrRules::RulesConfig.add_rule({name:"Blog Post Activity Stream",
35
+ event_inclusion: /(?!.*Controller)PyrCommunity::Post/,
36
+ criteria: "data['published'] == true",
37
+ action_configs: [{title: "Activity Feed", type: PyrCore::ActionHandler::ActivityStream}]})
38
+
39
+
40
+ PyrRules::RulesConfig.add_rule({name:"CRM Resource Activity Stream",
41
+ event_inclusion: /PyrCrm::Contact::create|PyrCrm::Event::create/,
42
+ criteria: "!(target.class == PyrCrm::Contact && target.lead?)",
43
+ action_configs: [{title: "Activity Feed", type: PyrCore::ActionHandler::ActivityStream}]})
44
+
45
+ PyrRules::RulesConfig.add_rule({name:"Request Completed",
46
+ event_inclusion: /Controller/,
47
+ action_configs: [{title: "Log Request Completed", type: PyrRules::WebRequestLogger}]})
48
+
49
+
50
+ PyrRules::RulesConfig.add_rule({name:"New Followers Activity Stream",
51
+ event_inclusion: /Follow::create/,
52
+ action_configs: [{title: "Activity Feed", type: PyrCore::ActionHandler::ActivityStream}]})
53
+
54
+
55
+
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,224 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: icentris-rules
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.9'
5
+ platform: ruby
6
+ authors:
7
+ - Vijay K, Darren H
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: protected_attributes
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jquery-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jquery-ui-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mongoid
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '4'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mongoid-versioning
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '2.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '2.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sqlite3
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Pyr Rules Engine
140
+ email:
141
+ - vijay.koppala@icentris.com, darren.hicks@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - app/helpers/pyr_rules/rules_helper.rb
147
+ - app/helpers/pyr_rules/events_helper.rb
148
+ - app/helpers/pyr_rules/actions_helper.rb
149
+ - app/assets/javascripts/pyr_rules/rules.js
150
+ - app/assets/stylesheets/scaffold.css
151
+ - app/assets/stylesheets/pyr_rules/rules.css.scss
152
+ - app/assets/images/pyr_rules/ui-anim_basic_16x16.gif
153
+ - app/views/shared/_rule.html.erb
154
+ - app/views/shared/_action_field_mapping.html.erb
155
+ - app/views/shared/_event.html.erb
156
+ - app/views/shared/_action.html.erb
157
+ - app/views/pyr_rules/events/index.html.erb
158
+ - app/views/pyr_rules/events/_sidebar.html.erb
159
+ - app/views/pyr_rules/events/show.html.erb
160
+ - app/views/pyr_rules/rules/add_action_mapping.js.erb
161
+ - app/views/pyr_rules/rules/_form.html.erb
162
+ - app/views/pyr_rules/rules/lookup_sub_properties.js.erb
163
+ - app/views/pyr_rules/rules/_rules.html.erb
164
+ - app/views/pyr_rules/rules/remove_action_mapping.js.erb
165
+ - app/views/pyr_rules/rules/_ready_headers.js.erb
166
+ - app/views/pyr_rules/rules/_rule_context_field.html.erb
167
+ - app/views/pyr_rules/rules/new.html.erb
168
+ - app/views/pyr_rules/rules/index.html.erb
169
+ - app/views/pyr_rules/rules/edit.html.erb
170
+ - app/views/pyr_rules/rules/show.html.erb
171
+ - app/views/pyr_rules/actions/index.html.erb
172
+ - app/models/pyr_rules.rb
173
+ - app/models/pyr_rules/action.rb
174
+ - app/models/pyr_rules/rule.rb
175
+ - app/controllers/pyr_rules/events_controller.rb
176
+ - app/controllers/pyr_rules/actions_controller.rb
177
+ - app/controllers/pyr_rules/rules_controller.rb
178
+ - app/rules/pyr_rules/event_subscriber.rb
179
+ - app/rules/pyr_rules/action_handler.rb
180
+ - app/rules/pyr_rules/model_event_emitter.rb
181
+ - app/rules/pyr_rules/model_creation_handler.rb
182
+ - app/rules/pyr_rules/web_request_logger.rb
183
+ - app/rules/pyr_rules/controller_event_emitter.rb
184
+ - app/rules/pyr_rules/rules_config.rb
185
+ - app/rules/pyr_rules/rules_engine.rb
186
+ - app/rules/pyr_rules/email_action_handler.rb
187
+ - app/rules/pyr_rules/rule_context.rb
188
+ - app/rules/pyr_rules/event_concerns.rb
189
+ - app/rules/pyr_rules/event_config_loader.rb
190
+ - config/routes.rb
191
+ - config/security.yml
192
+ - db/seeds.rb
193
+ - lib/tasks/pyr_rules_tasks.rake
194
+ - lib/pyr_rules.rb
195
+ - lib/pyr_rules/version.rb
196
+ - lib/pyr_rules/engine.rb
197
+ - lib/pyr_rules/generators/dummy_generator.rb
198
+ - MIT-LICENSE
199
+ - Rakefile
200
+ - README.rdoc
201
+ homepage: http://www.icentris.com
202
+ licenses: []
203
+ metadata: {}
204
+ post_install_message:
205
+ rdoc_options: []
206
+ require_paths:
207
+ - lib
208
+ required_ruby_version: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ! '>='
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
213
+ required_rubygems_version: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - ! '>='
216
+ - !ruby/object:Gem::Version
217
+ version: '0'
218
+ requirements: []
219
+ rubyforge_project:
220
+ rubygems_version: 2.1.10
221
+ signing_key:
222
+ specification_version: 4
223
+ summary: Pyr Rules Engine
224
+ test_files: []