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,377 @@
|
|
1
|
+
require 'active_support/core_ext/object/blank'
|
2
|
+
require 'active_support/core_ext/object/try'
|
3
|
+
begin
|
4
|
+
require 'tzinfo'
|
5
|
+
rescue LoadError => e
|
6
|
+
$stderr.puts "You don't have tzinfo installed in your application. Please add it to your Gemfile and run bundle install"
|
7
|
+
raise e
|
8
|
+
end
|
9
|
+
|
10
|
+
# The TimeZone class serves as a wrapper around TZInfo::Timezone instances. It allows us to do the following:
|
11
|
+
#
|
12
|
+
# * Limit the set of zones provided by TZInfo to a meaningful subset of 142 zones.
|
13
|
+
# * Retrieve and display zones with a friendlier name (e.g., "Eastern Time (US & Canada)" instead of "America/New_York").
|
14
|
+
# * Lazily load TZInfo::Timezone instances only when they're needed.
|
15
|
+
# * Create ActiveSupport::TimeWithZone instances via TimeZone's +local+, +parse+, +at+ and +now+ methods.
|
16
|
+
#
|
17
|
+
# If you set <tt>config.time_zone</tt> in the Rails Initializer, you can access this TimeZone object via <tt>Time.zone</tt>:
|
18
|
+
#
|
19
|
+
# # environment.rb:
|
20
|
+
# Rails::Initializer.run do |config|
|
21
|
+
# config.time_zone = "Eastern Time (US & Canada)"
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# Time.zone # => #<TimeZone:0x514834...>
|
25
|
+
# Time.zone.name # => "Eastern Time (US & Canada)"
|
26
|
+
# Time.zone.now # => Sun, 18 May 2008 14:30:44 EDT -04:00
|
27
|
+
#
|
28
|
+
# The version of TZInfo bundled with Active Support only includes the definitions necessary to support the zones
|
29
|
+
# defined by the TimeZone class. If you need to use zones that aren't defined by TimeZone, you'll need to install the TZInfo gem
|
30
|
+
# (if a recent version of the gem is installed locally, this will be used instead of the bundled version.)
|
31
|
+
module ActiveSupport
|
32
|
+
class TimeZone
|
33
|
+
unless const_defined?(:MAPPING)
|
34
|
+
# Keys are Rails TimeZone names, values are TZInfo identifiers
|
35
|
+
MAPPING = {
|
36
|
+
"International Date Line West" => "Pacific/Midway",
|
37
|
+
"Midway Island" => "Pacific/Midway",
|
38
|
+
"Samoa" => "Pacific/Pago_Pago",
|
39
|
+
"Hawaii" => "Pacific/Honolulu",
|
40
|
+
"Alaska" => "America/Juneau",
|
41
|
+
"Pacific Time (US & Canada)" => "America/Los_Angeles",
|
42
|
+
"Tijuana" => "America/Tijuana",
|
43
|
+
"Mountain Time (US & Canada)" => "America/Denver",
|
44
|
+
"Arizona" => "America/Phoenix",
|
45
|
+
"Chihuahua" => "America/Chihuahua",
|
46
|
+
"Mazatlan" => "America/Mazatlan",
|
47
|
+
"Central Time (US & Canada)" => "America/Chicago",
|
48
|
+
"Saskatchewan" => "America/Regina",
|
49
|
+
"Guadalajara" => "America/Mexico_City",
|
50
|
+
"Mexico City" => "America/Mexico_City",
|
51
|
+
"Monterrey" => "America/Monterrey",
|
52
|
+
"Central America" => "America/Guatemala",
|
53
|
+
"Eastern Time (US & Canada)" => "America/New_York",
|
54
|
+
"Indiana (East)" => "America/Indiana/Indianapolis",
|
55
|
+
"Bogota" => "America/Bogota",
|
56
|
+
"Lima" => "America/Lima",
|
57
|
+
"Quito" => "America/Lima",
|
58
|
+
"Atlantic Time (Canada)" => "America/Halifax",
|
59
|
+
"Caracas" => "America/Caracas",
|
60
|
+
"La Paz" => "America/La_Paz",
|
61
|
+
"Santiago" => "America/Santiago",
|
62
|
+
"Newfoundland" => "America/St_Johns",
|
63
|
+
"Brasilia" => "America/Sao_Paulo",
|
64
|
+
"Buenos Aires" => "America/Argentina/Buenos_Aires",
|
65
|
+
"Georgetown" => "America/Guyana",
|
66
|
+
"Greenland" => "America/Godthab",
|
67
|
+
"Mid-Atlantic" => "Atlantic/South_Georgia",
|
68
|
+
"Azores" => "Atlantic/Azores",
|
69
|
+
"Cape Verde Is." => "Atlantic/Cape_Verde",
|
70
|
+
"Dublin" => "Europe/Dublin",
|
71
|
+
"Edinburgh" => "Europe/London",
|
72
|
+
"Lisbon" => "Europe/Lisbon",
|
73
|
+
"London" => "Europe/London",
|
74
|
+
"Casablanca" => "Africa/Casablanca",
|
75
|
+
"Monrovia" => "Africa/Monrovia",
|
76
|
+
"UTC" => "Etc/UTC",
|
77
|
+
"Belgrade" => "Europe/Belgrade",
|
78
|
+
"Bratislava" => "Europe/Bratislava",
|
79
|
+
"Budapest" => "Europe/Budapest",
|
80
|
+
"Ljubljana" => "Europe/Ljubljana",
|
81
|
+
"Prague" => "Europe/Prague",
|
82
|
+
"Sarajevo" => "Europe/Sarajevo",
|
83
|
+
"Skopje" => "Europe/Skopje",
|
84
|
+
"Warsaw" => "Europe/Warsaw",
|
85
|
+
"Zagreb" => "Europe/Zagreb",
|
86
|
+
"Brussels" => "Europe/Brussels",
|
87
|
+
"Copenhagen" => "Europe/Copenhagen",
|
88
|
+
"Madrid" => "Europe/Madrid",
|
89
|
+
"Paris" => "Europe/Paris",
|
90
|
+
"Amsterdam" => "Europe/Amsterdam",
|
91
|
+
"Berlin" => "Europe/Berlin",
|
92
|
+
"Bern" => "Europe/Berlin",
|
93
|
+
"Rome" => "Europe/Rome",
|
94
|
+
"Stockholm" => "Europe/Stockholm",
|
95
|
+
"Vienna" => "Europe/Vienna",
|
96
|
+
"West Central Africa" => "Africa/Algiers",
|
97
|
+
"Bucharest" => "Europe/Bucharest",
|
98
|
+
"Cairo" => "Africa/Cairo",
|
99
|
+
"Helsinki" => "Europe/Helsinki",
|
100
|
+
"Kyiv" => "Europe/Kiev",
|
101
|
+
"Riga" => "Europe/Riga",
|
102
|
+
"Sofia" => "Europe/Sofia",
|
103
|
+
"Tallinn" => "Europe/Tallinn",
|
104
|
+
"Vilnius" => "Europe/Vilnius",
|
105
|
+
"Athens" => "Europe/Athens",
|
106
|
+
"Istanbul" => "Europe/Istanbul",
|
107
|
+
"Minsk" => "Europe/Minsk",
|
108
|
+
"Jerusalem" => "Asia/Jerusalem",
|
109
|
+
"Harare" => "Africa/Harare",
|
110
|
+
"Pretoria" => "Africa/Johannesburg",
|
111
|
+
"Moscow" => "Europe/Moscow",
|
112
|
+
"St. Petersburg" => "Europe/Moscow",
|
113
|
+
"Volgograd" => "Europe/Moscow",
|
114
|
+
"Kuwait" => "Asia/Kuwait",
|
115
|
+
"Riyadh" => "Asia/Riyadh",
|
116
|
+
"Nairobi" => "Africa/Nairobi",
|
117
|
+
"Baghdad" => "Asia/Baghdad",
|
118
|
+
"Tehran" => "Asia/Tehran",
|
119
|
+
"Abu Dhabi" => "Asia/Muscat",
|
120
|
+
"Muscat" => "Asia/Muscat",
|
121
|
+
"Baku" => "Asia/Baku",
|
122
|
+
"Tbilisi" => "Asia/Tbilisi",
|
123
|
+
"Yerevan" => "Asia/Yerevan",
|
124
|
+
"Kabul" => "Asia/Kabul",
|
125
|
+
"Ekaterinburg" => "Asia/Yekaterinburg",
|
126
|
+
"Islamabad" => "Asia/Karachi",
|
127
|
+
"Karachi" => "Asia/Karachi",
|
128
|
+
"Tashkent" => "Asia/Tashkent",
|
129
|
+
"Chennai" => "Asia/Kolkata",
|
130
|
+
"Kolkata" => "Asia/Kolkata",
|
131
|
+
"Mumbai" => "Asia/Kolkata",
|
132
|
+
"New Delhi" => "Asia/Kolkata",
|
133
|
+
"Kathmandu" => "Asia/Kathmandu",
|
134
|
+
"Astana" => "Asia/Dhaka",
|
135
|
+
"Dhaka" => "Asia/Dhaka",
|
136
|
+
"Sri Jayawardenepura" => "Asia/Colombo",
|
137
|
+
"Almaty" => "Asia/Almaty",
|
138
|
+
"Novosibirsk" => "Asia/Novosibirsk",
|
139
|
+
"Rangoon" => "Asia/Rangoon",
|
140
|
+
"Bangkok" => "Asia/Bangkok",
|
141
|
+
"Hanoi" => "Asia/Bangkok",
|
142
|
+
"Jakarta" => "Asia/Jakarta",
|
143
|
+
"Krasnoyarsk" => "Asia/Krasnoyarsk",
|
144
|
+
"Beijing" => "Asia/Shanghai",
|
145
|
+
"Chongqing" => "Asia/Chongqing",
|
146
|
+
"Hong Kong" => "Asia/Hong_Kong",
|
147
|
+
"Urumqi" => "Asia/Urumqi",
|
148
|
+
"Kuala Lumpur" => "Asia/Kuala_Lumpur",
|
149
|
+
"Singapore" => "Asia/Singapore",
|
150
|
+
"Taipei" => "Asia/Taipei",
|
151
|
+
"Perth" => "Australia/Perth",
|
152
|
+
"Irkutsk" => "Asia/Irkutsk",
|
153
|
+
"Ulaan Bataar" => "Asia/Ulaanbaatar",
|
154
|
+
"Seoul" => "Asia/Seoul",
|
155
|
+
"Osaka" => "Asia/Tokyo",
|
156
|
+
"Sapporo" => "Asia/Tokyo",
|
157
|
+
"Tokyo" => "Asia/Tokyo",
|
158
|
+
"Yakutsk" => "Asia/Yakutsk",
|
159
|
+
"Darwin" => "Australia/Darwin",
|
160
|
+
"Adelaide" => "Australia/Adelaide",
|
161
|
+
"Canberra" => "Australia/Melbourne",
|
162
|
+
"Melbourne" => "Australia/Melbourne",
|
163
|
+
"Sydney" => "Australia/Sydney",
|
164
|
+
"Brisbane" => "Australia/Brisbane",
|
165
|
+
"Hobart" => "Australia/Hobart",
|
166
|
+
"Vladivostok" => "Asia/Vladivostok",
|
167
|
+
"Guam" => "Pacific/Guam",
|
168
|
+
"Port Moresby" => "Pacific/Port_Moresby",
|
169
|
+
"Magadan" => "Asia/Magadan",
|
170
|
+
"Solomon Is." => "Asia/Magadan",
|
171
|
+
"New Caledonia" => "Pacific/Noumea",
|
172
|
+
"Fiji" => "Pacific/Fiji",
|
173
|
+
"Kamchatka" => "Asia/Kamchatka",
|
174
|
+
"Marshall Is." => "Pacific/Majuro",
|
175
|
+
"Auckland" => "Pacific/Auckland",
|
176
|
+
"Wellington" => "Pacific/Auckland",
|
177
|
+
"Nuku'alofa" => "Pacific/Tongatapu"
|
178
|
+
}.each { |name, zone| name.freeze; zone.freeze }
|
179
|
+
MAPPING.freeze
|
180
|
+
end
|
181
|
+
|
182
|
+
UTC_OFFSET_WITH_COLON = '%s%02d:%02d'
|
183
|
+
UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.sub(':', '')
|
184
|
+
|
185
|
+
# Assumes self represents an offset from UTC in seconds (as returned from Time#utc_offset)
|
186
|
+
# and turns this into an +HH:MM formatted string. Example:
|
187
|
+
#
|
188
|
+
# TimeZone.seconds_to_utc_offset(-21_600) # => "-06:00"
|
189
|
+
def self.seconds_to_utc_offset(seconds, colon = true)
|
190
|
+
format = colon ? UTC_OFFSET_WITH_COLON : UTC_OFFSET_WITHOUT_COLON
|
191
|
+
sign = (seconds < 0 ? '-' : '+')
|
192
|
+
hours = seconds.abs / 3600
|
193
|
+
minutes = (seconds.abs % 3600) / 60
|
194
|
+
format % [sign, hours, minutes]
|
195
|
+
end
|
196
|
+
|
197
|
+
include Comparable
|
198
|
+
attr_reader :name
|
199
|
+
attr_reader :tzinfo
|
200
|
+
|
201
|
+
# Create a new TimeZone object with the given name and offset. The
|
202
|
+
# offset is the number of seconds that this time zone is offset from UTC
|
203
|
+
# (GMT). Seconds were chosen as the offset unit because that is the unit that
|
204
|
+
# Ruby uses to represent time zone offsets (see Time#utc_offset).
|
205
|
+
def initialize(name, utc_offset = nil, tzinfo = nil)
|
206
|
+
@name = name
|
207
|
+
@utc_offset = utc_offset
|
208
|
+
@tzinfo = tzinfo || TimeZone.find_tzinfo(name)
|
209
|
+
@current_period = nil
|
210
|
+
end
|
211
|
+
|
212
|
+
def utc_offset
|
213
|
+
if @utc_offset
|
214
|
+
@utc_offset
|
215
|
+
else
|
216
|
+
@current_period ||= tzinfo.try(:current_period)
|
217
|
+
@current_period.try(:utc_offset)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
# Returns the offset of this time zone as a formatted string, of the
|
222
|
+
# format "+HH:MM".
|
223
|
+
def formatted_offset(colon=true, alternate_utc_string = nil)
|
224
|
+
utc_offset == 0 && alternate_utc_string || self.class.seconds_to_utc_offset(utc_offset, colon)
|
225
|
+
end
|
226
|
+
|
227
|
+
# Compare this time zone to the parameter. The two are comapred first on
|
228
|
+
# their offsets, and then by name.
|
229
|
+
def <=>(zone)
|
230
|
+
result = (utc_offset <=> zone.utc_offset)
|
231
|
+
result = (name <=> zone.name) if result == 0
|
232
|
+
result
|
233
|
+
end
|
234
|
+
|
235
|
+
# Compare #name and TZInfo identifier to a supplied regexp, returning true
|
236
|
+
# if a match is found.
|
237
|
+
def =~(re)
|
238
|
+
return true if name =~ re || MAPPING[name] =~ re
|
239
|
+
end
|
240
|
+
|
241
|
+
# Returns a textual representation of this time zone.
|
242
|
+
def to_s
|
243
|
+
"(GMT#{formatted_offset}) #{name}"
|
244
|
+
end
|
245
|
+
|
246
|
+
# Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from given values. Example:
|
247
|
+
#
|
248
|
+
# Time.zone = "Hawaii" # => "Hawaii"
|
249
|
+
# Time.zone.local(2007, 2, 1, 15, 30, 45) # => Thu, 01 Feb 2007 15:30:45 HST -10:00
|
250
|
+
def local(*args)
|
251
|
+
time = Time.utc_time(*args)
|
252
|
+
ActiveSupport::TimeWithZone.new(nil, self, time)
|
253
|
+
end
|
254
|
+
|
255
|
+
# Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from number of seconds since the Unix epoch. Example:
|
256
|
+
#
|
257
|
+
# Time.zone = "Hawaii" # => "Hawaii"
|
258
|
+
# Time.utc(2000).to_f # => 946684800.0
|
259
|
+
# Time.zone.at(946684800.0) # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
260
|
+
def at(secs)
|
261
|
+
utc = Time.at(secs).utc rescue DateTime.civil(1970).since(secs)
|
262
|
+
utc.in_time_zone(self)
|
263
|
+
end
|
264
|
+
|
265
|
+
# Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from parsed string. Example:
|
266
|
+
#
|
267
|
+
# Time.zone = "Hawaii" # => "Hawaii"
|
268
|
+
# Time.zone.parse('1999-12-31 14:00:00') # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
269
|
+
#
|
270
|
+
# If upper components are missing from the string, they are supplied from TimeZone#now:
|
271
|
+
#
|
272
|
+
# Time.zone.now # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
273
|
+
# Time.zone.parse('22:30:00') # => Fri, 31 Dec 1999 22:30:00 HST -10:00
|
274
|
+
def parse(str, now=now)
|
275
|
+
date_parts = Date._parse(str)
|
276
|
+
return if date_parts.blank?
|
277
|
+
time = Time.parse(str, now) rescue DateTime.parse(str)
|
278
|
+
if date_parts[:offset].nil?
|
279
|
+
ActiveSupport::TimeWithZone.new(nil, self, time)
|
280
|
+
else
|
281
|
+
time.in_time_zone(self)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
# Returns an ActiveSupport::TimeWithZone instance representing the current time
|
286
|
+
# in the time zone represented by +self+. Example:
|
287
|
+
#
|
288
|
+
# Time.zone = 'Hawaii' # => "Hawaii"
|
289
|
+
# Time.zone.now # => Wed, 23 Jan 2008 20:24:27 HST -10:00
|
290
|
+
def now
|
291
|
+
Time.now.utc.in_time_zone(self)
|
292
|
+
end
|
293
|
+
|
294
|
+
# Return the current date in this time zone.
|
295
|
+
def today
|
296
|
+
tzinfo.now.to_date
|
297
|
+
end
|
298
|
+
|
299
|
+
# Adjust the given time to the simultaneous time in the time zone represented by +self+. Returns a
|
300
|
+
# Time.utc() instance -- if you want an ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead.
|
301
|
+
def utc_to_local(time)
|
302
|
+
tzinfo.utc_to_local(time)
|
303
|
+
end
|
304
|
+
|
305
|
+
# Adjust the given time to the simultaneous time in UTC. Returns a Time.utc() instance.
|
306
|
+
def local_to_utc(time, dst=true)
|
307
|
+
tzinfo.local_to_utc(time, dst)
|
308
|
+
end
|
309
|
+
|
310
|
+
# Available so that TimeZone instances respond like TZInfo::Timezone instances
|
311
|
+
def period_for_utc(time)
|
312
|
+
tzinfo.period_for_utc(time)
|
313
|
+
end
|
314
|
+
|
315
|
+
# Available so that TimeZone instances respond like TZInfo::Timezone instances
|
316
|
+
def period_for_local(time, dst=true)
|
317
|
+
tzinfo.period_for_local(time, dst)
|
318
|
+
end
|
319
|
+
|
320
|
+
# TODO: Preload instead of lazy load for thread safety
|
321
|
+
def self.find_tzinfo(name)
|
322
|
+
require 'active_support/tzinfo' unless defined?(::TZInfo)
|
323
|
+
::TZInfo::TimezoneProxy.new(MAPPING[name] || name)
|
324
|
+
end
|
325
|
+
|
326
|
+
class << self
|
327
|
+
alias_method :create, :new
|
328
|
+
|
329
|
+
# Return a TimeZone instance with the given name, or +nil+ if no
|
330
|
+
# such TimeZone instance exists. (This exists to support the use of
|
331
|
+
# this class with the +composed_of+ macro.)
|
332
|
+
def new(name)
|
333
|
+
self[name]
|
334
|
+
end
|
335
|
+
|
336
|
+
# Return an array of all TimeZone objects. There are multiple
|
337
|
+
# TimeZone objects per time zone, in many cases, to make it easier
|
338
|
+
# for users to find their own time zone.
|
339
|
+
def all
|
340
|
+
@zones ||= zones_map.values.sort
|
341
|
+
end
|
342
|
+
|
343
|
+
def zones_map
|
344
|
+
@zones_map ||= Hash[MAPPING.map { |place, _| [place, create(place)] }]
|
345
|
+
end
|
346
|
+
|
347
|
+
# Locate a specific time zone object. If the argument is a string, it
|
348
|
+
# is interpreted to mean the name of the timezone to locate. If it is a
|
349
|
+
# numeric value it is either the hour offset, or the second offset, of the
|
350
|
+
# timezone to find. (The first one with that offset will be returned.)
|
351
|
+
# Returns +nil+ if no such time zone is known to the system.
|
352
|
+
def [](arg)
|
353
|
+
case arg
|
354
|
+
when String
|
355
|
+
zones_map[arg] ||= lookup(arg)
|
356
|
+
when Numeric, ActiveSupport::Duration
|
357
|
+
arg *= 3600 if arg.abs <= 13
|
358
|
+
all.find { |z| z.utc_offset == arg.to_i }
|
359
|
+
else
|
360
|
+
raise ArgumentError, "invalid argument to TimeZone[]: #{arg.inspect}"
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
# A convenience method for returning a collection of TimeZone objects
|
365
|
+
# for time zones in the USA.
|
366
|
+
def us_zones
|
367
|
+
@us_zones ||= all.find_all { |z| z.name =~ /US|Arizona|Indiana|Hawaii|Alaska/ }
|
368
|
+
end
|
369
|
+
|
370
|
+
private
|
371
|
+
|
372
|
+
def lookup(name)
|
373
|
+
(tzinfo = find_tzinfo(name)) && create(tzinfo.name.freeze)
|
374
|
+
end
|
375
|
+
end
|
376
|
+
end
|
377
|
+
end
|
Binary file
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Extensions to +nil+ which allow for more helpful error messages for people who
|
2
|
+
# are new to Rails.
|
3
|
+
#
|
4
|
+
# Ruby raises NoMethodError if you invoke a method on an object that does not
|
5
|
+
# respond to it:
|
6
|
+
#
|
7
|
+
# $ ruby -e nil.destroy
|
8
|
+
# -e:1: undefined method `destroy' for nil:NilClass (NoMethodError)
|
9
|
+
#
|
10
|
+
# With these extensions, if the method belongs to the public interface of the
|
11
|
+
# classes in NilClass::WHINERS the error message suggests which could be the
|
12
|
+
# actual intended class:
|
13
|
+
#
|
14
|
+
# $ rails runner nil.destroy
|
15
|
+
# ...
|
16
|
+
# You might have expected an instance of ActiveRecord::Base.
|
17
|
+
# ...
|
18
|
+
#
|
19
|
+
# NilClass#id exists in Ruby 1.8 (though it is deprecated). Since +id+ is a fundamental
|
20
|
+
# method of Active Record models NilClass#id is redefined as well to raise a RuntimeError
|
21
|
+
# and warn the user. She probably wanted a model database identifier and the 4
|
22
|
+
# returned by the original method could result in obscure bugs.
|
23
|
+
#
|
24
|
+
# The flag <tt>config.whiny_nils</tt> determines whether this feature is enabled.
|
25
|
+
# By default it is on in development and test modes, and it is off in production
|
26
|
+
# mode.
|
27
|
+
class NilClass
|
28
|
+
METHOD_CLASS_MAP = Hash.new
|
29
|
+
|
30
|
+
def self.add_whiner(klass)
|
31
|
+
methods = klass.public_instance_methods - public_instance_methods
|
32
|
+
class_name = klass.name
|
33
|
+
methods.each { |method| METHOD_CLASS_MAP[method.to_sym] = class_name }
|
34
|
+
end
|
35
|
+
|
36
|
+
add_whiner ::Array
|
37
|
+
|
38
|
+
# Raises a RuntimeError when you attempt to call +id+ on +nil+.
|
39
|
+
def id
|
40
|
+
raise RuntimeError, "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id", caller
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def method_missing(method, *args, &block)
|
45
|
+
if klass = METHOD_CLASS_MAP[method]
|
46
|
+
raise_nil_warning_for klass, method, caller
|
47
|
+
else
|
48
|
+
super
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Raises a NoMethodError when you attempt to call a method on +nil+.
|
53
|
+
def raise_nil_warning_for(class_name = nil, selector = nil, with_caller = nil)
|
54
|
+
message = "You have a nil object when you didn't expect it!"
|
55
|
+
message << "\nYou might have expected an instance of #{class_name}." if class_name
|
56
|
+
message << "\nThe error occurred while evaluating nil.#{selector}" if selector
|
57
|
+
|
58
|
+
raise NoMethodError, message, with_caller || caller
|
59
|
+
end
|
60
|
+
end
|