swivel 0.0.146 → 0.0.149
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -1
- data/Rakefile +1 -1
- data/lib/swivel.rb +1 -1
- data/lib/swivel2/benchmarking.rb +1 -0
- data/lib/swivel2/config.rb +45 -0
- data/lib/swivel2/connection.rb +89 -0
- data/lib/swivel2/formats.rb +11 -0
- data/lib/swivel2/logging.rb +1 -0
- data/lib/swivel2/performance.rb +21 -0
- data/lib/swivel2/response.rb +5 -0
- data/lib/swivel2/swivelrc.default +5 -0
- data/vendor/activeresource-2.0.2-/CHANGELOG +223 -0
- data/vendor/activeresource-2.0.2-/README +165 -0
- data/vendor/activeresource-2.0.2-/Rakefile +133 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource.rb +47 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/base.rb +872 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/connection.rb +172 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/custom_methods.rb +105 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/formats.rb +14 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/formats/json_format.rb +23 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/formats/xml_format.rb +34 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/http_mock.rb +147 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/validations.rb +288 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/version.rb +9 -0
- data/vendor/activeresource-2.0.2-/lib/activeresource.rb +1 -0
- data/vendor/activeresource-2.0.2-/test/abstract_unit.rb +10 -0
- data/vendor/activeresource-2.0.2-/test/authorization_test.rb +82 -0
- data/vendor/activeresource-2.0.2-/test/base/custom_methods_test.rb +96 -0
- data/vendor/activeresource-2.0.2-/test/base/equality_test.rb +43 -0
- data/vendor/activeresource-2.0.2-/test/base/load_test.rb +111 -0
- data/vendor/activeresource-2.0.2-/test/base_errors_test.rb +48 -0
- data/vendor/activeresource-2.0.2-/test/base_test.rb +454 -0
- data/vendor/activeresource-2.0.2-/test/connection_test.rb +170 -0
- data/vendor/activeresource-2.0.2-/test/fixtures/beast.rb +14 -0
- data/vendor/activeresource-2.0.2-/test/fixtures/person.rb +3 -0
- data/vendor/activeresource-2.0.2-/test/fixtures/street_address.rb +4 -0
- data/vendor/activeresource-2.0.2-/test/format_test.rb +42 -0
- data/vendor/activeresource-2.0.2-/test/setter_trap.rb +27 -0
- data/vendor/activesupport-2.0.2-/CHANGELOG +986 -0
- data/vendor/activesupport-2.0.2-/README +43 -0
- data/vendor/activesupport-2.0.2-/lib/active_support.rb +49 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/basic_object.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/buffered_logger.rb +107 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/clean_logger.rb +127 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext.rb +4 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/access.rb +28 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/conversions.rb +94 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/extract_options.rb +19 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/grouping.rb +68 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/random_access.rb +12 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/bigdecimal.rb +2 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/bigdecimal/conversions.rb +6 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/blank.rb +50 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/cgi.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +14 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class.rb +4 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/attribute_accessors.rb +48 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/delegating_attributes.rb +40 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/inheritable_attributes.rb +140 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/removal.rb +24 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date.rb +10 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date/behavior.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date/calculations.rb +188 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date/conversions.rb +98 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date_time.rb +10 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date_time/calculations.rb +77 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date_time/conversions.rb +74 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/duplicable.rb +37 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/enumerable.rb +63 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/exception.rb +33 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/file.rb +21 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/float.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/float/rounding.rb +24 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/conversions.rb +242 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/diff.rb +19 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/except.rb +24 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/indifferent_access.rb +102 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/keys.rb +54 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/reverse_merge.rb +25 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/slice.rb +28 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/integer.rb +7 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/integer/even_odd.rb +24 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/integer/inflections.rb +21 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/agnostics.rb +11 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/daemonizing.rb +15 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/debugger.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/reporting.rb +51 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/requires.rb +24 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/load_error.rb +38 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/logger.rb +16 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module.rb +8 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/aliasing.rb +70 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/attr_accessor_with_default.rb +31 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/attr_internal.rb +31 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/attribute_accessors.rb +48 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/delegation.rb +62 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/inclusion.rb +11 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/introspection.rb +35 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/loading.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/name_error.rb +17 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/numeric.rb +7 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/numeric/bytes.rb +44 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/numeric/time.rb +91 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object.rb +4 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/conversions.rb +14 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/extending.rb +58 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/instance_variables.rb +22 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/misc.rb +59 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/pathname.rb +7 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/pathname/clean_within.rb +14 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/proc.rb +12 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range.rb +11 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/blockless_step.rb +22 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/conversions.rb +23 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/include_range.rb +22 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/overlaps.rb +12 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string.rb +23 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/access.rb +58 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/conversions.rb +28 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/inflections.rb +153 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/iterators.rb +17 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/starts_ends_with.rb +27 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/unicode.rb +42 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/xchar.rb +11 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/symbol.rb +14 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/test.rb +1 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/test/unit/assertions.rb +62 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time.rb +19 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time/behavior.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time/calculations.rb +224 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time/conversions.rb +94 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/dependencies.rb +540 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/deprecation.rb +204 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/duration.rb +96 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/inflections.rb +53 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/inflector.rb +282 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json.rb +31 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/decoding.rb +60 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/date.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/date_time.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/enumerable.rb +12 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/false_class.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/hash.rb +50 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/nil_class.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/numeric.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/object.rb +6 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/regexp.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/string.rb +30 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/symbol.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/time.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/true_class.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoding.rb +38 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/variable.rb +10 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte.rb +9 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/chars.rb +141 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/generators/generate_tables.rb +149 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/handlers/passthru_handler.rb +9 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/handlers/utf8_handler.rb +564 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/handlers/utf8_handler_proc.rb +43 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/option_merger.rb +25 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/ordered_options.rb +49 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/test_case.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/testing.rb +1 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/testing/default.rb +12 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/values/time_zone.rb +181 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/values/unicode_tables.dat +0 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor.rb +14 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/blankslate.rb +113 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +20 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/css.rb +250 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +115 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +139 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +63 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +328 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb +1021 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/version.rb +9 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/whiny_nil.rb +38 -0
- data/vendor/activesupport-2.0.2-/lib/activesupport.rb +1 -0
- metadata +222 -2
@@ -0,0 +1,43 @@
|
|
1
|
+
= Active Support -- Utility classes and standard library extensions from Rails
|
2
|
+
|
3
|
+
Active Support is a collection of various utility classes and standard library extensions that were found useful
|
4
|
+
for Rails. All these additions have hence been collected in this bundle as way to gather all that sugar that makes
|
5
|
+
Ruby sweeter.
|
6
|
+
|
7
|
+
|
8
|
+
== Download
|
9
|
+
|
10
|
+
The latest version of Active Support can be found at
|
11
|
+
|
12
|
+
* http://rubyforge.org/project/showfiles.php?group_id=182
|
13
|
+
|
14
|
+
Documentation can be found at
|
15
|
+
|
16
|
+
* http://as.rubyonrails.com
|
17
|
+
|
18
|
+
|
19
|
+
== Installation
|
20
|
+
|
21
|
+
The preferred method of installing Active Support is through its GEM file. You'll need to have
|
22
|
+
RubyGems[http://rubygems.rubyforge.org/wiki/wiki.pl] installed for that, though. If you have it,
|
23
|
+
then use:
|
24
|
+
|
25
|
+
% [sudo] gem install activesupport-1.0.0.gem
|
26
|
+
|
27
|
+
|
28
|
+
== License
|
29
|
+
|
30
|
+
Active Support is released under the MIT license.
|
31
|
+
|
32
|
+
|
33
|
+
== Support
|
34
|
+
|
35
|
+
The Active Support homepage is http://www.rubyonrails.com. You can find the Active Support
|
36
|
+
RubyForge page at http://rubyforge.org/projects/activesupport. And as Jim from Rake says:
|
37
|
+
|
38
|
+
Feel free to submit commits or feature requests. If you send a patch,
|
39
|
+
remember to update the corresponding unit tests. If fact, I prefer
|
40
|
+
new feature to be submitted in the form of new unit tests.
|
41
|
+
|
42
|
+
For other information, feel free to ask on the ruby-talk mailing list
|
43
|
+
(which is mirrored to comp.lang.ruby) or contact mailto:david@loudthinking.com.
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2005 David Heinemeier Hansson
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
$:.unshift(File.dirname(__FILE__))
|
25
|
+
|
26
|
+
require 'active_support/vendor'
|
27
|
+
require 'active_support/basic_object'
|
28
|
+
require 'active_support/inflector'
|
29
|
+
|
30
|
+
require 'active_support/core_ext'
|
31
|
+
|
32
|
+
require 'active_support/clean_logger'
|
33
|
+
require 'active_support/buffered_logger'
|
34
|
+
|
35
|
+
require 'active_support/dependencies'
|
36
|
+
require 'active_support/deprecation'
|
37
|
+
|
38
|
+
require 'active_support/ordered_options'
|
39
|
+
require 'active_support/option_merger'
|
40
|
+
|
41
|
+
require 'active_support/values/time_zone'
|
42
|
+
require 'active_support/duration'
|
43
|
+
|
44
|
+
require 'active_support/json'
|
45
|
+
|
46
|
+
require 'active_support/multibyte'
|
47
|
+
|
48
|
+
require 'active_support/testing'
|
49
|
+
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module ActiveSupport
|
2
|
+
# Inspired by the buffered logger idea by Ezra
|
3
|
+
class BufferedLogger
|
4
|
+
module Severity
|
5
|
+
DEBUG = 0
|
6
|
+
INFO = 1
|
7
|
+
WARN = 2
|
8
|
+
ERROR = 3
|
9
|
+
FATAL = 4
|
10
|
+
UNKNOWN = 5
|
11
|
+
end
|
12
|
+
include Severity
|
13
|
+
|
14
|
+
MAX_BUFFER_SIZE = 1000
|
15
|
+
|
16
|
+
# Set to false to disable the silencer
|
17
|
+
cattr_accessor :silencer
|
18
|
+
self.silencer = true
|
19
|
+
|
20
|
+
# Silences the logger for the duration of the block.
|
21
|
+
def silence(temporary_level = ERROR)
|
22
|
+
if silencer
|
23
|
+
begin
|
24
|
+
old_logger_level, self.level = level, temporary_level
|
25
|
+
yield self
|
26
|
+
ensure
|
27
|
+
self.level = old_logger_level
|
28
|
+
end
|
29
|
+
else
|
30
|
+
yield self
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
attr_accessor :level
|
35
|
+
attr_reader :auto_flushing
|
36
|
+
attr_reader :buffer
|
37
|
+
|
38
|
+
def initialize(log, level = DEBUG)
|
39
|
+
@level = level
|
40
|
+
@buffer = []
|
41
|
+
@auto_flushing = 1
|
42
|
+
|
43
|
+
if log.respond_to?(:write)
|
44
|
+
@log = log
|
45
|
+
elsif File.exist?(log)
|
46
|
+
@log = open(log, (File::WRONLY | File::APPEND))
|
47
|
+
@log.sync = true
|
48
|
+
else
|
49
|
+
@log = open(log, (File::WRONLY | File::APPEND | File::CREAT))
|
50
|
+
@log.sync = true
|
51
|
+
@log.write("# Logfile created on %s" % [Time.now.to_s])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def add(severity, message = nil, progname = nil, &block)
|
56
|
+
return if @level > severity
|
57
|
+
message = (message || (block && block.call) || progname).to_s
|
58
|
+
# If a newline is necessary then create a new message ending with a newline.
|
59
|
+
# Ensures that the original message is not mutated.
|
60
|
+
message = "#{message}\n" unless message[-1] == ?\n
|
61
|
+
@buffer << message
|
62
|
+
auto_flush
|
63
|
+
message
|
64
|
+
end
|
65
|
+
|
66
|
+
for severity in Severity.constants
|
67
|
+
class_eval <<-EOT, __FILE__, __LINE__
|
68
|
+
def #{severity.downcase}(message = nil, progname = nil, &block)
|
69
|
+
add(#{severity}, message, progname, &block)
|
70
|
+
end
|
71
|
+
|
72
|
+
def #{severity.downcase}?
|
73
|
+
#{severity} >= @level
|
74
|
+
end
|
75
|
+
EOT
|
76
|
+
end
|
77
|
+
|
78
|
+
# Set the auto-flush period. Set to true to flush after every log message,
|
79
|
+
# to an integer to flush every N messages, or to false, nil, or zero to
|
80
|
+
# never auto-flush. If you turn auto-flushing off, be sure to regularly
|
81
|
+
# flush the log yourself -- it will eat up memory until you do.
|
82
|
+
def auto_flushing=(period)
|
83
|
+
@auto_flushing =
|
84
|
+
case period
|
85
|
+
when true; 1
|
86
|
+
when false, nil, 0; MAX_BUFFER_SIZE
|
87
|
+
when Integer; period
|
88
|
+
else raise ArgumentError, "Unrecognized auto_flushing period: #{period.inspect}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def flush
|
93
|
+
@log.write(@buffer.slice!(0..-1).to_s) unless @buffer.empty?
|
94
|
+
end
|
95
|
+
|
96
|
+
def close
|
97
|
+
flush
|
98
|
+
@log.close if @log.respond_to?(:close)
|
99
|
+
@log = nil
|
100
|
+
end
|
101
|
+
|
102
|
+
protected
|
103
|
+
def auto_flush
|
104
|
+
flush if @buffer.size >= @auto_flushing
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'active_support/core_ext/class/attribute_accessors'
|
3
|
+
|
4
|
+
# Extensions to the built in Ruby logger.
|
5
|
+
#
|
6
|
+
# If you want to use the default log formatter as defined in the Ruby core, then you
|
7
|
+
# will need to set the formatter for the logger as in:
|
8
|
+
#
|
9
|
+
# logger.formatter = Formatter.new
|
10
|
+
#
|
11
|
+
# You can then specify the datetime format, for example:
|
12
|
+
#
|
13
|
+
# logger.datetime_format = "%Y-%m-%d"
|
14
|
+
#
|
15
|
+
# Note: This logger is deprecated in favor of ActiveSupport::BufferedLogger
|
16
|
+
class Logger
|
17
|
+
# Set to false to disable the silencer
|
18
|
+
cattr_accessor :silencer
|
19
|
+
self.silencer = true
|
20
|
+
|
21
|
+
# Silences the logger for the duration of the block.
|
22
|
+
def silence(temporary_level = Logger::ERROR)
|
23
|
+
if silencer
|
24
|
+
begin
|
25
|
+
old_logger_level, self.level = level, temporary_level
|
26
|
+
yield self
|
27
|
+
ensure
|
28
|
+
self.level = old_logger_level
|
29
|
+
end
|
30
|
+
else
|
31
|
+
yield self
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
alias :old_datetime_format= :datetime_format=
|
36
|
+
# Logging date-time format (string passed to +strftime+). Ignored if the formatter
|
37
|
+
# does not respond to datetime_format=.
|
38
|
+
def datetime_format=(datetime_format)
|
39
|
+
formatter.datetime_format = datetime_format if formatter.respond_to?(:datetime_format=)
|
40
|
+
end
|
41
|
+
|
42
|
+
alias :old_datetime_format :datetime_format
|
43
|
+
# Get the logging datetime format. Returns nil if the formatter does not support
|
44
|
+
# datetime formatting.
|
45
|
+
def datetime_format
|
46
|
+
formatter.datetime_format if formatter.respond_to?(:datetime_format)
|
47
|
+
end
|
48
|
+
|
49
|
+
alias :old_formatter :formatter if method_defined?(:formatter)
|
50
|
+
# Get the current formatter. The default formatter is a SimpleFormatter which only
|
51
|
+
# displays the log message
|
52
|
+
def formatter
|
53
|
+
@formatter ||= SimpleFormatter.new
|
54
|
+
end
|
55
|
+
|
56
|
+
unless const_defined? :Formatter
|
57
|
+
class Formatter
|
58
|
+
Format = "%s, [%s#%d] %5s -- %s: %s\n"
|
59
|
+
|
60
|
+
attr_accessor :datetime_format
|
61
|
+
|
62
|
+
def initialize
|
63
|
+
@datetime_format = nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def call(severity, time, progname, msg)
|
67
|
+
Format % [severity[0..0], format_datetime(time), $$, severity, progname,
|
68
|
+
msg2str(msg)]
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
def format_datetime(time)
|
73
|
+
if @datetime_format.nil?
|
74
|
+
time.strftime("%Y-%m-%dT%H:%M:%S.") << "%06d " % time.usec
|
75
|
+
else
|
76
|
+
time.strftime(@datetime_format)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def msg2str(msg)
|
81
|
+
case msg
|
82
|
+
when ::String
|
83
|
+
msg
|
84
|
+
when ::Exception
|
85
|
+
"#{ msg.message } (#{ msg.class })\n" <<
|
86
|
+
(msg.backtrace || []).join("\n")
|
87
|
+
else
|
88
|
+
msg.inspect
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Simple formatter which only displays the message.
|
95
|
+
class SimpleFormatter < Logger::Formatter
|
96
|
+
# This method is invoked when a log event occurs
|
97
|
+
def call(severity, timestamp, progname, msg)
|
98
|
+
"#{String === msg ? msg : msg.inspect}\n"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
alias old_format_message format_message
|
104
|
+
|
105
|
+
# Ruby 1.8.3 transposed the msg and progname arguments to format_message.
|
106
|
+
# We can't test RUBY_VERSION because some distributions don't keep Ruby
|
107
|
+
# and its standard library in sync, leading to installations of Ruby 1.8.2
|
108
|
+
# with Logger from 1.8.3 and vice versa.
|
109
|
+
if method_defined?(:formatter=)
|
110
|
+
def format_message(severity, timestamp, progname, msg)
|
111
|
+
formatter.call(severity, timestamp, progname, msg)
|
112
|
+
end
|
113
|
+
else
|
114
|
+
def format_message(severity, timestamp, msg, progname)
|
115
|
+
formatter.call(severity, timestamp, progname, msg)
|
116
|
+
end
|
117
|
+
|
118
|
+
attr_writer :formatter
|
119
|
+
public :formatter=
|
120
|
+
|
121
|
+
alias old_format_datetime format_datetime
|
122
|
+
def format_datetime(datetime) datetime end
|
123
|
+
|
124
|
+
alias old_msg2str msg2str
|
125
|
+
def msg2str(msg) msg end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'active_support/core_ext/array/access'
|
2
|
+
require 'active_support/core_ext/array/conversions'
|
3
|
+
require 'active_support/core_ext/array/extract_options'
|
4
|
+
require 'active_support/core_ext/array/grouping'
|
5
|
+
require 'active_support/core_ext/array/random_access'
|
6
|
+
|
7
|
+
class Array #:nodoc:
|
8
|
+
include ActiveSupport::CoreExtensions::Array::Access
|
9
|
+
include ActiveSupport::CoreExtensions::Array::Conversions
|
10
|
+
include ActiveSupport::CoreExtensions::Array::ExtractOptions
|
11
|
+
include ActiveSupport::CoreExtensions::Array::Grouping
|
12
|
+
include ActiveSupport::CoreExtensions::Array::RandomAccess
|
13
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ActiveSupport #:nodoc:
|
2
|
+
module CoreExtensions #:nodoc:
|
3
|
+
module Array #:nodoc:
|
4
|
+
# Makes it easier to access parts of an array.
|
5
|
+
module Access
|
6
|
+
# Returns the remaining of the array from the +position+.
|
7
|
+
#
|
8
|
+
# Examples:
|
9
|
+
# %w( a b c d ).from(0) # => %w( a b c d )
|
10
|
+
# %w( a b c d ).from(2) # => %w( c d )
|
11
|
+
# %w( a b c d ).from(10) # => nil
|
12
|
+
def from(position)
|
13
|
+
self[position..-1]
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns the beginning of the array up to the +position+.
|
17
|
+
#
|
18
|
+
# Examples:
|
19
|
+
# %w( a b c d ).to(0) # => %w( a )
|
20
|
+
# %w( a b c d ).to(2) # => %w( a b c )
|
21
|
+
# %w( a b c d ).to(10) # => %w( a b c d )
|
22
|
+
def to(position)
|
23
|
+
self[0..position]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'builder'
|
2
|
+
|
3
|
+
module ActiveSupport #:nodoc:
|
4
|
+
module CoreExtensions #:nodoc:
|
5
|
+
module Array #:nodoc:
|
6
|
+
module Conversions
|
7
|
+
# Converts the array to a comma-separated sentence where the last element is joined by the connector word. Options:
|
8
|
+
# * <tt>:connector</tt> - The word used to join the last element in arrays with two or more elements (default: "and")
|
9
|
+
# * <tt>:skip_last_comma</tt> - Set to true to return "a, b and c" instead of "a, b, and c".
|
10
|
+
def to_sentence(options = {})
|
11
|
+
options.assert_valid_keys(:connector, :skip_last_comma)
|
12
|
+
options.reverse_merge! :connector => 'and', :skip_last_comma => false
|
13
|
+
options[:connector] = "#{options[:connector]} " unless options[:connector].nil? || options[:connector].strip == ''
|
14
|
+
|
15
|
+
case length
|
16
|
+
when 0
|
17
|
+
""
|
18
|
+
when 1
|
19
|
+
self[0].to_s
|
20
|
+
when 2
|
21
|
+
"#{self[0]} #{options[:connector]}#{self[1]}"
|
22
|
+
else
|
23
|
+
"#{self[0...-1].join(', ')}#{options[:skip_last_comma] ? '' : ','} #{options[:connector]}#{self[-1]}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Calls to_param on all its elements and joins the result with slashes. This is used by url_for in Action Pack.
|
28
|
+
def to_param
|
29
|
+
map(&:to_param).join '/'
|
30
|
+
end
|
31
|
+
|
32
|
+
# Converts an array into a string suitable for use as a URL query string, using the given <tt>key</tt> as the
|
33
|
+
# param name.
|
34
|
+
#
|
35
|
+
# ==== Example:
|
36
|
+
# ['Rails', 'coding'].to_query('hobbies') => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding"
|
37
|
+
def to_query(key)
|
38
|
+
collect { |value| value.to_query("#{key}[]") } * '&'
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.included(base) #:nodoc:
|
42
|
+
base.class_eval do
|
43
|
+
alias_method :to_default_s, :to_s
|
44
|
+
alias_method :to_s, :to_formatted_s
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_formatted_s(format = :default)
|
49
|
+
case format
|
50
|
+
when :db
|
51
|
+
if respond_to?(:empty?) && self.empty?
|
52
|
+
"null"
|
53
|
+
else
|
54
|
+
collect { |element| element.id }.join(",")
|
55
|
+
end
|
56
|
+
else
|
57
|
+
to_default_s
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_xml(options = {})
|
62
|
+
raise "Not all elements respond to to_xml" unless all? { |e| e.respond_to? :to_xml }
|
63
|
+
|
64
|
+
options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize : "records"
|
65
|
+
options[:children] ||= options[:root].singularize
|
66
|
+
options[:indent] ||= 2
|
67
|
+
options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
|
68
|
+
|
69
|
+
root = options.delete(:root).to_s
|
70
|
+
children = options.delete(:children)
|
71
|
+
|
72
|
+
if !options.has_key?(:dasherize) || options[:dasherize]
|
73
|
+
root = root.dasherize
|
74
|
+
end
|
75
|
+
|
76
|
+
options[:builder].instruct! unless options.delete(:skip_instruct)
|
77
|
+
|
78
|
+
opts = options.merge({ :root => children })
|
79
|
+
|
80
|
+
xml = options[:builder]
|
81
|
+
if empty?
|
82
|
+
xml.tag!(root, options[:skip_types] ? {} : {:type => "array"})
|
83
|
+
else
|
84
|
+
xml.tag!(root, options[:skip_types] ? {} : {:type => "array"}) {
|
85
|
+
yield xml if block_given?
|
86
|
+
each { |e| e.to_xml(opts.merge!({ :skip_instruct => true })) }
|
87
|
+
}
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|