csd 0.0.15 → 0.0.16
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/.gitignore +1 -0
- data/COPYING +367 -0
- data/Rakefile +10 -10
- data/VERSION +1 -1
- data/bin/ai +19 -0
- data/csd.gemspec +257 -35
- data/lib/active_support.rb +75 -0
- data/lib/active_support/all.rb +3 -0
- data/lib/active_support/backtrace_cleaner.rb +94 -0
- data/lib/active_support/base64.rb +42 -0
- data/lib/active_support/basic_object.rb +21 -0
- data/lib/active_support/benchmarkable.rb +60 -0
- data/lib/active_support/buffered_logger.rb +132 -0
- data/lib/active_support/builder.rb +6 -0
- data/lib/active_support/cache.rb +626 -0
- data/lib/active_support/cache/compressed_mem_cache_store.rb +13 -0
- data/lib/active_support/cache/file_store.rb +188 -0
- data/lib/active_support/cache/mem_cache_store.rb +191 -0
- data/lib/active_support/cache/memory_store.rb +159 -0
- data/lib/active_support/cache/strategy/local_cache.rb +164 -0
- data/lib/active_support/cache/synchronized_memory_store.rb +11 -0
- data/lib/active_support/callbacks.rb +600 -0
- data/lib/active_support/concern.rb +29 -0
- data/lib/active_support/configurable.rb +36 -0
- data/lib/active_support/core_ext.rb +3 -0
- data/lib/active_support/core_ext/array.rb +7 -0
- data/lib/active_support/core_ext/array/access.rb +46 -0
- data/lib/active_support/core_ext/array/conversions.rb +164 -0
- data/lib/active_support/core_ext/array/extract_options.rb +29 -0
- data/lib/active_support/core_ext/array/grouping.rb +100 -0
- data/lib/active_support/core_ext/array/random_access.rb +20 -0
- data/lib/active_support/core_ext/array/uniq_by.rb +17 -0
- data/lib/active_support/core_ext/array/wrap.rb +22 -0
- data/lib/active_support/core_ext/benchmark.rb +7 -0
- data/lib/active_support/core_ext/big_decimal.rb +1 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +27 -0
- data/lib/active_support/core_ext/cgi.rb +1 -0
- data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +19 -0
- data/lib/active_support/core_ext/class.rb +4 -0
- data/lib/active_support/core_ext/class/attribute.rb +67 -0
- data/lib/active_support/core_ext/class/attribute_accessors.rb +63 -0
- data/lib/active_support/core_ext/class/delegating_attributes.rb +44 -0
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +232 -0
- data/lib/active_support/core_ext/class/subclasses.rb +55 -0
- data/lib/active_support/core_ext/date/acts_like.rb +8 -0
- data/lib/active_support/core_ext/date/calculations.rb +240 -0
- data/lib/active_support/core_ext/date/conversions.rb +99 -0
- data/lib/active_support/core_ext/date/freeze.rb +31 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +13 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +113 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +102 -0
- data/lib/active_support/core_ext/date_time/zones.rb +17 -0
- data/lib/active_support/core_ext/enumerable.rb +119 -0
- data/lib/active_support/core_ext/exception.rb +3 -0
- data/lib/active_support/core_ext/file.rb +2 -0
- data/lib/active_support/core_ext/file/atomic.rb +41 -0
- data/lib/active_support/core_ext/file/path.rb +5 -0
- data/lib/active_support/core_ext/float.rb +1 -0
- data/lib/active_support/core_ext/float/rounding.rb +19 -0
- data/lib/active_support/core_ext/hash.rb +8 -0
- data/lib/active_support/core_ext/hash/conversions.rb +150 -0
- data/lib/active_support/core_ext/hash/deep_merge.rb +16 -0
- data/lib/active_support/core_ext/hash/diff.rb +13 -0
- data/lib/active_support/core_ext/hash/except.rb +24 -0
- data/lib/active_support/core_ext/hash/indifferent_access.rb +14 -0
- data/lib/active_support/core_ext/hash/keys.rb +45 -0
- data/lib/active_support/core_ext/hash/reverse_merge.rb +28 -0
- data/lib/active_support/core_ext/hash/slice.rb +38 -0
- data/lib/active_support/core_ext/integer.rb +3 -0
- data/lib/active_support/core_ext/integer/inflections.rb +14 -0
- data/lib/active_support/core_ext/integer/multiple.rb +6 -0
- data/lib/active_support/core_ext/integer/time.rb +39 -0
- data/lib/active_support/core_ext/kernel.rb +5 -0
- data/lib/active_support/core_ext/kernel/agnostics.rb +11 -0
- data/lib/active_support/core_ext/kernel/debugger.rb +16 -0
- data/lib/active_support/core_ext/kernel/reporting.rb +62 -0
- data/lib/active_support/core_ext/kernel/requires.rb +26 -0
- data/lib/active_support/core_ext/kernel/singleton_class.rb +13 -0
- data/lib/active_support/core_ext/load_error.rb +23 -0
- data/lib/active_support/core_ext/logger.rb +146 -0
- data/lib/active_support/core_ext/module.rb +12 -0
- data/lib/active_support/core_ext/module/aliasing.rb +70 -0
- data/lib/active_support/core_ext/module/anonymous.rb +24 -0
- data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +31 -0
- data/lib/active_support/core_ext/module/attr_internal.rb +32 -0
- data/lib/active_support/core_ext/module/attribute_accessors.rb +66 -0
- data/lib/active_support/core_ext/module/delegation.rb +146 -0
- data/lib/active_support/core_ext/module/deprecation.rb +9 -0
- data/lib/active_support/core_ext/module/introspection.rb +88 -0
- data/lib/active_support/core_ext/module/method_names.rb +14 -0
- data/lib/active_support/core_ext/module/reachable.rb +10 -0
- data/lib/active_support/core_ext/module/remove_method.rb +6 -0
- data/lib/active_support/core_ext/module/synchronization.rb +42 -0
- data/lib/active_support/core_ext/name_error.rb +18 -0
- data/lib/active_support/core_ext/numeric.rb +2 -0
- data/lib/active_support/core_ext/numeric/bytes.rb +44 -0
- data/lib/active_support/core_ext/numeric/time.rb +77 -0
- data/lib/active_support/core_ext/object.rb +14 -0
- data/lib/active_support/core_ext/object/acts_like.rb +10 -0
- data/lib/active_support/core_ext/object/blank.rb +76 -0
- data/lib/active_support/core_ext/object/conversions.rb +4 -0
- data/lib/active_support/core_ext/object/duplicable.rb +65 -0
- data/lib/active_support/core_ext/object/extending.rb +11 -0
- data/lib/active_support/core_ext/object/instance_variables.rb +67 -0
- data/lib/active_support/core_ext/object/misc.rb +2 -0
- data/lib/active_support/core_ext/object/returning.rb +42 -0
- data/lib/active_support/core_ext/object/to_param.rb +49 -0
- data/lib/active_support/core_ext/object/to_query.rb +27 -0
- data/lib/active_support/core_ext/object/try.rb +36 -0
- data/lib/active_support/core_ext/object/with_options.rb +26 -0
- data/lib/active_support/core_ext/proc.rb +14 -0
- data/lib/active_support/core_ext/process.rb +1 -0
- data/lib/active_support/core_ext/process/daemon.rb +23 -0
- data/lib/active_support/core_ext/range.rb +4 -0
- data/lib/active_support/core_ext/range/blockless_step.rb +29 -0
- data/lib/active_support/core_ext/range/conversions.rb +21 -0
- data/lib/active_support/core_ext/range/include_range.rb +21 -0
- data/lib/active_support/core_ext/range/overlaps.rb +8 -0
- data/lib/active_support/core_ext/regexp.rb +5 -0
- data/lib/active_support/core_ext/rexml.rb +46 -0
- data/lib/active_support/core_ext/string.rb +12 -0
- data/lib/active_support/core_ext/string/access.rb +99 -0
- data/lib/active_support/core_ext/string/behavior.rb +7 -0
- data/lib/active_support/core_ext/string/conversions.rb +61 -0
- data/lib/active_support/core_ext/string/encoding.rb +11 -0
- data/lib/active_support/core_ext/string/exclude.rb +6 -0
- data/lib/active_support/core_ext/string/filters.rb +49 -0
- data/lib/active_support/core_ext/string/inflections.rb +149 -0
- data/lib/active_support/core_ext/string/interpolation.rb +2 -0
- data/lib/active_support/core_ext/string/multibyte.rb +72 -0
- data/lib/active_support/core_ext/string/output_safety.rb +109 -0
- data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -0
- data/lib/active_support/core_ext/string/xchar.rb +18 -0
- data/lib/active_support/core_ext/time/acts_like.rb +8 -0
- data/lib/active_support/core_ext/time/calculations.rb +282 -0
- data/lib/active_support/core_ext/time/conversions.rb +85 -0
- data/lib/active_support/core_ext/time/marshal.rb +56 -0
- data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +10 -0
- data/lib/active_support/core_ext/time/zones.rb +78 -0
- data/lib/active_support/core_ext/uri.rb +22 -0
- data/lib/active_support/dependencies.rb +628 -0
- data/lib/active_support/dependencies/autoload.rb +50 -0
- data/lib/active_support/deprecation.rb +18 -0
- data/lib/active_support/deprecation/behaviors.rb +38 -0
- data/lib/active_support/deprecation/method_wrappers.rb +29 -0
- data/lib/active_support/deprecation/proxy_wrappers.rb +74 -0
- data/lib/active_support/deprecation/reporting.rb +56 -0
- data/lib/active_support/duration.rb +105 -0
- data/lib/active_support/gzip.rb +25 -0
- data/lib/active_support/hash_with_indifferent_access.rb +145 -0
- data/lib/active_support/i18n.rb +8 -0
- data/lib/active_support/inflections.rb +56 -0
- data/lib/active_support/inflector.rb +7 -0
- data/lib/active_support/inflector/inflections.rb +211 -0
- data/lib/active_support/inflector/methods.rb +141 -0
- data/lib/active_support/inflector/transliterate.rb +97 -0
- data/lib/active_support/json.rb +2 -0
- data/lib/active_support/json/backends/jsongem.rb +43 -0
- data/lib/active_support/json/backends/yajl.rb +40 -0
- data/lib/active_support/json/backends/yaml.rb +90 -0
- data/lib/active_support/json/decoding.rb +51 -0
- data/lib/active_support/json/encoding.rb +254 -0
- data/lib/active_support/json/variable.rb +11 -0
- data/lib/active_support/lazy_load_hooks.rb +27 -0
- data/lib/active_support/locale/en.yml +36 -0
- data/lib/active_support/memoizable.rb +103 -0
- data/lib/active_support/message_encryptor.rb +71 -0
- data/lib/active_support/message_verifier.rb +62 -0
- data/lib/active_support/multibyte.rb +44 -0
- data/lib/active_support/multibyte/chars.rb +480 -0
- data/lib/active_support/multibyte/exceptions.rb +8 -0
- data/lib/active_support/multibyte/unicode.rb +393 -0
- data/lib/active_support/multibyte/utils.rb +60 -0
- data/lib/active_support/notifications.rb +81 -0
- data/lib/active_support/notifications/fanout.rb +93 -0
- data/lib/active_support/notifications/instrumenter.rb +56 -0
- data/lib/active_support/option_merger.rb +25 -0
- data/lib/active_support/ordered_hash.rb +158 -0
- data/lib/active_support/ordered_options.rb +27 -0
- data/lib/active_support/railtie.rb +100 -0
- data/lib/active_support/rescuable.rb +114 -0
- data/lib/active_support/ruby/shim.rb +22 -0
- data/lib/active_support/secure_random.rb +199 -0
- data/lib/active_support/string_inquirer.rb +21 -0
- data/lib/active_support/test_case.rb +42 -0
- data/lib/active_support/testing/assertions.rb +82 -0
- data/lib/active_support/testing/declarative.rb +40 -0
- data/lib/active_support/testing/default.rb +9 -0
- data/lib/active_support/testing/deprecation.rb +55 -0
- data/lib/active_support/testing/isolation.rb +154 -0
- data/lib/active_support/testing/pending.rb +48 -0
- data/lib/active_support/testing/performance.rb +455 -0
- data/lib/active_support/testing/setup_and_teardown.rb +111 -0
- data/lib/active_support/time.rb +34 -0
- data/lib/active_support/time/autoload.rb +5 -0
- data/lib/active_support/time_with_zone.rb +341 -0
- data/lib/active_support/values/time_zone.rb +377 -0
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +10 -0
- data/lib/active_support/whiny_nil.rb +60 -0
- data/lib/active_support/xml_mini.rb +158 -0
- data/lib/active_support/xml_mini/jdom.rb +168 -0
- data/lib/active_support/xml_mini/libxml.rb +80 -0
- data/lib/active_support/xml_mini/libxmlsax.rb +85 -0
- data/lib/active_support/xml_mini/nokogiri.rb +78 -0
- data/lib/active_support/xml_mini/nokogirisax.rb +83 -0
- data/lib/active_support/xml_mini/rexml.rb +129 -0
- data/lib/csd.rb +82 -2
- data/lib/csd/application.rb +2 -0
- data/lib/csd/application/default.rb +51 -0
- data/lib/csd/application/default/base.rb +15 -0
- data/lib/csd/application/minisip.rb +25 -0
- data/lib/csd/application/minisip/about.yml +14 -0
- data/lib/csd/application/minisip/base.rb +161 -0
- data/lib/csd/application/minisip/error.rb +11 -0
- data/lib/csd/application/minisip/options/common.rb +0 -0
- data/lib/csd/application/minisip/options/compile.rb +59 -0
- data/lib/csd/{applications → application}/minisip/unix/base.rb +10 -11
- data/lib/csd/application/opensips/about.yml +2 -0
- data/lib/csd/applications.rb +55 -0
- data/lib/csd/commands.rb +88 -65
- data/lib/csd/error.rb +31 -0
- data/lib/csd/extensions.rb +1 -0
- data/lib/{extensions → csd/extensions}/core/array.rb +2 -2
- data/lib/csd/extensions/core/dir.rb +46 -0
- data/lib/{extensions → csd/extensions}/core/file.rb +2 -2
- data/lib/{extensions → csd/extensions}/core/object.rb +2 -2
- data/lib/csd/extensions/core/option_parser.rb +33 -0
- data/lib/{extensions → csd/extensions}/core/pathname.rb +12 -3
- data/lib/{extensions → csd/extensions}/core/string.rb +2 -2
- data/lib/{extensions → csd/extensions}/gem/platform.rb +6 -2
- data/lib/csd/global_open_struct.rb +18 -0
- data/lib/csd/options.rb +124 -95
- data/lib/csd/path.rb +31 -0
- data/lib/csd/ui.rb +1 -0
- data/lib/csd/ui/cli.rb +7 -0
- data/lib/csd/ui/ui.rb +46 -0
- data/lib/csd/version.rb +9 -0
- data/lib/term/ansicolor.rb +102 -0
- data/lib/term/ansicolor/.keep +0 -0
- data/lib/term/ansicolor/version.rb +10 -0
- data/test/functional/test_applications.rb +86 -0
- data/test/functional/test_commands.rb +42 -29
- data/test/functional/test_options.rb +98 -0
- data/test/helper.rb +14 -0
- data/test/unit/test_dir.rb +38 -0
- data/test/unit/test_pathname.rb +32 -0
- metadata +253 -40
- data/LICENSE +0 -20
- data/bin/csd +0 -8
- data/lib/csd/applications/base.rb +0 -33
- data/lib/csd/applications/minisip/base.rb +0 -125
- data/lib/csd/applications/minisip/init.rb +0 -20
- data/lib/csd/init.rb +0 -69
- data/lib/csd/path_container.rb +0 -15
- data/publish +0 -29
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'active_support/core_ext/module/delegation'
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
# Notifications provides an instrumentation API for Ruby. To instrument an
|
5
|
+
# action in Ruby you just need to do:
|
6
|
+
#
|
7
|
+
# ActiveSupport::Notifications.instrument(:render, :extra => :information) do
|
8
|
+
# render :text => "Foo"
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# You can consume those events and the information they provide by registering
|
12
|
+
# a log subscriber. For instance, let's store all instrumented events in an array:
|
13
|
+
#
|
14
|
+
# @events = []
|
15
|
+
#
|
16
|
+
# ActiveSupport::Notifications.subscribe do |*args|
|
17
|
+
# @events << ActiveSupport::Notifications::Event.new(*args)
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# ActiveSupport::Notifications.instrument(:render, :extra => :information) do
|
21
|
+
# render :text => "Foo"
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# event = @events.first
|
25
|
+
# event.name #=> :render
|
26
|
+
# event.duration #=> 10 (in miliseconds)
|
27
|
+
# event.result #=> "Foo"
|
28
|
+
# event.payload #=> { :extra => :information }
|
29
|
+
#
|
30
|
+
# When subscribing to Notifications, you can pass a pattern, to only consume
|
31
|
+
# events that match the pattern:
|
32
|
+
#
|
33
|
+
# ActiveSupport::Notifications.subscribe(/render/) do |event|
|
34
|
+
# @render_events << event
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# Notifications ships with a queue implementation that consumes and publish events
|
38
|
+
# to log subscribers in a thread. You can use any queue implementation you want.
|
39
|
+
#
|
40
|
+
module Notifications
|
41
|
+
autoload :Instrumenter, 'active_support/notifications/instrumenter'
|
42
|
+
autoload :Event, 'active_support/notifications/instrumenter'
|
43
|
+
autoload :Fanout, 'active_support/notifications/fanout'
|
44
|
+
|
45
|
+
class << self
|
46
|
+
attr_writer :notifier
|
47
|
+
delegate :publish, :subscribe, :unsubscribe, :to => :notifier
|
48
|
+
delegate :instrument, :to => :instrumenter
|
49
|
+
|
50
|
+
def notifier
|
51
|
+
@notifier ||= Notifier.new
|
52
|
+
end
|
53
|
+
|
54
|
+
def instrumenter
|
55
|
+
Thread.current[:"instrumentation_#{notifier.object_id}"] ||= Instrumenter.new(notifier)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class Notifier
|
60
|
+
def initialize(queue = Fanout.new)
|
61
|
+
@queue = queue
|
62
|
+
end
|
63
|
+
|
64
|
+
def publish(*args)
|
65
|
+
@queue.publish(*args)
|
66
|
+
end
|
67
|
+
|
68
|
+
def subscribe(pattern = nil, &block)
|
69
|
+
@queue.bind(pattern).subscribe(&block)
|
70
|
+
end
|
71
|
+
|
72
|
+
def unsubscribe(subscriber)
|
73
|
+
@queue.unsubscribe(subscriber)
|
74
|
+
end
|
75
|
+
|
76
|
+
def wait
|
77
|
+
@queue.wait
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module ActiveSupport
|
2
|
+
module Notifications
|
3
|
+
# This is a default queue implementation that ships with Notifications. It
|
4
|
+
# just pushes events to all registered log subscribers.
|
5
|
+
class Fanout
|
6
|
+
def initialize
|
7
|
+
@subscribers = []
|
8
|
+
@listeners_for = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def bind(pattern)
|
12
|
+
Binding.new(self, pattern)
|
13
|
+
end
|
14
|
+
|
15
|
+
def subscribe(pattern = nil, &block)
|
16
|
+
@listeners_for.clear
|
17
|
+
@subscribers << Subscriber.new(pattern, &block)
|
18
|
+
@subscribers.last
|
19
|
+
end
|
20
|
+
|
21
|
+
def unsubscribe(subscriber)
|
22
|
+
@listeners_for.clear
|
23
|
+
@subscribers.reject! {|s| s.matches?(subscriber)}
|
24
|
+
end
|
25
|
+
|
26
|
+
def publish(name, *args)
|
27
|
+
if listeners = @listeners_for[name]
|
28
|
+
listeners.each { |s| s.publish(name, *args) }
|
29
|
+
else
|
30
|
+
@listeners_for[name] = @subscribers.select { |s| s.publish(name, *args) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# This is a sync queue, so there is not waiting.
|
35
|
+
def wait
|
36
|
+
end
|
37
|
+
|
38
|
+
# Used for internal implementation only.
|
39
|
+
class Binding #:nodoc:
|
40
|
+
def initialize(queue, pattern)
|
41
|
+
@queue = queue
|
42
|
+
@pattern =
|
43
|
+
case pattern
|
44
|
+
when Regexp, NilClass
|
45
|
+
pattern
|
46
|
+
else
|
47
|
+
/^#{Regexp.escape(pattern.to_s)}$/
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def subscribe(&block)
|
52
|
+
@queue.subscribe(@pattern, &block)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class Subscriber #:nodoc:
|
57
|
+
def initialize(pattern, &block)
|
58
|
+
@pattern = pattern
|
59
|
+
@block = block
|
60
|
+
end
|
61
|
+
|
62
|
+
def publish(*args)
|
63
|
+
return unless subscribed_to?(args.first)
|
64
|
+
push(*args)
|
65
|
+
true
|
66
|
+
end
|
67
|
+
|
68
|
+
def drained?
|
69
|
+
true
|
70
|
+
end
|
71
|
+
|
72
|
+
def subscribed_to?(name)
|
73
|
+
!@pattern || @pattern =~ name.to_s
|
74
|
+
end
|
75
|
+
|
76
|
+
def matches?(subscriber_or_name)
|
77
|
+
case subscriber_or_name
|
78
|
+
when String
|
79
|
+
@pattern && @pattern =~ subscriber_or_name
|
80
|
+
when self
|
81
|
+
true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def push(*args)
|
88
|
+
@block.call(*args)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'active_support/secure_random'
|
2
|
+
require 'active_support/core_ext/module/delegation'
|
3
|
+
|
4
|
+
module ActiveSupport
|
5
|
+
module Notifications
|
6
|
+
class Instrumenter
|
7
|
+
attr_reader :id
|
8
|
+
|
9
|
+
def initialize(notifier)
|
10
|
+
@id = unique_id
|
11
|
+
@notifier = notifier
|
12
|
+
end
|
13
|
+
|
14
|
+
# Instrument the given block by measuring the time taken to execute it
|
15
|
+
# and publish it. Notice that events get sent even if an error occurs
|
16
|
+
# in the passed-in block
|
17
|
+
def instrument(name, payload={})
|
18
|
+
time = Time.now
|
19
|
+
begin
|
20
|
+
yield(payload) if block_given?
|
21
|
+
rescue Exception => e
|
22
|
+
payload[:exception] = [e.class.name, e.message]
|
23
|
+
raise e
|
24
|
+
ensure
|
25
|
+
@notifier.publish(name, time, Time.now, @id, payload)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def unique_id
|
31
|
+
SecureRandom.hex(10)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Event
|
36
|
+
attr_reader :name, :time, :end, :transaction_id, :payload
|
37
|
+
|
38
|
+
def initialize(name, start, ending, transaction_id, payload)
|
39
|
+
@name = name
|
40
|
+
@payload = payload.dup
|
41
|
+
@time = start
|
42
|
+
@transaction_id = transaction_id
|
43
|
+
@end = ending
|
44
|
+
end
|
45
|
+
|
46
|
+
def duration
|
47
|
+
@duration ||= 1000.0 * (@end - @time)
|
48
|
+
end
|
49
|
+
|
50
|
+
def parent_of?(event)
|
51
|
+
start = (self.time - event.time) * 1000
|
52
|
+
start <= 0 && (start + duration >= event.duration)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'active_support/core_ext/hash/deep_merge'
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
class OptionMerger #:nodoc:
|
5
|
+
instance_methods.each do |method|
|
6
|
+
undef_method(method) if method !~ /^(__|instance_eval|class|object_id)/
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(context, options)
|
10
|
+
@context, @options = context, options
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def method_missing(method, *arguments, &block)
|
15
|
+
if arguments.last.is_a?(Proc)
|
16
|
+
proc = arguments.pop
|
17
|
+
arguments << lambda { |*args| @options.deep_merge(proc.call(*args)) }
|
18
|
+
else
|
19
|
+
arguments << (arguments.last.respond_to?(:to_hash) ? @options.deep_merge(arguments.pop) : @options.dup)
|
20
|
+
end
|
21
|
+
|
22
|
+
@context.__send__(method, *arguments, &block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
YAML.add_builtin_type("omap") do |type, val|
|
4
|
+
ActiveSupport::OrderedHash[val.map(&:to_a).map(&:first)]
|
5
|
+
end
|
6
|
+
|
7
|
+
# OrderedHash is namespaced to prevent conflicts with other implementations
|
8
|
+
module ActiveSupport
|
9
|
+
class OrderedHash < ::Hash #:nodoc:
|
10
|
+
def to_yaml_type
|
11
|
+
"!tag:yaml.org,2002:omap"
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_yaml(opts = {})
|
15
|
+
YAML.quick_emit(self, opts) do |out|
|
16
|
+
out.seq(taguri, to_yaml_style) do |seq|
|
17
|
+
each do |k, v|
|
18
|
+
seq.add(k => v)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Hash is ordered in Ruby 1.9!
|
25
|
+
if RUBY_VERSION < '1.9'
|
26
|
+
def initialize(*args, &block)
|
27
|
+
super
|
28
|
+
@keys = []
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.[](*args)
|
32
|
+
ordered_hash = new
|
33
|
+
|
34
|
+
if (args.length == 1 && args.first.is_a?(Array))
|
35
|
+
args.first.each do |key_value_pair|
|
36
|
+
next unless (key_value_pair.is_a?(Array))
|
37
|
+
ordered_hash[key_value_pair[0]] = key_value_pair[1]
|
38
|
+
end
|
39
|
+
|
40
|
+
return ordered_hash
|
41
|
+
end
|
42
|
+
|
43
|
+
unless (args.size % 2 == 0)
|
44
|
+
raise ArgumentError.new("odd number of arguments for Hash")
|
45
|
+
end
|
46
|
+
|
47
|
+
args.each_with_index do |val, ind|
|
48
|
+
next if (ind % 2 != 0)
|
49
|
+
ordered_hash[val] = args[ind + 1]
|
50
|
+
end
|
51
|
+
|
52
|
+
ordered_hash
|
53
|
+
end
|
54
|
+
|
55
|
+
def initialize_copy(other)
|
56
|
+
super
|
57
|
+
# make a deep copy of keys
|
58
|
+
@keys = other.keys
|
59
|
+
end
|
60
|
+
|
61
|
+
def []=(key, value)
|
62
|
+
@keys << key if !has_key?(key)
|
63
|
+
super
|
64
|
+
end
|
65
|
+
|
66
|
+
def delete(key)
|
67
|
+
if has_key? key
|
68
|
+
index = @keys.index(key)
|
69
|
+
@keys.delete_at index
|
70
|
+
end
|
71
|
+
super
|
72
|
+
end
|
73
|
+
|
74
|
+
def delete_if
|
75
|
+
super
|
76
|
+
sync_keys!
|
77
|
+
self
|
78
|
+
end
|
79
|
+
|
80
|
+
def reject!
|
81
|
+
super
|
82
|
+
sync_keys!
|
83
|
+
self
|
84
|
+
end
|
85
|
+
|
86
|
+
def reject(&block)
|
87
|
+
dup.reject!(&block)
|
88
|
+
end
|
89
|
+
|
90
|
+
def keys
|
91
|
+
@keys.dup
|
92
|
+
end
|
93
|
+
|
94
|
+
def values
|
95
|
+
@keys.collect { |key| self[key] }
|
96
|
+
end
|
97
|
+
|
98
|
+
def to_hash
|
99
|
+
self
|
100
|
+
end
|
101
|
+
|
102
|
+
def to_a
|
103
|
+
@keys.map { |key| [ key, self[key] ] }
|
104
|
+
end
|
105
|
+
|
106
|
+
def each_key
|
107
|
+
@keys.each { |key| yield key }
|
108
|
+
end
|
109
|
+
|
110
|
+
def each_value
|
111
|
+
@keys.each { |key| yield self[key]}
|
112
|
+
end
|
113
|
+
|
114
|
+
def each
|
115
|
+
@keys.each {|key| yield [key, self[key]]}
|
116
|
+
end
|
117
|
+
|
118
|
+
alias_method :each_pair, :each
|
119
|
+
|
120
|
+
def clear
|
121
|
+
super
|
122
|
+
@keys.clear
|
123
|
+
self
|
124
|
+
end
|
125
|
+
|
126
|
+
def shift
|
127
|
+
k = @keys.first
|
128
|
+
v = delete(k)
|
129
|
+
[k, v]
|
130
|
+
end
|
131
|
+
|
132
|
+
def merge!(other_hash)
|
133
|
+
other_hash.each {|k,v| self[k] = v }
|
134
|
+
self
|
135
|
+
end
|
136
|
+
|
137
|
+
def merge(other_hash)
|
138
|
+
dup.merge!(other_hash)
|
139
|
+
end
|
140
|
+
|
141
|
+
# When replacing with another hash, the initial order of our keys must come from the other hash -ordered or not.
|
142
|
+
def replace(other)
|
143
|
+
super
|
144
|
+
@keys = other.keys
|
145
|
+
self
|
146
|
+
end
|
147
|
+
|
148
|
+
def inspect
|
149
|
+
"#<OrderedHash #{super}>"
|
150
|
+
end
|
151
|
+
|
152
|
+
private
|
153
|
+
def sync_keys!
|
154
|
+
@keys.delete_if {|k| !has_key?(k)}
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'active_support/ordered_hash'
|
2
|
+
|
3
|
+
module ActiveSupport #:nodoc:
|
4
|
+
class OrderedOptions < OrderedHash
|
5
|
+
def []=(key, value)
|
6
|
+
super(key.to_sym, value)
|
7
|
+
end
|
8
|
+
|
9
|
+
def [](key)
|
10
|
+
super(key.to_sym)
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(name, *args)
|
14
|
+
if name.to_s =~ /(.*)=$/
|
15
|
+
self[$1.to_sym] = args.first
|
16
|
+
else
|
17
|
+
self[name]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class InheritableOptions < OrderedOptions
|
23
|
+
def initialize(parent)
|
24
|
+
super() { |h,k| parent[k] }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "rails"
|
3
|
+
|
4
|
+
module ActiveSupport
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
config.active_support = ActiveSupport::OrderedOptions.new
|
7
|
+
|
8
|
+
# Loads support for "whiny nil" (noisy warnings when methods are invoked
|
9
|
+
# on +nil+ values) if Configuration#whiny_nils is true.
|
10
|
+
initializer "active_support.initialize_whiny_nils" do |app|
|
11
|
+
require 'active_support/whiny_nil' if app.config.whiny_nils
|
12
|
+
end
|
13
|
+
|
14
|
+
# Sets the default value for Time.zone
|
15
|
+
# If assigned value cannot be matched to a TimeZone, an exception will be raised.
|
16
|
+
initializer "active_support.initialize_time_zone" do |app|
|
17
|
+
require 'active_support/core_ext/time/zones'
|
18
|
+
zone_default = Time.__send__(:get_zone, app.config.time_zone)
|
19
|
+
|
20
|
+
unless zone_default
|
21
|
+
raise \
|
22
|
+
'Value assigned to config.time_zone not recognized.' +
|
23
|
+
'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
|
24
|
+
end
|
25
|
+
|
26
|
+
Time.zone_default = zone_default
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module I18n
|
32
|
+
class Railtie < Rails::Railtie
|
33
|
+
config.i18n = ActiveSupport::OrderedOptions.new
|
34
|
+
config.i18n.railties_load_path = []
|
35
|
+
config.i18n.load_path = []
|
36
|
+
config.i18n.fallbacks = ActiveSupport::OrderedOptions.new
|
37
|
+
|
38
|
+
initializer "i18n.initialize" do
|
39
|
+
ActiveSupport.on_load(:i18n) do
|
40
|
+
I18n.reload!
|
41
|
+
|
42
|
+
ActionDispatch::Callbacks.to_prepare do
|
43
|
+
I18n.reload!
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Set the i18n configuration from config.i18n but special-case for
|
49
|
+
# the load_path which should be appended to what's already set instead of overwritten.
|
50
|
+
config.after_initialize do |app|
|
51
|
+
fallbacks = app.config.i18n.delete(:fallbacks)
|
52
|
+
|
53
|
+
app.config.i18n.each do |setting, value|
|
54
|
+
case setting
|
55
|
+
when :railties_load_path
|
56
|
+
app.config.i18n.load_path.unshift(*value)
|
57
|
+
when :load_path
|
58
|
+
I18n.load_path += value
|
59
|
+
else
|
60
|
+
I18n.send("#{setting}=", value)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
init_fallbacks(fallbacks) if fallbacks && validate_fallbacks(fallbacks)
|
65
|
+
I18n.reload!
|
66
|
+
end
|
67
|
+
|
68
|
+
class << self
|
69
|
+
protected
|
70
|
+
|
71
|
+
def init_fallbacks(fallbacks)
|
72
|
+
include_fallbacks_module
|
73
|
+
args = case fallbacks
|
74
|
+
when ActiveSupport::OrderedOptions
|
75
|
+
[*(fallbacks[:defaults] || []) << fallbacks[:map]].compact
|
76
|
+
when Hash, Array
|
77
|
+
Array.wrap(fallbacks)
|
78
|
+
else # TrueClass
|
79
|
+
[]
|
80
|
+
end
|
81
|
+
I18n.fallbacks = I18n::Locale::Fallbacks.new(*args)
|
82
|
+
end
|
83
|
+
|
84
|
+
def include_fallbacks_module
|
85
|
+
I18n.backend.class.send(:include, I18n::Backend::Fallbacks)
|
86
|
+
end
|
87
|
+
|
88
|
+
def validate_fallbacks(fallbacks)
|
89
|
+
case fallbacks
|
90
|
+
when ActiveSupport::OrderedOptions
|
91
|
+
!fallbacks.empty?
|
92
|
+
when TrueClass, Array, Hash
|
93
|
+
true
|
94
|
+
else
|
95
|
+
raise "Unexpected fallback type #{fallbacks.inspect}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|