Sutto-perennial 0.2.3.5 → 0.2.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/perennial +1 -2
- data/lib/perennial/core_ext/attribute_accessors.rb +25 -0
- data/lib/perennial/core_ext/misc.rb +2 -2
- data/lib/perennial/dispatchable.rb +38 -25
- data/lib/perennial.rb +1 -1
- metadata +2 -2
data/bin/perennial
CHANGED
@@ -15,8 +15,7 @@ Perennial::Application.processing(ARGV) do |a|
|
|
15
15
|
path = File.expand_path(path)
|
16
16
|
# Check if the folder exists
|
17
17
|
if File.exist?(path) && !opts[:force]
|
18
|
-
|
19
|
-
exit
|
18
|
+
die! "The path you tried to use, #{path}, already exists. Please try another or pass --force"
|
20
19
|
end
|
21
20
|
# Convert the name and class name.
|
22
21
|
app_path = app_name.underscore
|
@@ -1,6 +1,31 @@
|
|
1
1
|
# cattr_* and class_inheritable_* are taken from
|
2
2
|
# ActiveSupport. Included here to help keep the
|
3
3
|
# codebase simple / clean.
|
4
|
+
|
5
|
+
class Object
|
6
|
+
|
7
|
+
unless respond_to?(:instance_variable_defined?)
|
8
|
+
def instance_variable_defined?(variable)
|
9
|
+
instance_variables.include?(variable.to_s)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def instance_values #:nodoc:
|
14
|
+
instance_variables.inject({}) do |values, name|
|
15
|
+
values[name.to_s[1..-1]] = instance_variable_get(name)
|
16
|
+
values
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
if RUBY_VERSION >= '1.9'
|
21
|
+
def instance_variable_names
|
22
|
+
instance_variables.map { |var| var.to_s }
|
23
|
+
end
|
24
|
+
else
|
25
|
+
alias_method :instance_variable_names, :instance_variables
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
4
29
|
class Class
|
5
30
|
def cattr_reader(*syms)
|
6
31
|
syms.flatten.each do |sym|
|
@@ -70,8 +70,8 @@ class Module
|
|
70
70
|
|
71
71
|
def add_extension(name, &blk)
|
72
72
|
item = name.to_s.camelize.to_sym
|
73
|
-
|
74
|
-
|
73
|
+
target = const_get(item) rescue nil
|
74
|
+
raise "Didn't find library for #{name}" if target.nil?
|
75
75
|
if target.is_a?(Class)
|
76
76
|
target.class_eval(&blk)
|
77
77
|
elsif target.is_a?(Module)
|
@@ -36,39 +36,52 @@ module Perennial
|
|
36
36
|
self.class.handlers
|
37
37
|
end
|
38
38
|
|
39
|
+
def dispatch_queue
|
40
|
+
@dispatch_queue ||= []
|
41
|
+
end
|
42
|
+
|
39
43
|
# Dispatch an 'event' with a given name to the handlers
|
40
44
|
# registered on the current class. Used as a nicer way of defining
|
41
45
|
# behaviours that should occur under a given set of circumstances.
|
42
46
|
# == Params
|
43
47
|
# +name+: The name of the current event
|
44
48
|
# +opts+: an optional hash of options to pass
|
45
|
-
def dispatch(name, opts = {})
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
49
|
+
def dispatch(name, opts = {}, force = false)
|
50
|
+
if dispatch_queue.empty? || force
|
51
|
+
Logger.debug "Dispatching #{name} event (#{dispatch_queue.size} queued - on #{self.class.name})"
|
52
|
+
begin
|
53
|
+
# The full handler name is the method we call given it exists.
|
54
|
+
full_handler_name = :"handle_#{name.to_s.underscore}"
|
55
|
+
# First, dispatch locally if the method is defined.
|
56
|
+
self.send(full_handler_name, opts) if self.respond_to?(full_handler_name)
|
57
|
+
# Iterate through all of the registered handlers,
|
58
|
+
# If there is a method named handle_<event_name>
|
59
|
+
# defined we sent that otherwise we call the handle
|
60
|
+
# method on the handler. Note that the handle method
|
61
|
+
# is the only required aspect of a handler. An improved
|
62
|
+
# version of this would likely cache the respond_to?
|
63
|
+
# call.
|
64
|
+
self.handlers.each do |handler|
|
65
|
+
if handler.respond_to?(full_handler_name)
|
66
|
+
handler.send(full_handler_name, opts)
|
67
|
+
else
|
68
|
+
handler.handle name, opts
|
69
|
+
end
|
70
|
+
end
|
71
|
+
# If we get the HaltHandlerProcessing exception, we
|
72
|
+
# catch it and continue on our way. In essence, we
|
73
|
+
# stop the dispatch of events to the next set of the
|
74
|
+
# handlers.
|
75
|
+
rescue HaltHandlerProcessing => e
|
76
|
+
Logger.info "Halting processing chain"
|
77
|
+
rescue Exception => e
|
78
|
+
Logger.log_exception(e)
|
62
79
|
end
|
80
|
+
dispatch(*dispatch_queue.shift) unless dispatch_queue.empty?
|
81
|
+
else
|
82
|
+
Logger.debug "Adding #{name} event to the end of the queue (on #{self.class.name})"
|
83
|
+
dispatch_queue << [name, opts, true]
|
63
84
|
end
|
64
|
-
# If we get the HaltHandlerProcessing exception, we
|
65
|
-
# catch it and continue on our way. In essence, we
|
66
|
-
# stop the dispatch of events to the next set of the
|
67
|
-
# handlers.
|
68
|
-
rescue HaltHandlerProcessing => e
|
69
|
-
Logger.info "Halting processing chain"
|
70
|
-
rescue Exception => e
|
71
|
-
Logger.log_exception(e)
|
72
85
|
end
|
73
86
|
|
74
87
|
end
|
data/lib/perennial.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Sutto-perennial
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.3.
|
4
|
+
version: 0.2.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darcy Laycock
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-11 00:00:00 -07:00
|
13
13
|
default_executable: perennial
|
14
14
|
dependencies: []
|
15
15
|
|