depalma 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +45 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/depalma.gemspec +43 -0
- data/lib/dispatch_rule.rb +19 -0
- data/lib/dispatch_unit.rb +27 -0
- data/lib/dispatcher.rb +51 -0
- metadata +61 -0
data/README.rdoc
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
== depalma
|
|
2
|
+
|
|
3
|
+
== Installation
|
|
4
|
+
|
|
5
|
+
== Usage
|
|
6
|
+
|
|
7
|
+
It's recommended that you inherit from the Dispatcher and DispatchRule classes and create your own. From there you can override the dispatch algorithm (or leave it alone). Even if you don't plan on overriding any methods you may want to at least override the Dispatcher.recall method. Which does nothing by default.
|
|
8
|
+
|
|
9
|
+
Dispatch rules basically tell the Dispatcher which "units" to assign "messages" too. A "unit" is what you are dispatching to, and a "message" is what is being dispatched. For example if you had a sales team "Salesman A", "Salesman B", and "Salesman C" they would be the "units". And if you were dispatching sales leads to those salesmen the "leads" would be the "message".
|
|
10
|
+
|
|
11
|
+
First create a rule.
|
|
12
|
+
|
|
13
|
+
class SalesLeadDispatchRule < DispatchRule
|
|
14
|
+
# Create a rule to your liking maybe it accepts variables.
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
Then create your dispatcher
|
|
18
|
+
|
|
19
|
+
class LeadDispatcher < Dispatcher
|
|
20
|
+
def recall
|
|
21
|
+
# Create code here to find all the leads dispatched in the past hour and unassign them.
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def distribution_algorithm
|
|
25
|
+
# If Dispatcher.message_list or Dispatcher.unit_list or undefined throw and error.
|
|
26
|
+
raise NotImplementedError, "Dispatcher.message_list is undefined or empty.", if Dispatcher.message_list == undef || Dispatcher.message_list.empty?
|
|
27
|
+
raise NotImplementedError, "Dispatcher.unit_list is undefined or empty.", if Dispatcher.unit_list == undef || Dispatcher.unit_list.empty?
|
|
28
|
+
|
|
29
|
+
# Apply the Dispatch rules, loop through the messages and assign them to the units.
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
Then you can create your dispatcher and dispatch rules
|
|
35
|
+
|
|
36
|
+
The Dispatcher takes three optional arguments (message_list, unit_list, rule_list) in that order.
|
|
37
|
+
|
|
38
|
+
sldRule = SalesLeadDispatchRule.new
|
|
39
|
+
ldispatcher = LeadDispatcher.new(todays_leads, SalesReps.find(:all), [sldRule])
|
|
40
|
+
|
|
41
|
+
Or you can set each one seperately.
|
|
42
|
+
ldispatcher.add_rule(sldRule)
|
|
43
|
+
ldispatcher.message_list(todays_leads)
|
|
44
|
+
ldispatcher.unit_list(SalesReps.find(:all))
|
|
45
|
+
results = ldispatcher.dispatch
|
data/Rakefile
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Rakefile
|
|
2
|
+
begin
|
|
3
|
+
require 'jeweler'
|
|
4
|
+
Jeweler::Tasks.new do |gemspec|
|
|
5
|
+
gemspec.name = "depalma"
|
|
6
|
+
gemspec.summary = "A simple but powerful dispatcher."
|
|
7
|
+
gemspec.description = "Configure simple dispatch rules and have data dispatched over a group of receivers."
|
|
8
|
+
gemspec.email = "rankin.devon@gmail.com"
|
|
9
|
+
gemspec.homepage = "http://github.com/crankin/depalma"
|
|
10
|
+
gemspec.authors = ["Christopher Rankin"]
|
|
11
|
+
end
|
|
12
|
+
Jeweler::GemcutterTasks.new
|
|
13
|
+
rescue LoadError
|
|
14
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler -s http://gemcutter.org"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# depalma.gemspec
|
|
18
|
+
Gem::Specification.new do |s|
|
|
19
|
+
s.name = %q{depalma}
|
|
20
|
+
s.version = "0.0.0"
|
|
21
|
+
|
|
22
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
|
23
|
+
s.authors = ["Christopher Rankin"]
|
|
24
|
+
s.date = %q{2010-01-08}
|
|
25
|
+
s.description = %q{Configure simple dispatch rules and have data dispatched over a group of receivers.}
|
|
26
|
+
s.email = %q{rankin.devon@gmail.com}
|
|
27
|
+
s.extra_rdoc_files = ["lib/dispatcher.rb", "lib/dispatch_rule.rb", "README.rdoc"]
|
|
28
|
+
s.files = ["lib/dispatcher.rb", "lib/dispatch_rule.rb", "Rakefile", "README.rdoc", "Manifest", "depalma.gemspec"]
|
|
29
|
+
s.has_rdoc = true
|
|
30
|
+
s.homepage = %q{http://github.com/crankin/depalma}
|
|
31
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "depalma", "--main", "README.rdoc"]
|
|
32
|
+
s.require_paths = ["lib"]
|
|
33
|
+
s.rubyforge_project = %q{depalma}
|
|
34
|
+
s.rubygems_version = %q{1.2.0}
|
|
35
|
+
s.summary = %q{A simple but powerful dispatcher.}
|
|
36
|
+
|
|
37
|
+
if s.respond_to? :specification_version then
|
|
38
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
39
|
+
s.specification_version = 2
|
|
40
|
+
|
|
41
|
+
if current_version >= 3 then
|
|
42
|
+
else
|
|
43
|
+
end
|
|
44
|
+
else
|
|
45
|
+
end
|
|
46
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.0
|
data/depalma.gemspec
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = %q{depalma}
|
|
8
|
+
s.version = "0.1.0"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["Christopher Rankin"]
|
|
12
|
+
s.date = %q{2010-01-10}
|
|
13
|
+
s.description = %q{Configure simple dispatch rules and have data dispatched over a group of receivers.}
|
|
14
|
+
s.email = %q{rankin.devon@gmail.com}
|
|
15
|
+
s.extra_rdoc_files = [
|
|
16
|
+
"README.rdoc"
|
|
17
|
+
]
|
|
18
|
+
s.files = [
|
|
19
|
+
"README.rdoc",
|
|
20
|
+
"Rakefile",
|
|
21
|
+
"VERSION",
|
|
22
|
+
"depalma.gemspec",
|
|
23
|
+
"lib/dispatch_rule.rb",
|
|
24
|
+
"lib/dispatch_unit.rb",
|
|
25
|
+
"lib/dispatcher.rb"
|
|
26
|
+
]
|
|
27
|
+
s.homepage = %q{http://github.com/crankin/depalma}
|
|
28
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
29
|
+
s.require_paths = ["lib"]
|
|
30
|
+
s.rubygems_version = %q{1.3.5}
|
|
31
|
+
s.summary = %q{A simple but powerful dispatcher.}
|
|
32
|
+
|
|
33
|
+
if s.respond_to? :specification_version then
|
|
34
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
35
|
+
s.specification_version = 3
|
|
36
|
+
|
|
37
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
38
|
+
else
|
|
39
|
+
end
|
|
40
|
+
else
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class DispatchRule
|
|
2
|
+
# Accessors
|
|
3
|
+
attr_accessor :weight
|
|
4
|
+
# Class Methods
|
|
5
|
+
|
|
6
|
+
# initialize
|
|
7
|
+
#---------------------------------------------------------------------------
|
|
8
|
+
def initialize(weight=0)
|
|
9
|
+
@weight = weight
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Instance Methods
|
|
13
|
+
|
|
14
|
+
# Run the rule, called from the dispatcher. Rules should return a list of weighted "units".
|
|
15
|
+
#---------------------------------------------------------------------------
|
|
16
|
+
def run(list=[])
|
|
17
|
+
raise NotImplementedError, 'Please subclass DispatchRule, and write a "run" method.'
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class DispatchUnit
|
|
2
|
+
# Accessors
|
|
3
|
+
attr_accessor :weight, :body
|
|
4
|
+
|
|
5
|
+
# Class Methods
|
|
6
|
+
|
|
7
|
+
# initialize
|
|
8
|
+
#---------------------------------------------------------------------------
|
|
9
|
+
def initialize(weight, body)
|
|
10
|
+
@weight = weight
|
|
11
|
+
@body = body
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Instance Methods
|
|
15
|
+
|
|
16
|
+
# promote
|
|
17
|
+
#---------------------------------------------------------------------------
|
|
18
|
+
def promote
|
|
19
|
+
@weight += 1
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# demote
|
|
23
|
+
#---------------------------------------------------------------------------
|
|
24
|
+
def demote
|
|
25
|
+
@weight -= 1
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/dispatcher.rb
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
class Dispatcher
|
|
2
|
+
# Accessors
|
|
3
|
+
attr_accessor :message_list, :unit_list, :rule_list
|
|
4
|
+
|
|
5
|
+
# Class Methods
|
|
6
|
+
|
|
7
|
+
# units_from_list
|
|
8
|
+
#---------------------------------------------------------------------------
|
|
9
|
+
def self.create_units_from_list(list)
|
|
10
|
+
list.map { |x|
|
|
11
|
+
DispatchUnit.new(0, x)
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Instance Methods
|
|
16
|
+
|
|
17
|
+
# initialize
|
|
18
|
+
#---------------------------------------------------------------------------
|
|
19
|
+
def initialize(messages=[], units=[], rules=[])
|
|
20
|
+
@rule_list = rules
|
|
21
|
+
@message_list = messages
|
|
22
|
+
@unit_list = units
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# dispatch_algorithm
|
|
26
|
+
#---------------------------------------------------------------------------
|
|
27
|
+
def dispatch_algorithm
|
|
28
|
+
raise NotImplementedError, 'Subclass Dispatcher and define your own "dispatch_algorithm" method.'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# add_rule
|
|
32
|
+
#---------------------------------------------------------------------------
|
|
33
|
+
def add_rule(rule)
|
|
34
|
+
@rule_list.push(rule)
|
|
35
|
+
@rule_list.sort! { |x,y| x.weight <=> y.weight }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# remove_rule
|
|
39
|
+
#---------------------------------------------------------------------------
|
|
40
|
+
def remove_rule(rule)
|
|
41
|
+
@rule_list.delete(rule)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# dispatch
|
|
45
|
+
#---------------------------------------------------------------------------
|
|
46
|
+
def dispatch
|
|
47
|
+
@rule_list.each { |rule| rule.run(self.unit_list) }
|
|
48
|
+
self.dispatch_algorithm
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: depalma
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Christopher Rankin
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2010-01-10 00:00:00 -05:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Configure simple dispatch rules and have data dispatched over a group of receivers.
|
|
17
|
+
email: rankin.devon@gmail.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- README.rdoc
|
|
24
|
+
files:
|
|
25
|
+
- README.rdoc
|
|
26
|
+
- Rakefile
|
|
27
|
+
- VERSION
|
|
28
|
+
- depalma.gemspec
|
|
29
|
+
- lib/dispatch_rule.rb
|
|
30
|
+
- lib/dispatch_unit.rb
|
|
31
|
+
- lib/dispatcher.rb
|
|
32
|
+
has_rdoc: true
|
|
33
|
+
homepage: http://github.com/crankin/depalma
|
|
34
|
+
licenses: []
|
|
35
|
+
|
|
36
|
+
post_install_message:
|
|
37
|
+
rdoc_options:
|
|
38
|
+
- --charset=UTF-8
|
|
39
|
+
require_paths:
|
|
40
|
+
- lib
|
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: "0"
|
|
46
|
+
version:
|
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: "0"
|
|
52
|
+
version:
|
|
53
|
+
requirements: []
|
|
54
|
+
|
|
55
|
+
rubyforge_project:
|
|
56
|
+
rubygems_version: 1.3.5
|
|
57
|
+
signing_key:
|
|
58
|
+
specification_version: 3
|
|
59
|
+
summary: A simple but powerful dispatcher.
|
|
60
|
+
test_files: []
|
|
61
|
+
|