提交 b9888373 编写于 作者: C Charlie Somerville

load definitions from a marshalled file

上级 890aff3b
#!/usr/bin/env ruby
Dir.chdir(File.expand_path("..", __FILE__))
$: << File.expand_path("../lib", __FILE__)
require "active_support"
ActiveSupport::TimeZone.all
def flatten_constants(mod, ary = [])
ary << mod
mod.constants.each do |const|
flatten_constants(mod.const_get(const), ary)
end
ary
end
defns = flatten_constants(TZInfo::Definitions).select { |mod|
defined?(mod.get)
}.map { |tz|
tz.get
}
file = "lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions.dump"
data = Marshal.dump(defns)
Marshal.load(data)
File.open(file, "wb") do |f|
require "pry"
pry binding
f.write(data)
end
puts "Wrote #{data.size} bytes to #{file}"
#--
# Copyright (c) 2005-2006 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.
#
......@@ -30,4 +30,5 @@
# require 'tzinfo/tzdataparser'
# require 'tzinfo/timezone_proxy'
require 'tzinfo/data_timezone'
require 'tzinfo/linked_timezone'
\ No newline at end of file
require 'tzinfo/linked_timezone'
require 'tzinfo/definitions'
require "tzinfo/data_timezone_info"
require "tzinfo/linked_timezone_info"
require "tzinfo/timezone_definition"
module TZInfo
module Definitions
def self.load_all!
return true if @loaded
@loaded = true
defns = Marshal.load(File.read(File.expand_path("../definitions.dump", __FILE__)))
defns.each do |defn|
tz_mod = defn.instance_variable_get(:@identifier).split("/").reduce(TZInfo::Definitions) { |mod, name|
if mod.const_defined?(name)
mod.const_get(name)
else
mod.const_set(name, Module.new)
end
}
def tz_mod.get
@timezone
end
tz_mod.instance_variable_set(:@timezone, defn)
end
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册