mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Whitespace and example identation
This commit is contained in:
committed by
Xavier Noria
parent
e8ef58a697
commit
9f9a02af86
@@ -5,17 +5,17 @@
|
||||
#
|
||||
# Here is an example where +on_load+ method is called to register a hook.
|
||||
#
|
||||
# initializer "active_record.initialize_timezone" do
|
||||
# ActiveSupport.on_load(:active_record) do
|
||||
# self.time_zone_aware_attributes = true
|
||||
# self.default_timezone = :utc
|
||||
# end
|
||||
# end
|
||||
# initializer "active_record.initialize_timezone" do
|
||||
# ActiveSupport.on_load(:active_record) do
|
||||
# self.time_zone_aware_attributes = true
|
||||
# self.default_timezone = :utc
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# When the entirety of +activerecord/lib/active_record/base.rb+ has been evaluated then +run_load_hooks+ is invoked.
|
||||
# The very last line of +activerecord/lib/active_record/base.rb+ is:
|
||||
#
|
||||
# ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Base)
|
||||
# ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Base)
|
||||
#
|
||||
module ActiveSupport
|
||||
@load_hooks = Hash.new {|h,k| h[k] = [] }
|
||||
|
||||
@@ -4,7 +4,7 @@ require 'active_support/core_ext/class/attribute'
|
||||
module ActiveSupport
|
||||
# ActiveSupport::LogSubscriber is an object set to consume ActiveSupport::Notifications
|
||||
# with solely purpose of logging. The log subscriber dispatches notifications to a
|
||||
# regirested object based on its given namespace.
|
||||
# registered object based on its given namespace.
|
||||
#
|
||||
# An example would be Active Record log subscriber responsible for logging queries:
|
||||
#
|
||||
@@ -16,7 +16,7 @@ module ActiveSupport
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# And it's finally registed as:
|
||||
# And it's finally registered as:
|
||||
#
|
||||
# ActiveRecord::LogSubscriber.attach_to :active_record
|
||||
#
|
||||
|
||||
@@ -47,6 +47,7 @@ module ActiveSupport
|
||||
# exception.record.new_record? ? ...
|
||||
# end
|
||||
# end
|
||||
#
|
||||
def rescue_from(*klasses, &block)
|
||||
options = klasses.extract_options!
|
||||
|
||||
|
||||
@@ -46,8 +46,10 @@ module ActiveSupport
|
||||
# p SecureRandom.random_bytes(10) # => "\016\t{\370g\310pbr\301"
|
||||
# p SecureRandom.random_bytes(10) # => "\323U\030TO\234\357\020\a\337"
|
||||
# ...
|
||||
#
|
||||
module SecureRandom
|
||||
# SecureRandom.random_bytes generates a random binary string.
|
||||
|
||||
# Generates a random binary string.
|
||||
#
|
||||
# The argument n specifies the length of the result string.
|
||||
#
|
||||
@@ -56,6 +58,7 @@ module ActiveSupport
|
||||
#
|
||||
# If secure random number generator is not available,
|
||||
# NotImplementedError is raised.
|
||||
#
|
||||
def self.random_bytes(n=nil)
|
||||
n ||= 16
|
||||
|
||||
@@ -124,7 +127,7 @@ module ActiveSupport
|
||||
raise NotImplementedError, "No random device"
|
||||
end
|
||||
|
||||
# SecureRandom.hex generates a random hex string.
|
||||
# Generates a random hex string.
|
||||
#
|
||||
# The argument n specifies the length of the random length.
|
||||
# The length of the result string is twice of n.
|
||||
@@ -134,11 +137,12 @@ module ActiveSupport
|
||||
#
|
||||
# If secure random number generator is not available,
|
||||
# NotImplementedError is raised.
|
||||
#
|
||||
def self.hex(n=nil)
|
||||
random_bytes(n).unpack("H*")[0]
|
||||
end
|
||||
|
||||
# SecureRandom.base64 generates a random base64 string.
|
||||
# Generates a random base64 string.
|
||||
#
|
||||
# The argument n specifies the length of the random length.
|
||||
# The length of the result string is about 4/3 of n.
|
||||
@@ -148,11 +152,12 @@ module ActiveSupport
|
||||
#
|
||||
# If secure random number generator is not available,
|
||||
# NotImplementedError is raised.
|
||||
#
|
||||
def self.base64(n=nil)
|
||||
[random_bytes(n)].pack("m*").delete("\n")
|
||||
end
|
||||
|
||||
# SecureRandom.random_number generates a random number.
|
||||
# Generates a random number.
|
||||
#
|
||||
# If an positive integer is given as n,
|
||||
# SecureRandom.random_number returns an integer:
|
||||
@@ -161,6 +166,7 @@ module ActiveSupport
|
||||
# If 0 is given or an argument is not given,
|
||||
# SecureRandom.random_number returns an float:
|
||||
# 0.0 <= SecureRandom.random_number() < 1.0.
|
||||
#
|
||||
def self.random_number(n=0)
|
||||
if 0 < n
|
||||
hex = n.to_s(16)
|
||||
|
||||
@@ -32,6 +32,7 @@ module ActiveSupport
|
||||
# t > Time.utc(1999) # => true
|
||||
# t.is_a?(Time) # => true
|
||||
# t.is_a?(ActiveSupport::TimeWithZone) # => true
|
||||
#
|
||||
class TimeWithZone
|
||||
def self.name
|
||||
'Time' # Report class name as 'Time' to thwart type checking
|
||||
@@ -127,6 +128,7 @@ module ActiveSupport
|
||||
# # With ActiveSupport::JSON::Encoding.use_standard_json_time_format = false
|
||||
# Time.utc(2005,2,1,15,15,10).in_time_zone.to_json
|
||||
# # => "2005/02/01 15:15:10 +0000"
|
||||
#
|
||||
def as_json(options = nil)
|
||||
if ActiveSupport::JSON::Encoding.use_standard_json_time_format
|
||||
xmlschema
|
||||
|
||||
Reference in New Issue
Block a user