/usr/lib/ruby/vendor_ruby/tzinfo/ruby_data_source.rb is in ruby-tzinfo 1.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | #--
# Copyright (c) 2012-2013 Philip Ross
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#++
module TZInfo
# A DataSource that loads data from the set of Ruby modules included in the
# TZInfo::Data library (tzinfo-data gem).
#
# To have TZInfo use this DataSource, call TZInfo::DataSource.set as follows:
#
# TZInfo::DataSource.set(:ruby)
class RubyDataSource < DataSource
# Base path for require.
REQUIRE_PATH = File.join('tzinfo', 'data', 'definitions')
# Whether the timezone index has been loaded yet.
@@timezone_index_loaded = false
# Whether the country index has been loaded yet.
@@country_index_loaded = false
# Returns a TimezoneInfo instance for a given identifier.
# Raises InvalidTimezoneIdentifier if the timezone is not found or the
# identifier is invalid.
def load_timezone_info(identifier)
raise InvalidTimezoneIdentifier, 'Invalid identifier' if identifier !~ /^[A-Za-z0-9\+\-_]+(\/[A-Za-z0-9\+\-_]+)*$/
identifier = identifier.gsub(/-/, '__m__').gsub(/\+/, '__p__')
# Untaint identifier after it has been reassigned to a new string. We
# don't want to modify the original identifier. identifier may also be
# frozen and therefore cannot be untainted.
identifier.untaint
identifier = identifier.split('/')
begin
require_definition(identifier)
m = Data::Definitions
identifier.each {|part|
m = m.const_get(part)
}
info = m.get
rescue LoadError, NameError => e
raise InvalidTimezoneIdentifier, e.message
end
end
# Returns an array of all the available timezone identifiers.
def timezone_identifiers
load_timezone_index
Data::Indexes::Timezones.timezones
end
# Returns an array of all the available timezone identifiers for
# data timezones (i.e. those that actually contain definitions).
def data_timezone_identifiers
load_timezone_index
Data::Indexes::Timezones.data_timezones
end
# Returns an array of all the available timezone identifiers that
# are links to other timezones.
def linked_timezone_identifiers
load_timezone_index
Data::Indexes::Timezones.linked_timezones
end
# Returns a CountryInfo instance for the given ISO 3166-1 alpha-2
# country code. Raises InvalidCountryCode if the country could not be found
# or the code is invalid.
def load_country_info(code)
load_country_index
info = Data::Indexes::Countries.countries[code]
raise InvalidCountryCode.new, 'Invalid country code' unless info
info
end
# Returns an array of all the available ISO 3166-1 alpha-2
# country codes.
def country_codes
load_country_index
Data::Indexes::Countries.countries.keys.freeze
end
# Returns the name of this DataSource.
def to_s
"Ruby DataSource"
end
private
# Requires a zone definition by its identifier (split on /).
def require_definition(identifier)
require_data(*(['definitions'] + identifier))
end
# Requires an index by its name.
def self.require_index(name)
require_data(*['indexes', name])
end
# Requires a file from tzinfo/data.
def require_data(*file)
self.class.require_data(*file)
end
# Requires a file from tzinfo/data.
def self.require_data(*file)
require File.join('tzinfo', 'data', *file)
end
# Loads in the index of timezones if it hasn't already been loaded.
def load_timezone_index
self.class.load_timezone_index
end
# Loads in the index of timezones if it hasn't already been loaded.
def self.load_timezone_index
unless @@timezone_index_loaded
require_index('timezones')
@@timezone_index_loaded = true
end
end
# Loads in the index of countries if it hasn't already been loaded.
def load_country_index
self.class.load_country_index
end
# Loads in the index of countries if it hasn't already been loaded.
def self.load_country_index
unless @@country_index_loaded
require_index('countries')
@@country_index_loaded = true
end
end
end
end
|