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
|
+
# Methods in this handler call functions in the utf8proc ruby extension. These are significantly faster than the
|
2
|
+
# pure ruby versions. Chars automatically uses this handler when it can load the utf8proc extension. For
|
3
|
+
# documentation on handler methods see UTF8Handler.
|
4
|
+
class ActiveSupport::Multibyte::Handlers::UTF8HandlerProc < ActiveSupport::Multibyte::Handlers::UTF8Handler #:nodoc:
|
5
|
+
class << self
|
6
|
+
def normalize(str, form=ActiveSupport::Multibyte::DEFAULT_NORMALIZATION_FORM) #:nodoc:
|
7
|
+
codepoints = str.unpack('U*')
|
8
|
+
case form
|
9
|
+
when :d
|
10
|
+
utf8map(str, :stable)
|
11
|
+
when :c
|
12
|
+
utf8map(str, :stable, :compose)
|
13
|
+
when :kd
|
14
|
+
utf8map(str, :stable, :compat)
|
15
|
+
when :kc
|
16
|
+
utf8map(str, :stable, :compose, :compat)
|
17
|
+
else
|
18
|
+
raise ArgumentError, "#{form} is not a valid normalization variant", caller
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def decompose(str) #:nodoc:
|
23
|
+
utf8map(str, :stable)
|
24
|
+
end
|
25
|
+
|
26
|
+
def downcase(str) #:nodoc:c
|
27
|
+
utf8map(str, :casefold)
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def utf8map(str, *option_array) #:nodoc:
|
33
|
+
options = 0
|
34
|
+
option_array.each do |option|
|
35
|
+
flag = Utf8Proc::Options[option]
|
36
|
+
raise ArgumentError, "Unknown argument given to utf8map." unless
|
37
|
+
flag
|
38
|
+
options |= flag
|
39
|
+
end
|
40
|
+
return Utf8Proc::utf8map(str, options)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ActiveSupport
|
2
|
+
class OptionMerger #:nodoc:
|
3
|
+
instance_methods.each do |method|
|
4
|
+
undef_method(method) if method !~ /^(__|instance_eval|class|object_id)/
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(context, options)
|
8
|
+
@context, @options = context, options
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def method_missing(method, *arguments, &block)
|
13
|
+
merge_argument_options! arguments
|
14
|
+
@context.send!(method, *arguments, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def merge_argument_options!(arguments)
|
18
|
+
arguments << if arguments.last.respond_to? :to_hash
|
19
|
+
@options.merge(arguments.pop)
|
20
|
+
else
|
21
|
+
@options.dup
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# OrderedHash is namespaced to prevent conflicts with other implementations
|
2
|
+
module ActiveSupport
|
3
|
+
# Hash is ordered in Ruby 1.9!
|
4
|
+
if RUBY_VERSION >= '1.9'
|
5
|
+
OrderedHash = ::Hash
|
6
|
+
else
|
7
|
+
class OrderedHash < Array #:nodoc:
|
8
|
+
def []=(key, value)
|
9
|
+
if pair = assoc(key)
|
10
|
+
pair.pop
|
11
|
+
pair << value
|
12
|
+
else
|
13
|
+
self << [key, value]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def [](key)
|
18
|
+
pair = assoc(key)
|
19
|
+
pair ? pair.last : nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def keys
|
23
|
+
collect { |key, value| key }
|
24
|
+
end
|
25
|
+
|
26
|
+
def values
|
27
|
+
collect { |key, value| value }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class OrderedOptions < ActiveSupport::OrderedHash #:nodoc:
|
34
|
+
def []=(key, value)
|
35
|
+
super(key.to_sym, value)
|
36
|
+
end
|
37
|
+
|
38
|
+
def [](key)
|
39
|
+
super(key.to_sym)
|
40
|
+
end
|
41
|
+
|
42
|
+
def method_missing(name, *args)
|
43
|
+
if name.to_s =~ /(.*)=$/
|
44
|
+
self[$1.to_sym] = args.first
|
45
|
+
else
|
46
|
+
self[name]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'active_support/testing/default'
|
@@ -0,0 +1,181 @@
|
|
1
|
+
# A value object representing a time zone. A time zone is simply a named
|
2
|
+
# offset (in seconds) from GMT. Note that two time zone objects are only
|
3
|
+
# equivalent if they have both the same offset, and the same name.
|
4
|
+
#
|
5
|
+
# A TimeZone instance may be used to convert a Time value to the corresponding
|
6
|
+
# time zone.
|
7
|
+
#
|
8
|
+
# The class also includes #all, which returns a list of all TimeZone objects.
|
9
|
+
class TimeZone
|
10
|
+
include Comparable
|
11
|
+
|
12
|
+
attr_reader :name, :utc_offset
|
13
|
+
|
14
|
+
# Create a new TimeZone object with the given name and offset. The offset is
|
15
|
+
# the number of seconds that this time zone is offset from UTC (GMT). Seconds
|
16
|
+
# were chosen as the offset unit because that is the unit that Ruby uses
|
17
|
+
# to represent time zone offsets (see Time#utc_offset).
|
18
|
+
def initialize(name, utc_offset)
|
19
|
+
@name = name
|
20
|
+
@utc_offset = utc_offset
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns the offset of this time zone as a formatted string, of the
|
24
|
+
# format "+HH:MM". If the offset is zero, this returns the empty
|
25
|
+
# string. If +colon+ is false, a colon will not be inserted into the
|
26
|
+
# result.
|
27
|
+
def formatted_offset( colon=true )
|
28
|
+
return "" if utc_offset == 0
|
29
|
+
sign = (utc_offset < 0 ? -1 : 1)
|
30
|
+
hours = utc_offset.abs / 3600
|
31
|
+
minutes = (utc_offset.abs % 3600) / 60
|
32
|
+
"%+03d%s%02d" % [ hours * sign, colon ? ":" : "", minutes ]
|
33
|
+
end
|
34
|
+
|
35
|
+
# Compute and return the current time, in the time zone represented by
|
36
|
+
# +self+.
|
37
|
+
def now
|
38
|
+
adjust(Time.now)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Return the current date in this time zone.
|
42
|
+
def today
|
43
|
+
now.to_date
|
44
|
+
end
|
45
|
+
|
46
|
+
# Adjust the given time to the time zone represented by +self+.
|
47
|
+
def adjust(time)
|
48
|
+
time = time.to_time unless time.is_a?(::Time)
|
49
|
+
time + utc_offset - time.utc_offset
|
50
|
+
end
|
51
|
+
|
52
|
+
# Reinterprets the given time value as a time in the current time
|
53
|
+
# zone, and then adjusts it to return the corresponding time in the
|
54
|
+
# local time zone.
|
55
|
+
def unadjust(time)
|
56
|
+
time = time.to_time unless time.is_a?(::Time)
|
57
|
+
time = time.localtime
|
58
|
+
time - utc_offset - time.utc_offset
|
59
|
+
end
|
60
|
+
|
61
|
+
# Compare this time zone to the parameter. The two are comapred first on
|
62
|
+
# their offsets, and then by name.
|
63
|
+
def <=>(zone)
|
64
|
+
result = (utc_offset <=> zone.utc_offset)
|
65
|
+
result = (name <=> zone.name) if result == 0
|
66
|
+
result
|
67
|
+
end
|
68
|
+
|
69
|
+
# Returns a textual representation of this time zone.
|
70
|
+
def to_s
|
71
|
+
"(UTC#{formatted_offset}) #{name}"
|
72
|
+
end
|
73
|
+
|
74
|
+
@@zones = nil
|
75
|
+
|
76
|
+
class << self
|
77
|
+
# Create a new TimeZone instance with the given name and offset.
|
78
|
+
def create(name, offset)
|
79
|
+
zone = allocate
|
80
|
+
zone.send!(:initialize, name, offset)
|
81
|
+
zone
|
82
|
+
end
|
83
|
+
|
84
|
+
# Return a TimeZone instance with the given name, or +nil+ if no
|
85
|
+
# such TimeZone instance exists. (This exists to support the use of
|
86
|
+
# this class with the #composed_of macro.)
|
87
|
+
def new(name)
|
88
|
+
self[name]
|
89
|
+
end
|
90
|
+
|
91
|
+
# Return an array of all TimeZone objects. There are multiple TimeZone
|
92
|
+
# objects per time zone, in many cases, to make it easier for users to
|
93
|
+
# find their own time zone.
|
94
|
+
def all
|
95
|
+
unless @@zones
|
96
|
+
@@zones = []
|
97
|
+
[[-43_200, "International Date Line West" ],
|
98
|
+
[-39_600, "Midway Island", "Samoa" ],
|
99
|
+
[-36_000, "Hawaii" ],
|
100
|
+
[-32_400, "Alaska" ],
|
101
|
+
[-28_800, "Pacific Time (US & Canada)", "Tijuana" ],
|
102
|
+
[-25_200, "Mountain Time (US & Canada)", "Chihuahua", "Mazatlan",
|
103
|
+
"Arizona" ],
|
104
|
+
[-21_600, "Central Time (US & Canada)", "Saskatchewan", "Guadalajara",
|
105
|
+
"Mexico City", "Monterrey", "Central America" ],
|
106
|
+
[-18_000, "Eastern Time (US & Canada)", "Indiana (East)", "Bogota",
|
107
|
+
"Lima", "Quito" ],
|
108
|
+
[-14_400, "Atlantic Time (Canada)", "Caracas", "La Paz", "Santiago" ],
|
109
|
+
[-12_600, "Newfoundland" ],
|
110
|
+
[-10_800, "Brasilia", "Buenos Aires", "Georgetown", "Greenland" ],
|
111
|
+
[ -7_200, "Mid-Atlantic" ],
|
112
|
+
[ -3_600, "Azores", "Cape Verde Is." ],
|
113
|
+
[ 0, "Dublin", "Edinburgh", "Lisbon", "London", "Casablanca",
|
114
|
+
"Monrovia" ],
|
115
|
+
[ 3_600, "Belgrade", "Bratislava", "Budapest", "Ljubljana", "Prague",
|
116
|
+
"Sarajevo", "Skopje", "Warsaw", "Zagreb", "Brussels",
|
117
|
+
"Copenhagen", "Madrid", "Paris", "Amsterdam", "Berlin",
|
118
|
+
"Bern", "Rome", "Stockholm", "Vienna",
|
119
|
+
"West Central Africa" ],
|
120
|
+
[ 7_200, "Bucharest", "Cairo", "Helsinki", "Kyev", "Riga", "Sofia",
|
121
|
+
"Tallinn", "Vilnius", "Athens", "Istanbul", "Minsk",
|
122
|
+
"Jerusalem", "Harare", "Pretoria" ],
|
123
|
+
[ 10_800, "Moscow", "St. Petersburg", "Volgograd", "Kuwait", "Riyadh",
|
124
|
+
"Nairobi", "Baghdad" ],
|
125
|
+
[ 12_600, "Tehran" ],
|
126
|
+
[ 14_400, "Abu Dhabi", "Muscat", "Baku", "Tbilisi", "Yerevan" ],
|
127
|
+
[ 16_200, "Kabul" ],
|
128
|
+
[ 18_000, "Ekaterinburg", "Islamabad", "Karachi", "Tashkent" ],
|
129
|
+
[ 19_800, "Chennai", "Kolkata", "Mumbai", "New Delhi" ],
|
130
|
+
[ 20_700, "Kathmandu" ],
|
131
|
+
[ 21_600, "Astana", "Dhaka", "Sri Jayawardenepura", "Almaty",
|
132
|
+
"Novosibirsk" ],
|
133
|
+
[ 23_400, "Rangoon" ],
|
134
|
+
[ 25_200, "Bangkok", "Hanoi", "Jakarta", "Krasnoyarsk" ],
|
135
|
+
[ 28_800, "Beijing", "Chongqing", "Hong Kong", "Urumqi",
|
136
|
+
"Kuala Lumpur", "Singapore", "Taipei", "Perth", "Irkutsk",
|
137
|
+
"Ulaan Bataar" ],
|
138
|
+
[ 32_400, "Seoul", "Osaka", "Sapporo", "Tokyo", "Yakutsk" ],
|
139
|
+
[ 34_200, "Darwin", "Adelaide" ],
|
140
|
+
[ 36_000, "Canberra", "Melbourne", "Sydney", "Brisbane", "Hobart",
|
141
|
+
"Vladivostok", "Guam", "Port Moresby" ],
|
142
|
+
[ 39_600, "Magadan", "Solomon Is.", "New Caledonia" ],
|
143
|
+
[ 43_200, "Fiji", "Kamchatka", "Marshall Is.", "Auckland",
|
144
|
+
"Wellington" ],
|
145
|
+
[ 46_800, "Nuku'alofa" ]].
|
146
|
+
each do |offset, *places|
|
147
|
+
places.each { |place| @@zones << create(place, offset).freeze }
|
148
|
+
end
|
149
|
+
@@zones.sort!
|
150
|
+
end
|
151
|
+
@@zones
|
152
|
+
end
|
153
|
+
|
154
|
+
# Locate a specific time zone object. If the argument is a string, it
|
155
|
+
# is interpreted to mean the name of the timezone to locate. If it is a
|
156
|
+
# numeric value it is either the hour offset, or the second offset, of the
|
157
|
+
# timezone to find. (The first one with that offset will be returned.)
|
158
|
+
# Returns +nil+ if no such time zone is known to the system.
|
159
|
+
def [](arg)
|
160
|
+
case arg
|
161
|
+
when String
|
162
|
+
all.find { |z| z.name == arg }
|
163
|
+
when Numeric
|
164
|
+
arg *= 3600 if arg.abs <= 13
|
165
|
+
all.find { |z| z.utc_offset == arg.to_i }
|
166
|
+
else
|
167
|
+
raise ArgumentError, "invalid argument to TimeZone[]: #{arg.inspect}"
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
# A regular expression that matches the names of all time zones in
|
172
|
+
# the USA.
|
173
|
+
US_ZONES = /US|Arizona|Indiana|Hawaii|Alaska/ unless defined?(US_ZONES)
|
174
|
+
|
175
|
+
# A convenience method for returning a collection of TimeZone objects
|
176
|
+
# for time zones in the USA.
|
177
|
+
def us_zones
|
178
|
+
all.find_all { |z| z.name =~ US_ZONES }
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Prefer gems to the bundled libs.
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
begin
|
5
|
+
gem 'builder', '~> 2.1.2'
|
6
|
+
rescue Gem::LoadError
|
7
|
+
$:.unshift "#{File.dirname(__FILE__)}/vendor/builder-2.1.2"
|
8
|
+
end
|
9
|
+
|
10
|
+
begin
|
11
|
+
gem 'xml-simple', '~> 1.0.11'
|
12
|
+
rescue Gem::LoadError
|
13
|
+
$:.unshift "#{File.dirname(__FILE__)}/vendor/xml-simple-1.0.11"
|
14
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
|
4
|
+
# All rights reserved.
|
5
|
+
|
6
|
+
# Permission is granted for use, copying, modification, distribution,
|
7
|
+
# and distribution of modified versions of this work as long as the
|
8
|
+
# above copyright notice is included.
|
9
|
+
#++
|
10
|
+
|
11
|
+
######################################################################
|
12
|
+
# BlankSlate provides an abstract base class with no predefined
|
13
|
+
# methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
|
14
|
+
# BlankSlate is useful as a base class when writing classes that
|
15
|
+
# depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
|
16
|
+
#
|
17
|
+
class BlankSlate
|
18
|
+
class << self
|
19
|
+
|
20
|
+
# Hide the method named +name+ in the BlankSlate class. Don't
|
21
|
+
# hide +instance_eval+ or any method beginning with "__".
|
22
|
+
def hide(name)
|
23
|
+
if instance_methods.include?(name.to_s) and
|
24
|
+
name !~ /^(__|instance_eval)/
|
25
|
+
@hidden_methods ||= {}
|
26
|
+
@hidden_methods[name.to_sym] = instance_method(name)
|
27
|
+
undef_method name
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def find_hidden_method(name)
|
32
|
+
@hidden_methods ||= {}
|
33
|
+
@hidden_methods[name] || superclass.find_hidden_method(name)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Redefine a previously hidden method so that it may be called on a blank
|
37
|
+
# slate object.
|
38
|
+
def reveal(name)
|
39
|
+
bound_method = nil
|
40
|
+
unbound_method = find_hidden_method(name)
|
41
|
+
fail "Don't know how to reveal method '#{name}'" unless unbound_method
|
42
|
+
define_method(name) do |*args|
|
43
|
+
bound_method ||= unbound_method.bind(self)
|
44
|
+
bound_method.call(*args)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
instance_methods.each { |m| hide(m) }
|
50
|
+
end
|
51
|
+
|
52
|
+
######################################################################
|
53
|
+
# Since Ruby is very dynamic, methods added to the ancestors of
|
54
|
+
# BlankSlate <em>after BlankSlate is defined</em> will show up in the
|
55
|
+
# list of available BlankSlate methods. We handle this by defining a
|
56
|
+
# hook in the Object and Kernel classes that will hide any method
|
57
|
+
# defined after BlankSlate has been loaded.
|
58
|
+
#
|
59
|
+
module Kernel
|
60
|
+
class << self
|
61
|
+
alias_method :blank_slate_method_added, :method_added
|
62
|
+
|
63
|
+
# Detect method additions to Kernel and remove them in the
|
64
|
+
# BlankSlate class.
|
65
|
+
def method_added(name)
|
66
|
+
result = blank_slate_method_added(name)
|
67
|
+
return result if self != Kernel
|
68
|
+
BlankSlate.hide(name)
|
69
|
+
result
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
######################################################################
|
75
|
+
# Same as above, except in Object.
|
76
|
+
#
|
77
|
+
class Object
|
78
|
+
class << self
|
79
|
+
alias_method :blank_slate_method_added, :method_added
|
80
|
+
|
81
|
+
# Detect method additions to Object and remove them in the
|
82
|
+
# BlankSlate class.
|
83
|
+
def method_added(name)
|
84
|
+
result = blank_slate_method_added(name)
|
85
|
+
return result if self != Object
|
86
|
+
BlankSlate.hide(name)
|
87
|
+
result
|
88
|
+
end
|
89
|
+
|
90
|
+
def find_hidden_method(name)
|
91
|
+
nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
######################################################################
|
97
|
+
# Also, modules included into Object need to be scanned and have their
|
98
|
+
# instance methods removed from blank slate. In theory, modules
|
99
|
+
# included into Kernel would have to be removed as well, but a
|
100
|
+
# "feature" of Ruby prevents late includes into modules from being
|
101
|
+
# exposed in the first place.
|
102
|
+
#
|
103
|
+
class Module
|
104
|
+
alias blankslate_original_append_features append_features
|
105
|
+
def append_features(mod)
|
106
|
+
result = blankslate_original_append_features(mod)
|
107
|
+
return result if mod != Object
|
108
|
+
instance_methods.each do |name|
|
109
|
+
BlankSlate.hide(name)
|
110
|
+
end
|
111
|
+
result
|
112
|
+
end
|
113
|
+
end
|