repo
stringlengths
5
92
file_url
stringlengths
80
287
file_path
stringlengths
5
197
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:37:27
2026-01-04 17:58:21
truncated
bool
2 classes
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/logger.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/logger.rb
# Adds the 'around_level' method to Logger. class Logger def self.define_around_helper(level) module_eval <<-end_eval def around_#{level}(before_message, after_message, &block) # def around_debug(before_message, after_message, &block) self.#{level}(before_message) # self.debug(before_message) return_value = block.call(self) # return_value = block.call(self) self.#{level}(after_message) # self.debug(after_message) return return_value # return return_value end # end end_eval end [:debug, :info, :error, :fatal].each {|level| define_around_helper(level) } end require 'logger' # Extensions to the built in Ruby logger. # # If you want to use the default log formatter as defined in the Ruby core, then you # will need to set the formatter for the logger as in: # # logger.formatter = Formatter.new # # You can then specify the datetime format, for example: # # logger.datetime_format = "%Y-%m-%d" # # Note: This logger is deprecated in favor of ActiveSupport::BufferedLogger class Logger ## # :singleton-method: # Set to false to disable the silencer cattr_accessor :silencer self.silencer = true # Silences the logger for the duration of the block. def silence(temporary_level = Logger::ERROR) if silencer begin old_logger_level, self.level = level, temporary_level yield self ensure self.level = old_logger_level end else yield self end end alias :old_datetime_format= :datetime_format= # Logging date-time format (string passed to +strftime+). Ignored if the formatter # does not respond to datetime_format=. def datetime_format=(datetime_format) formatter.datetime_format = datetime_format if formatter.respond_to?(:datetime_format=) end alias :old_datetime_format :datetime_format # Get the logging datetime format. Returns nil if the formatter does not support # datetime formatting. def datetime_format formatter.datetime_format if formatter.respond_to?(:datetime_format) end alias :old_formatter :formatter if method_defined?(:formatter) # Get the current formatter. The default formatter is a SimpleFormatter which only # displays the log message def formatter @formatter ||= SimpleFormatter.new end unless const_defined? :Formatter class Formatter Format = "%s, [%s#%d] %5s -- %s: %s\n" attr_accessor :datetime_format def initialize @datetime_format = nil end def call(severity, time, progname, msg) Format % [severity[0..0], format_datetime(time), $$, severity, progname, msg2str(msg)] end private def format_datetime(time) if @datetime_format.nil? time.strftime("%Y-%m-%dT%H:%M:%S.") << "%06d " % time.usec else time.strftime(@datetime_format) end end def msg2str(msg) case msg when ::String msg when ::Exception "#{ msg.message } (#{ msg.class })\n" << (msg.backtrace || []).join("\n") else msg.inspect end end end end # Simple formatter which only displays the message. class SimpleFormatter < Logger::Formatter # This method is invoked when a log event occurs def call(severity, timestamp, progname, msg) "#{String === msg ? msg : msg.inspect}\n" end end private alias old_format_message format_message # Ruby 1.8.3 transposed the msg and progname arguments to format_message. # We can't test RUBY_VERSION because some distributions don't keep Ruby # and its standard library in sync, leading to installations of Ruby 1.8.2 # with Logger from 1.8.3 and vice versa. if method_defined?(:formatter=) def format_message(severity, timestamp, progname, msg) formatter.call(severity, timestamp, progname, msg) end else def format_message(severity, timestamp, msg, progname) formatter.call(severity, timestamp, progname, msg) end attr_writer :formatter public :formatter= alias old_format_datetime format_datetime def format_datetime(datetime) datetime end alias old_msg2str msg2str def msg2str(msg) msg end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/duplicable.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/duplicable.rb
class Object # Can you safely .dup this object? # False for nil, false, true, symbols, and numbers; true otherwise. def duplicable? true end end class NilClass #:nodoc: def duplicable? false end end class FalseClass #:nodoc: def duplicable? false end end class TrueClass #:nodoc: def duplicable? false end end class Symbol #:nodoc: def duplicable? false end end class Numeric #:nodoc: def duplicable? false end end class Class #:nodoc: def duplicable? false end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/blank.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/blank.rb
class Object # An object is blank if it's false, empty, or a whitespace string. # For example, "", " ", +nil+, [], and {} are blank. # # This simplifies # # if !address.nil? && !address.empty? # # to # # if !address.blank? def blank? respond_to?(:empty?) ? empty? : !self end # An object is present if it's not blank. def present? !blank? end end class NilClass #:nodoc: def blank? true end end class FalseClass #:nodoc: def blank? true end end class TrueClass #:nodoc: def blank? false end end class Array #:nodoc: alias_method :blank?, :empty? end class Hash #:nodoc: alias_method :blank?, :empty? end class String #:nodoc: def blank? self !~ /\S/ end end class Numeric #:nodoc: def blank? false end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/benchmark.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/benchmark.rb
require 'benchmark' class << Benchmark # Earlier Ruby had a slower implementation. if RUBY_VERSION < '1.8.7' remove_method :realtime def realtime r0 = Time.now yield r1 = Time.now r1.to_f - r0.to_f end end def ms 1000 * realtime { yield } end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/array.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/array.rb
require 'active_support/core_ext/array/access' require 'active_support/core_ext/array/conversions' require 'active_support/core_ext/array/extract_options' require 'active_support/core_ext/array/grouping' require 'active_support/core_ext/array/random_access' require 'active_support/core_ext/array/wrapper' class Array #:nodoc: include ActiveSupport::CoreExtensions::Array::Access include ActiveSupport::CoreExtensions::Array::Conversions include ActiveSupport::CoreExtensions::Array::ExtractOptions include ActiveSupport::CoreExtensions::Array::Grouping include ActiveSupport::CoreExtensions::Array::RandomAccess extend ActiveSupport::CoreExtensions::Array::Wrapper end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/time.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/time.rb
require 'date' require 'time' class Time # Ruby 1.8-cvs and 1.9 define private Time#to_date %w(to_date to_datetime).each do |method| public method if private_instance_methods.include?(method) end # Pre-1.9 versions of Ruby have a bug with marshaling Time instances, where utc instances are # unmarshaled in the local zone, instead of utc. We're layering behavior on the _dump and _load # methods so that utc instances can be flagged on dump, and coerced back to utc on load. if RUBY_VERSION < '1.9' class << self alias_method :_original_load, :_load def _load(marshaled_time) time = _original_load(marshaled_time) utc = time.instance_variable_get('@marshal_with_utc_coercion') utc ? time.utc : time end end alias_method :_original_dump, :_dump def _dump(*args) obj = self.frozen? ? self.dup : self obj.instance_variable_set('@marshal_with_utc_coercion', utc?) obj._original_dump(*args) end end end require 'active_support/core_ext/time/behavior' require 'active_support/core_ext/time/calculations' require 'active_support/core_ext/time/conversions' require 'active_support/core_ext/time/zones' class Time#:nodoc: include ActiveSupport::CoreExtensions::Time::Behavior include ActiveSupport::CoreExtensions::Time::Calculations include ActiveSupport::CoreExtensions::Time::Conversions include ActiveSupport::CoreExtensions::Time::Zones end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/file.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/file.rb
require 'active_support/core_ext/file/atomic' class File #:nodoc: extend ActiveSupport::CoreExtensions::File::Atomic end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/float.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/float.rb
require 'active_support/core_ext/float/rounding' require 'active_support/core_ext/float/time' class Float #:nodoc: include ActiveSupport::CoreExtensions::Float::Rounding include ActiveSupport::CoreExtensions::Float::Time end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/kernel.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/kernel.rb
require 'active_support/core_ext/kernel/daemonizing' require 'active_support/core_ext/kernel/reporting' require 'active_support/core_ext/kernel/agnostics' require 'active_support/core_ext/kernel/requires' require 'active_support/core_ext/kernel/debugger'
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/base64.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/base64.rb
require 'active_support/base64' require 'active_support/core_ext/base64/encoding' ActiveSupport::Base64.extend ActiveSupport::CoreExtensions::Base64::Encoding
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/uri.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/uri.rb
if RUBY_VERSION >= '1.9' require 'uri' str = "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E" # Ni-ho-nn-go in UTF-8, means Japanese. str.force_encoding(Encoding::UTF_8) if str.respond_to?(:force_encoding) unless str == URI.unescape(URI.escape(str)) URI::Parser.class_eval do remove_method :unescape def unescape(str, escaped = @regexp[:ESCAPED]) enc = (str.encoding == Encoding::US_ASCII) ? Encoding::UTF_8 : str.encoding str.gsub(escaped) { [$&[1, 2].hex].pack('C') }.force_encoding(enc) end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/rexml.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/rexml.rb
# Fixes the rexml vulnerability disclosed at: # http://www.ruby-lang.org/en/news/2008/08/23/dos-vulnerability-in-rexml/ # This fix is identical to rexml-expansion-fix version 1.0.1 require 'rexml/rexml' # Earlier versions of rexml defined REXML::Version, newer ones REXML::VERSION unless (defined?(REXML::VERSION) ? REXML::VERSION : REXML::Version) > "3.1.7.2" require 'rexml/document' # REXML in 1.8.7 has the patch but didn't update Version from 3.1.7.2. unless REXML::Document.respond_to?(:entity_expansion_limit=) require 'rexml/entity' module REXML class Entity < Child undef_method :unnormalized def unnormalized document.record_entity_expansion! if document v = value() return nil if v.nil? @unnormalized = Text::unnormalize(v, parent) @unnormalized end end class Document < Element @@entity_expansion_limit = 10_000 def self.entity_expansion_limit= val @@entity_expansion_limit = val end def record_entity_expansion! @number_of_expansions ||= 0 @number_of_expansions += 1 if @number_of_expansions > @@entity_expansion_limit raise "Number of entity expansions exceeded, processing aborted." end end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/exception.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/exception.rb
module ActiveSupport if RUBY_VERSION >= '1.9' FrozenObjectError = RuntimeError else FrozenObjectError = TypeError end end # TODO: Turn all this into using the BacktraceCleaner. class Exception # :nodoc: def clean_message Pathname.clean_within message end TraceSubstitutions = [] FrameworkStart = /action_controller\/dispatcher\.rb/.freeze FrameworkRegexp = /generated|vendor|dispatch|ruby|script\/\w+/.freeze def clean_backtrace backtrace.collect do |line| Pathname.clean_within(TraceSubstitutions.inject(line) do |result, (regexp, sub)| result.gsub regexp, sub end) end end def application_backtrace before_framework_frame = nil before_application_frame = true trace = clean_backtrace.reject do |line| before_framework_frame ||= (line =~ FrameworkStart) non_app_frame = (line =~ FrameworkRegexp) before_application_frame = false unless non_app_frame before_framework_frame || (non_app_frame && !before_application_frame) end # If we didn't find any application frames, return an empty app trace. before_application_frame ? [] : trace end def framework_backtrace clean_backtrace.grep FrameworkRegexp end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/class.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/class.rb
require 'active_support/core_ext/class/attribute_accessors' require 'active_support/core_ext/class/inheritable_attributes' require 'active_support/core_ext/class/removal' require 'active_support/core_ext/class/delegating_attributes'
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/try.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/try.rb
class Object # Invokes the method identified by the symbol +method+, passing it any arguments # and/or the block specified, just like the regular Ruby <tt>Object#send</tt> does. # # *Unlike* that method however, a +NoMethodError+ exception will *not* be raised # and +nil+ will be returned instead, if the receiving object is a +nil+ object or NilClass. # # ==== Examples # # Without try # @person && @person.name # or # @person ? @person.name : nil # # With try # @person.try(:name) # # +try+ also accepts arguments and/or a block, for the method it is trying # Person.try(:find, 1) # @people.try(:collect) {|p| p.name} #-- # This method definition below is for rdoc purposes only. The alias_method call # below overrides it as an optimization since +try+ behaves like +Object#send+, # unless called on +NilClass+. def try(method, *args, &block) send(method, *args, &block) end remove_method :try alias_method :try, :__send__ end class NilClass def try(*args) nil end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/string.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/string.rb
# encoding: utf-8 require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/string/bytesize' require 'active_support/core_ext/string/conversions' require 'active_support/core_ext/string/access' require 'active_support/core_ext/string/starts_ends_with' require 'active_support/core_ext/string/iterators' require 'active_support/core_ext/string/multibyte' require 'active_support/core_ext/string/xchar' require 'active_support/core_ext/string/filters' require 'active_support/core_ext/string/behavior' class String #:nodoc: include ActiveSupport::CoreExtensions::String::Access include ActiveSupport::CoreExtensions::String::Conversions include ActiveSupport::CoreExtensions::String::Filters include ActiveSupport::CoreExtensions::String::Inflections include ActiveSupport::CoreExtensions::String::StartsEndsWith include ActiveSupport::CoreExtensions::String::Iterators include ActiveSupport::CoreExtensions::String::Behavior include ActiveSupport::CoreExtensions::String::Multibyte end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/process.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/process.rb
require 'active_support/core_ext/process/daemon'
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/object.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/object.rb
require 'active_support/core_ext/object/conversions' require 'active_support/core_ext/object/extending' require 'active_support/core_ext/object/instance_variables' require 'active_support/core_ext/object/metaclass' require 'active_support/core_ext/object/misc'
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/enumerable.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/enumerable.rb
require 'active_support/ordered_hash' module Enumerable # Ruby 1.8.7 introduces group_by, but the result isn't ordered. Override it. remove_method(:group_by) if [].respond_to?(:group_by) && RUBY_VERSION < '1.9' # Collect an enumerable into sets, grouped by the result of a block. Useful, # for example, for grouping records by date. # # Example: # # latest_transcripts.group_by(&:day).each do |day, transcripts| # p "#{day} -> #{transcripts.map(&:class).join(', ')}" # end # "2006-03-01 -> Transcript" # "2006-02-28 -> Transcript" # "2006-02-27 -> Transcript, Transcript" # "2006-02-26 -> Transcript, Transcript" # "2006-02-25 -> Transcript" # "2006-02-24 -> Transcript, Transcript" # "2006-02-23 -> Transcript" def group_by assoc = ActiveSupport::OrderedHash.new each do |element| key = yield(element) if assoc.has_key?(key) assoc[key] << element else assoc[key] = [element] end end assoc end unless [].respond_to?(:group_by) # Calculates a sum from the elements. Examples: # # payments.sum { |p| p.price * p.tax_rate } # payments.sum(&:price) # # The latter is a shortcut for: # # payments.inject { |sum, p| sum + p.price } # # It can also calculate the sum without the use of a block. # # [5, 15, 10].sum # => 30 # ["foo", "bar"].sum # => "foobar" # [[1, 2], [3, 1, 5]].sum => [1, 2, 3, 1, 5] # # The default sum of an empty list is zero. You can override this default: # # [].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0) # def sum(identity = 0, &block) if block_given? map(&block).sum(identity) else inject { |sum, element| sum + element } || identity end end # Iterates over a collection, passing the current element *and* the # +memo+ to the block. Handy for building up hashes or # reducing collections down to one object. Examples: # # %w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase } #=> {'foo' => 'FOO', 'bar' => 'BAR'} # # *Note* that you can't use immutable objects like numbers, true or false as # the memo. You would think the following returns 120, but since the memo is # never changed, it does not. # # (1..5).each_with_object(1) { |value, memo| memo *= value } # => 1 # def each_with_object(memo, &block) returning memo do |m| each do |element| block.call(element, m) end end end unless [].respond_to?(:each_with_object) # Convert an enumerable to a hash. Examples: # # people.index_by(&:login) # => { "nextangle" => <Person ...>, "chade-" => <Person ...>, ...} # people.index_by { |person| "#{person.first_name} #{person.last_name}" } # => { "Chade- Fowlersburg-e" => <Person ...>, "David Heinemeier Hansson" => <Person ...>, ...} # def index_by inject({}) do |accum, elem| accum[yield(elem)] = elem accum end end # Returns true if the collection has more than 1 element. Functionally equivalent to collection.size > 1. # Works with a block too ala any?, so people.many? { |p| p.age > 26 } # => returns true if more than 1 person is over 26. def many?(&block) size = block_given? ? select(&block).size : self.size size > 1 end # Returns true if none of the elements match the given block. # # success = responses.none? {|r| r.status / 100 == 5 } # # This is a builtin method in Ruby 1.8.7 and later. def none?(&block) !any?(&block) end unless [].respond_to?(:none?) end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/pathname.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/pathname.rb
require 'pathname' require 'active_support/core_ext/pathname/clean_within' class Pathname#:nodoc: extend ActiveSupport::CoreExtensions::Pathname::CleanWithin end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/integer.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/integer.rb
require 'active_support/core_ext/integer/even_odd' require 'active_support/core_ext/integer/inflections' require 'active_support/core_ext/integer/time' class Integer #:nodoc: include ActiveSupport::CoreExtensions::Integer::EvenOdd include ActiveSupport::CoreExtensions::Integer::Inflections include ActiveSupport::CoreExtensions::Integer::Time end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/cgi.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/cgi.rb
require 'active_support/core_ext/cgi/escape_skipping_slashes' class CGI #:nodoc: extend ActiveSupport::CoreExtensions::CGI::EscapeSkippingSlashes end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/module.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/module.rb
require 'active_support/core_ext/module/inclusion' require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/module/attr_internal' require 'active_support/core_ext/module/attr_accessor_with_default' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/module/introspection' require 'active_support/core_ext/module/loading' require 'active_support/core_ext/module/aliasing' require 'active_support/core_ext/module/model_naming' require 'active_support/core_ext/module/synchronization' module ActiveSupport module CoreExtensions # Various extensions for the Ruby core Module class. module Module # Nothing here. Only defined for API documentation purposes. end end end class Module include ActiveSupport::CoreExtensions::Module end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/bigdecimal.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/bigdecimal.rb
require 'bigdecimal' require 'active_support/core_ext/bigdecimal/conversions' class BigDecimal#:nodoc: include ActiveSupport::CoreExtensions::BigDecimal::Conversions end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/date_time.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/date_time.rb
require 'date' require 'active_support/core_ext/time/behavior' require 'active_support/core_ext/time/zones' require 'active_support/core_ext/date_time/calculations' require 'active_support/core_ext/date_time/conversions' class DateTime include ActiveSupport::CoreExtensions::Time::Behavior include ActiveSupport::CoreExtensions::Time::Zones include ActiveSupport::CoreExtensions::DateTime::Calculations include ActiveSupport::CoreExtensions::DateTime::Conversions end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/hash.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/hash.rb
%w(keys indifferent_access deep_merge reverse_merge conversions diff slice except).each do |ext| require "active_support/core_ext/hash/#{ext}" end class Hash #:nodoc: include ActiveSupport::CoreExtensions::Hash::Keys include ActiveSupport::CoreExtensions::Hash::IndifferentAccess include ActiveSupport::CoreExtensions::Hash::DeepMerge include ActiveSupport::CoreExtensions::Hash::ReverseMerge include ActiveSupport::CoreExtensions::Hash::Conversions include ActiveSupport::CoreExtensions::Hash::Diff include ActiveSupport::CoreExtensions::Hash::Slice include ActiveSupport::CoreExtensions::Hash::Except end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/date.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/date.rb
require 'date' require 'active_support/core_ext/date/behavior' require 'active_support/core_ext/date/calculations' require 'active_support/core_ext/date/conversions' class Date#:nodoc: include ActiveSupport::CoreExtensions::Date::Behavior include ActiveSupport::CoreExtensions::Date::Calculations include ActiveSupport::CoreExtensions::Date::Conversions end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/symbol.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/symbol.rb
unless :to_proc.respond_to?(:to_proc) class Symbol # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples: # # # The same as people.collect { |p| p.name } # people.collect(&:name) # # # The same as people.select { |p| p.manager? }.collect { |p| p.salary } # people.select(&:manager?).collect(&:salary) def to_proc Proc.new { |*args| args.shift.__send__(self, *args) } end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/numeric.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/numeric.rb
require 'active_support/core_ext/numeric/time' require 'active_support/core_ext/numeric/bytes' require 'active_support/core_ext/numeric/conversions' class Numeric #:nodoc: include ActiveSupport::CoreExtensions::Numeric::Time include ActiveSupport::CoreExtensions::Numeric::Bytes include ActiveSupport::CoreExtensions::Numeric::Conversions end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/string/bytesize.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/string/bytesize.rb
unless '1.9'.respond_to?(:bytesize) class String alias :bytesize :size end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/string/conversions.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/string/conversions.rb
require 'date' module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module String #:nodoc: # Converting strings to other objects module Conversions # 'a'.ord == 'a'[0] for Ruby 1.9 forward compatibility. def ord self[0] end if RUBY_VERSION < '1.9' # Form can be either :utc (default) or :local. def to_time(form = :utc) ::Time.send("#{form}_time", *::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec).map { |arg| arg || 0 }) end def to_date ::Date.new(*::Date._parse(self, false).values_at(:year, :mon, :mday)) end def to_datetime ::DateTime.civil(*::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec).map { |arg| arg || 0 }) end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/string/access.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/string/access.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module String #:nodoc: unless '1.9'.respond_to?(:force_encoding) # Makes it easier to access parts of a string, such as specific characters and substrings. module Access # Returns the character at the +position+ treating the string as an array (where 0 is the first character). # # Examples: # "hello".at(0) # => "h" # "hello".at(4) # => "o" # "hello".at(10) # => nil def at(position) mb_chars[position, 1].to_s end # Returns the remaining of the string from the +position+ treating the string as an array (where 0 is the first character). # # Examples: # "hello".from(0) # => "hello" # "hello".from(2) # => "llo" # "hello".from(10) # => nil def from(position) mb_chars[position..-1].to_s end # Returns the beginning of the string up to the +position+ treating the string as an array (where 0 is the first character). # # Examples: # "hello".to(0) # => "h" # "hello".to(2) # => "hel" # "hello".to(10) # => "hello" def to(position) mb_chars[0..position].to_s end # Returns the first character of the string or the first +limit+ characters. # # Examples: # "hello".first # => "h" # "hello".first(2) # => "he" # "hello".first(10) # => "hello" def first(limit = 1) if limit == 0 '' elsif limit >= size self else mb_chars[0...limit].to_s end end # Returns the last character of the string or the last +limit+ characters. # # Examples: # "hello".last # => "o" # "hello".last(2) # => "lo" # "hello".last(10) # => "hello" def last(limit = 1) if limit == 0 '' elsif limit >= size self else mb_chars[(-limit)..-1].to_s end end end else module Access #:nodoc: def at(position) self[position] end def from(position) self[position..-1] end def to(position) self[0..position] end def first(limit = 1) if limit == 0 '' elsif limit >= size self else to(limit - 1) end end def last(limit = 1) if limit == 0 '' elsif limit >= size self else from(-limit) end end end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module String #:nodoc: # Additional string tests. module StartsEndsWith def self.append_features(base) if '1.8.7 and up'.respond_to?(:start_with?) base.class_eval do alias_method :starts_with?, :start_with? alias_method :ends_with?, :end_with? end else super base.class_eval do alias_method :start_with?, :starts_with? alias_method :end_with?, :ends_with? end end end # Does the string start with the specified +prefix+? def starts_with?(prefix) prefix = prefix.to_s self[0, prefix.length] == prefix end # Does the string end with the specified +suffix+? def ends_with?(suffix) suffix = suffix.to_s self[-suffix.length, suffix.length] == suffix end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb
require 'active_support/inflector' unless defined?(ActiveSupport::Inflector) module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module String #:nodoc: # String inflections define new methods on the String class to transform names for different purposes. # For instance, you can figure out the name of a database from the name of a class. # # "ScaleScore".tableize # => "scale_scores" module Inflections # Returns the plural form of the word in the string. # # "post".pluralize # => "posts" # "octopus".pluralize # => "octopi" # "sheep".pluralize # => "sheep" # "words".pluralize # => "words" # "the blue mailman".pluralize # => "the blue mailmen" # "CamelOctopus".pluralize # => "CamelOctopi" def pluralize Inflector.pluralize(self) end # The reverse of +pluralize+, returns the singular form of a word in a string. # # "posts".singularize # => "post" # "octopi".singularize # => "octopus" # "sheep".singularize # => "sheep" # "word".singularize # => "word" # "the blue mailmen".singularize # => "the blue mailman" # "CamelOctopi".singularize # => "CamelOctopus" def singularize Inflector.singularize(self) end # By default, +camelize+ converts strings to UpperCamelCase. If the argument to camelize # is set to <tt>:lower</tt> then camelize produces lowerCamelCase. # # +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces. # # "active_record".camelize # => "ActiveRecord" # "active_record".camelize(:lower) # => "activeRecord" # "active_record/errors".camelize # => "ActiveRecord::Errors" # "active_record/errors".camelize(:lower) # => "activeRecord::Errors" def camelize(first_letter = :upper) case first_letter when :upper then Inflector.camelize(self, true) when :lower then Inflector.camelize(self, false) end end alias_method :camelcase, :camelize # Capitalizes all the words and replaces some characters in the string to create # a nicer looking title. +titleize+ is meant for creating pretty output. It is not # used in the Rails internals. # # +titleize+ is also aliased as +titlecase+. # # "man from the boondocks".titleize # => "Man From The Boondocks" # "x-men: the last stand".titleize # => "X Men: The Last Stand" def titleize Inflector.titleize(self) end alias_method :titlecase, :titleize # The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string. # # +underscore+ will also change '::' to '/' to convert namespaces to paths. # # "ActiveRecord".underscore # => "active_record" # "ActiveRecord::Errors".underscore # => active_record/errors def underscore Inflector.underscore(self) end # Replaces underscores with dashes in the string. # # "puni_puni" # => "puni-puni" def dasherize Inflector.dasherize(self) end # Removes the module part from the constant expression in the string. # # "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections" # "Inflections".demodulize # => "Inflections" def demodulize Inflector.demodulize(self) end # Replaces special characters in a string so that it may be used as part of a 'pretty' URL. # # ==== Examples # # class Person # def to_param # "#{id}-#{name.parameterize}" # end # end # # @person = Person.find(1) # # => #<Person id: 1, name: "Donald E. Knuth"> # # <%= link_to(@person.name, person_path %> # # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a> def parameterize(sep = '-') Inflector.parameterize(self, sep) end # Creates the name of a table like Rails does for models to table names. This method # uses the +pluralize+ method on the last word in the string. # # "RawScaledScorer".tableize # => "raw_scaled_scorers" # "egg_and_ham".tableize # => "egg_and_hams" # "fancyCategory".tableize # => "fancy_categories" def tableize Inflector.tableize(self) end # Create a class name from a plural table name like Rails does for table names to models. # Note that this returns a string and not a class. (To convert to an actual class # follow +classify+ with +constantize+.) # # "egg_and_hams".classify # => "EggAndHam" # "posts".classify # => "Post" # # Singular names are not handled correctly. # # "business".classify # => "Busines" def classify Inflector.classify(self) end # Capitalizes the first word, turns underscores into spaces, and strips '_id'. # Like +titleize+, this is meant for creating pretty output. # # "employee_salary" # => "Employee salary" # "author_id" # => "Author" def humanize Inflector.humanize(self) end # Creates a foreign key name from a class name. # +separate_class_name_and_id_with_underscore+ sets whether # the method should put '_' between the name and 'id'. # # Examples # "Message".foreign_key # => "message_id" # "Message".foreign_key(false) # => "messageid" # "Admin::Post".foreign_key # => "post_id" def foreign_key(separate_class_name_and_id_with_underscore = true) Inflector.foreign_key(self, separate_class_name_and_id_with_underscore) end # +constantize+ tries to find a declared constant with the name specified # in the string. It raises a NameError when the name is not in CamelCase # or is not initialized. # # Examples # "Module".constantize # => Module # "Class".constantize # => Class def constantize Inflector.constantize(self) end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/string/filters.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/string/filters.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module String #:nodoc: module Filters # Returns the string, first removing all whitespace on both ends of # the string, and then changing remaining consecutive whitespace # groups into one space each. # # Examples: # %{ Multi-line # string }.squish # => "Multi-line string" # " foo bar \n \t boo".squish # => "foo bar boo" def squish dup.squish! end # Performs a destructive squish. See String#squish. def squish! strip! gsub!(/\s+/, ' ') self end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/string/iterators.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/string/iterators.rb
require 'strscan' module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module String #:nodoc: # Custom string iterators module Iterators def self.append_features(base) super unless '1.9'.respond_to?(:each_char) end # Yields a single-character string for each character in the string. # When $KCODE = 'UTF8', multi-byte characters are yielded appropriately. def each_char scanner, char = StringScanner.new(self), /./mu while c = scanner.scan(char) yield c end end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/string/behavior.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/string/behavior.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module String #:nodoc: module Behavior # Enable more predictable duck-typing on String-like classes. See # Object#acts_like?. def acts_like_string? true end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/string/xchar.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/string/xchar.rb
begin # See http://bogomips.org/fast_xs/ by Eric Wong require 'fast_xs' class String alias_method :original_xs, :to_xs if method_defined?(:to_xs) alias_method :to_xs, :fast_xs end rescue LoadError # fast_xs extension unavailable. end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/string/multibyte.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/string/multibyte.rb
# encoding: utf-8 module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module String #:nodoc: # Implements multibyte methods for easier access to multibyte characters in a String instance. module Multibyte unless '1.9'.respond_to?(:force_encoding) # == Multibyte proxy # # +mb_chars+ is a multibyte safe proxy for string methods. # # In Ruby 1.8 and older it creates and returns an instance of the ActiveSupport::Multibyte::Chars class which # encapsulates the original string. A Unicode safe version of all the String methods are defined on this proxy # class. If the proxy class doesn't respond to a certain method, it's forwarded to the encapsuled string. # # name = 'Claus Müller' # name.reverse #=> "rell??M sualC" # name.length #=> 13 # # name.mb_chars.reverse.to_s #=> "rellüM sualC" # name.mb_chars.length #=> 12 # # In Ruby 1.9 and newer +mb_chars+ returns +self+ because String is (mostly) encoding aware. This means that # it becomes easy to run one version of your code on multiple Ruby versions. # # == Method chaining # # All the methods on the Chars proxy which normally return a string will return a Chars object. This allows # method chaining on the result of any of these methods. # # name.mb_chars.reverse.length #=> 12 # # == Interoperability and configuration # # The Chars object tries to be as interchangeable with String objects as possible: sorting and comparing between # String and Char work like expected. The bang! methods change the internal string representation in the Chars # object. Interoperability problems can be resolved easily with a +to_s+ call. # # For more information about the methods defined on the Chars proxy see ActiveSupport::Multibyte::Chars. For # information about how to change the default Multibyte behaviour see ActiveSupport::Multibyte. def mb_chars if ActiveSupport::Multibyte.proxy_class.wants?(self) ActiveSupport::Multibyte.proxy_class.new(self) else self end end # Returns true if the string has UTF-8 semantics (a String used for purely byte resources is unlikely to have # them), returns false otherwise. def is_utf8? ActiveSupport::Multibyte::Chars.consumes?(self) end unless '1.8.7 and later'.respond_to?(:chars) def chars ActiveSupport::Deprecation.warn('String#chars has been deprecated in favor of String#mb_chars.', caller) mb_chars end end else def mb_chars #:nodoc self end def is_utf8? #:nodoc case encoding when Encoding::UTF_8 valid_encoding? when Encoding::ASCII_8BIT, Encoding::US_ASCII dup.force_encoding(Encoding::UTF_8).valid_encoding? else false end end end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/pathname/clean_within.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/pathname/clean_within.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Pathname #:nodoc: module CleanWithin # Clean the paths contained in the provided string. def clean_within(string) string.gsub(%r{[\w. ]+(/[\w. ]+)+(\.rb)?(\b|$)}) do |path| new(path).cleanpath end end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module CGI #:nodoc: module EscapeSkippingSlashes #:nodoc: if RUBY_VERSION >= '1.9' def escape_skipping_slashes(str) str = str.join('/') if str.respond_to? :join str.gsub(/([^ \/a-zA-Z0-9_.-])/n) do "%#{$1.unpack('H2' * $1.bytesize).join('%').upcase}" end.tr(' ', '+') end else def escape_skipping_slashes(str) str = str.join('/') if str.respond_to? :join str.gsub(/([^ \/a-zA-Z0-9_.-])/n) do "%#{$1.unpack('H2').first.upcase}" end.tr(' ', '+') end end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/process/daemon.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/process/daemon.rb
if RUBY_VERSION < "1.9" module Process def self.daemon(nochdir = nil, noclose = nil) exit if fork # Parent exits, child continues. Process.setsid # Become session leader. exit if fork # Zap session leader. See [1]. unless nochdir Dir.chdir "/" # Release old working directory. end File.umask 0000 # Ensure sensible umask. Adjust as needed. unless noclose STDIN.reopen "/dev/null" # Free file descriptors and STDOUT.reopen "/dev/null", "a" # point them somewhere sensible. STDERR.reopen '/dev/null', 'a' end trap("TERM") { exit } return 0 end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/file/atomic.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/file/atomic.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module File #:nodoc: module Atomic # Write to a file atomically. Useful for situations where you don't # want other processes or threads to see half-written files. # # File.atomic_write("important.file") do |file| # file.write("hello") # end # # If your temp directory is not on the same filesystem as the file you're # trying to write, you can provide a different temporary directory. # # File.atomic_write("/data/something.important", "/data/tmp") do |f| # file.write("hello") # end def atomic_write(file_name, temp_dir = Dir.tmpdir) require 'tempfile' unless defined?(Tempfile) temp_file = Tempfile.new(basename(file_name), temp_dir) yield temp_file temp_file.close begin # Get original file permissions old_stat = stat(file_name) rescue Errno::ENOENT # No old permissions, write a temp file to determine the defaults check_name = join(dirname(file_name), ".permissions_check.#{Thread.current.object_id}.#{Process.pid}.#{rand(1000000)}") open(check_name, "w") { } old_stat = stat(check_name) unlink(check_name) end # Overwrite original file with temp file rename(temp_file.path, file_name) # Set correct permissions on new file chown(old_stat.uid, old_stat.gid, file_name) chmod(old_stat.mode, file_name) end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/hash/slice.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/hash/slice.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Hash #:nodoc: # Slice a hash to include only the given keys. This is useful for # limiting an options hash to valid keys before passing to a method: # # def search(criteria = {}) # assert_valid_keys(:mass, :velocity, :time) # end # # search(options.slice(:mass, :velocity, :time)) # # If you have an array of keys you want to limit to, you should splat them: # # valid_keys = [:mass, :velocity, :time] # search(options.slice(*valid_keys)) module Slice # Returns a new hash with only the given keys. def slice(*keys) keys = keys.map! { |key| convert_key(key) } if respond_to?(:convert_key) hash = self.class.new keys.each { |k| hash[k] = self[k] if has_key?(k) } hash end # Replaces the hash with only the given keys. # Returns a hash contained the removed key/value pairs # {:a => 1, :b => 2, :c => 3, :d => 4}.slice!(:a, :b) # => {:c => 3, :d =>4} def slice!(*keys) keys = keys.map! { |key| convert_key(key) } if respond_to?(:convert_key) omit = slice(*self.keys - keys) hash = slice(*keys) replace(hash) omit end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/hash/diff.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/hash/diff.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Hash #:nodoc: module Diff # Returns a hash that represents the difference between two hashes. # # Examples: # # {1 => 2}.diff(1 => 2) # => {} # {1 => 2}.diff(1 => 3) # => {1 => 2} # {}.diff(1 => 2) # => {1 => 2} # {1 => 2, 3 => 4}.diff(1 => 2) # => {3 => 4} def diff(h2) self.dup.delete_if { |k, v| h2[k] == v }.merge(h2.dup.delete_if { |k, v| self.has_key?(k) }) end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Hash #:nodoc: # Allows for reverse merging two hashes where the keys in the calling hash take precedence over those # in the <tt>other_hash</tt>. This is particularly useful for initializing an option hash with default values: # # def setup(options = {}) # options.reverse_merge! :size => 25, :velocity => 10 # end # # Using <tt>merge</tt>, the above example would look as follows: # # def setup(options = {}) # { :size => 25, :velocity => 10 }.merge(options) # end # # The default <tt>:size</tt> and <tt>:velocity</tt> are only set if the +options+ hash passed in doesn't already # have the respective key. module ReverseMerge # Performs the opposite of <tt>merge</tt>, with the keys and values from the first hash taking precedence over the second. def reverse_merge(other_hash) other_hash.merge(self) end # Performs the opposite of <tt>merge</tt>, with the keys and values from the first hash taking precedence over the second. # Modifies the receiver in place. def reverse_merge!(other_hash) replace(reverse_merge(other_hash)) end alias_method :reverse_update, :reverse_merge! end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/hash/keys.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/hash/keys.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Hash #:nodoc: module Keys # Return a new hash with all keys converted to strings. def stringify_keys inject({}) do |options, (key, value)| options[key.to_s] = value options end end # Destructively convert all keys to strings. def stringify_keys! keys.each do |key| self[key.to_s] = delete(key) end self end # Return a new hash with all keys converted to symbols. def symbolize_keys inject({}) do |options, (key, value)| options[(key.to_sym rescue key) || key] = value options end end # Destructively convert all keys to symbols. def symbolize_keys! self.replace(self.symbolize_keys) end alias_method :to_options, :symbolize_keys alias_method :to_options!, :symbolize_keys! # Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch. # Note that keys are NOT treated indifferently, meaning if you use strings for keys but assert symbols # as keys, this will fail. # # ==== Examples # { :name => "Rob", :years => "28" }.assert_valid_keys(:name, :age) # => raises "ArgumentError: Unknown key(s): years" # { :name => "Rob", :age => "28" }.assert_valid_keys("name", "age") # => raises "ArgumentError: Unknown key(s): name, age" # { :name => "Rob", :age => "28" }.assert_valid_keys(:name, :age) # => passes, raises nothing def assert_valid_keys(*valid_keys) unknown_keys = keys - [valid_keys].flatten raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty? end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/hash/conversions.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/hash/conversions.rb
require 'date' require 'active_support/core_ext/module/attribute_accessors' module ActiveSupport #:nodoc: # these accessors are here because people using ActiveResource and REST to integrate with other systems # have to be able to control the default behavior of rename_key. dasherize_xml is set to true to emulate # existing behavior. In a future version it should be set to false by default. mattr_accessor :dasherize_xml mattr_accessor :camelize_xml self.dasherize_xml = true self.camelize_xml = false module CoreExtensions #:nodoc: module Hash #:nodoc: module Conversions # This module exists to decorate files deserialized using Hash.from_xml with # the <tt>original_filename</tt> and <tt>content_type</tt> methods. module FileLike #:nodoc: attr_writer :original_filename, :content_type def original_filename @original_filename || 'untitled' end def content_type @content_type || 'application/octet-stream' end end XML_TYPE_NAMES = { "Symbol" => "symbol", "Fixnum" => "integer", "Bignum" => "integer", "BigDecimal" => "decimal", "Float" => "float", "TrueClass" => "boolean", "FalseClass" => "boolean", "Date" => "date", "DateTime" => "datetime", "Time" => "datetime", "ActiveSupport::TimeWithZone" => "datetime" } unless defined?(XML_TYPE_NAMES) XML_FORMATTING = { "symbol" => Proc.new { |symbol| symbol.to_s }, "date" => Proc.new { |date| date.to_s(:db) }, "datetime" => Proc.new { |time| time.xmlschema }, "binary" => Proc.new { |binary| ActiveSupport::Base64.encode64(binary) }, "yaml" => Proc.new { |yaml| yaml.to_yaml } } unless defined?(XML_FORMATTING) # TODO: use Time.xmlschema instead of Time.parse; # use regexp instead of Date.parse unless defined?(XML_PARSING) XML_PARSING = { "symbol" => Proc.new { |symbol| symbol.to_sym }, "date" => Proc.new { |date| ::Date.parse(date) }, "datetime" => Proc.new { |time| ::Time.parse(time).utc rescue ::DateTime.parse(time).utc }, "integer" => Proc.new { |integer| integer.to_i }, "float" => Proc.new { |float| float.to_f }, "decimal" => Proc.new { |number| BigDecimal(number) }, "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.strip) }, "string" => Proc.new { |string| string.to_s }, "yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml }, "base64Binary" => Proc.new { |bin| ActiveSupport::Base64.decode64(bin) }, "file" => Proc.new do |file, entity| f = StringIO.new(ActiveSupport::Base64.decode64(file)) f.extend(FileLike) f.original_filename = entity['name'] f.content_type = entity['content_type'] f end } XML_PARSING.update( "double" => XML_PARSING["float"], "dateTime" => XML_PARSING["datetime"] ) end def self.included(klass) klass.extend(ClassMethods) end # Converts a hash into a string suitable for use as a URL query string. An optional <tt>namespace</tt> can be # passed to enclose the param names (see example below). # # ==== Examples # { :name => 'David', :nationality => 'Danish' }.to_query # => "name=David&nationality=Danish" # # { :name => 'David', :nationality => 'Danish' }.to_query('user') # => "user%5Bname%5D=David&user%5Bnationality%5D=Danish" def to_query(namespace = nil) collect do |key, value| value.to_query(namespace ? "#{namespace}[#{key}]" : key) end.sort * '&' end alias_method :to_param, :to_query def to_xml(options = {}) require 'builder' unless defined?(Builder) options = options.dup options[:indent] ||= 2 options.reverse_merge!({ :builder => Builder::XmlMarkup.new(:indent => options[:indent]), :root => "hash" }) options[:builder].instruct! unless options.delete(:skip_instruct) root = rename_key(options[:root].to_s, options) options[:builder].__send__(:method_missing, root) do each do |key, value| case value when ::Hash value.to_xml(options.merge({ :root => key, :skip_instruct => true })) when ::Array value.to_xml(options.merge({ :root => key, :children => key.to_s.singularize, :skip_instruct => true})) when ::Method, ::Proc # If the Method or Proc takes two arguments, then # pass the suggested child element name. This is # used if the Method or Proc will be operating over # multiple records and needs to create an containing # element that will contain the objects being # serialized. if 1 == value.arity value.call(options.merge({ :root => key, :skip_instruct => true })) else value.call(options.merge({ :root => key, :skip_instruct => true }), key.to_s.singularize) end else if value.respond_to?(:to_xml) value.to_xml(options.merge({ :root => key, :skip_instruct => true })) else type_name = XML_TYPE_NAMES[value.class.name] key = rename_key(key.to_s, options) attributes = options[:skip_types] || value.nil? || type_name.nil? ? { } : { :type => type_name } if value.nil? attributes[:nil] = true end options[:builder].tag!(key, XML_FORMATTING[type_name] ? XML_FORMATTING[type_name].call(value) : value, attributes ) end end end yield options[:builder] if block_given? end end def rename_key(key, options = {}) camelize = options.has_key?(:camelize) ? options[:camelize] : ActiveSupport.camelize_xml dasherize = options.has_key?(:dasherize) ? options[:dasherize] : ActiveSupport.dasherize_xml key = key.camelize if camelize key = key.dasherize if dasherize key end module ClassMethods def from_xml(xml) typecast_xml_value(unrename_keys(XmlMini.parse(xml))) end private def typecast_xml_value(value) case value.class.to_s when 'Hash' if value['type'] == 'array' child_key, entries = value.detect { |k,v| k != 'type' } # child_key is throwaway if entries.nil? || (c = value['__content__'] && c.blank?) [] else case entries.class.to_s # something weird with classes not matching here. maybe singleton methods breaking is_a? when "Array" entries.collect { |v| typecast_xml_value(v) } when "Hash" [typecast_xml_value(entries)] else raise "can't typecast #{entries.inspect}" end end elsif value.has_key?("__content__") content = value["__content__"] if parser = XML_PARSING[value["type"]] if parser.arity == 2 XML_PARSING[value["type"]].call(content, value) else XML_PARSING[value["type"]].call(content) end else content end elsif value['type'] == 'string' && value['nil'] != 'true' "" # blank or nil parsed values are represented by nil elsif value.blank? || value['nil'] == 'true' nil # If the type is the only element which makes it then # this still makes the value nil, except if type is # a XML node(where type['value'] is a Hash) elsif value['type'] && value.size == 1 && !value['type'].is_a?(::Hash) nil else xml_value = value.inject({}) do |h,(k,v)| h[k] = typecast_xml_value(v) h end # Turn { :files => { :file => #<StringIO> } into { :files => #<StringIO> } so it is compatible with # how multipart uploaded files from HTML appear xml_value["file"].is_a?(StringIO) ? xml_value["file"] : xml_value end when 'Array' value.map! { |i| typecast_xml_value(i) } case value.length when 0 then nil when 1 then value.first else value end when 'String' value else raise "can't typecast #{value.class.name} - #{value.inspect}" end end def unrename_keys(params) case params.class.to_s when "Hash" params.inject({}) do |h,(k,v)| h[k.to_s.tr("-", "_")] = unrename_keys(v) h end when "Array" params.map { |v| unrename_keys(v) } else params end end end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb
# This class has dubious semantics and we only have it so that # people can write params[:key] instead of params['key'] # and they get the same value for both keys. class HashWithIndifferentAccess < Hash def initialize(constructor = {}) if constructor.is_a?(Hash) super() update(constructor) else super(constructor) end end def default(key = nil) if key.is_a?(Symbol) && include?(key = key.to_s) self[key] else super end end alias_method :regular_writer, :[]= unless method_defined?(:regular_writer) alias_method :regular_update, :update unless method_defined?(:regular_update) # Assigns a new value to the hash: # # hash = HashWithIndifferentAccess.new # hash[:key] = "value" # def []=(key, value) regular_writer(convert_key(key), convert_value(value)) end # Updates the instantized hash with values from the second: # # hash_1 = HashWithIndifferentAccess.new # hash_1[:key] = "value" # # hash_2 = HashWithIndifferentAccess.new # hash_2[:key] = "New Value!" # # hash_1.update(hash_2) # => {"key"=>"New Value!"} # def update(other_hash) other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) } self end alias_method :merge!, :update # Checks the hash for a key matching the argument passed in: # # hash = HashWithIndifferentAccess.new # hash["key"] = "value" # hash.key? :key # => true # hash.key? "key" # => true # def key?(key) super(convert_key(key)) end alias_method :include?, :key? alias_method :has_key?, :key? alias_method :member?, :key? # Fetches the value for the specified key, same as doing hash[key] def fetch(key, *extras) super(convert_key(key), *extras) end # Returns an array of the values at the specified indices: # # hash = HashWithIndifferentAccess.new # hash[:a] = "x" # hash[:b] = "y" # hash.values_at("a", "b") # => ["x", "y"] # def values_at(*indices) indices.collect {|key| self[convert_key(key)]} end # Returns an exact copy of the hash. def dup HashWithIndifferentAccess.new(self) end # Merges the instantized and the specified hashes together, giving precedence to the values from the second hash # Does not overwrite the existing hash. def merge(hash) self.dup.update(hash) end # Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second. # This overloaded definition prevents returning a regular hash, if reverse_merge is called on a HashWithDifferentAccess. def reverse_merge(other_hash) super other_hash.with_indifferent_access end # Removes a specified key from the hash. def delete(key) super(convert_key(key)) end def stringify_keys!; self end def symbolize_keys!; self end def to_options!; self end # Convert to a Hash with String keys. def to_hash Hash.new(default).merge(self) end protected def convert_key(key) key.kind_of?(Symbol) ? key.to_s : key end def convert_value(value) case value when Hash value.with_indifferent_access when Array value.collect { |e| e.is_a?(Hash) ? e.with_indifferent_access : e } else value end end end module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Hash #:nodoc: module IndifferentAccess #:nodoc: def with_indifferent_access hash = HashWithIndifferentAccess.new(self) hash.default = self.default hash end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Hash #:nodoc: # Allows for deep merging module DeepMerge # Returns a new hash with +self+ and +other_hash+ merged recursively. def deep_merge(other_hash) self.merge(other_hash) do |key, oldval, newval| oldval = oldval.to_hash if oldval.respond_to?(:to_hash) newval = newval.to_hash if newval.respond_to?(:to_hash) oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ? oldval.deep_merge(newval) : newval end end # Returns a new hash with +self+ and +other_hash+ merged recursively. # Modifies the receiver in place. def deep_merge!(other_hash) replace(deep_merge(other_hash)) end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/hash/except.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/hash/except.rb
require 'set' module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Hash #:nodoc: # Return a hash that includes everything but the given keys. This is useful for # limiting a set of parameters to everything but a few known toggles: # # @person.update_attributes(params[:person].except(:admin)) module Except # Returns a new hash without the given keys. def except(*keys) dup.except!(*keys) end # Replaces the hash without the given keys. def except!(*keys) keys.map! { |key| convert_key(key) } if respond_to?(:convert_key) keys.each { |key| delete(key) } self end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Date #:nodoc: # Converting dates to formatted strings, times, and datetimes. module Conversions DATE_FORMATS = { :short => "%e %b", :long => "%B %e, %Y", :db => "%Y-%m-%d", :number => "%Y%m%d", :long_ordinal => lambda { |date| date.strftime("%B #{date.day.ordinalize}, %Y") }, # => "April 25th, 2007" :rfc822 => "%e %b %Y" } def self.included(base) #:nodoc: base.instance_eval do alias_method :to_default_s, :to_s alias_method :to_s, :to_formatted_s alias_method :default_inspect, :inspect alias_method :inspect, :readable_inspect # Ruby 1.9 has Date#to_time which converts to localtime only. remove_method :to_time if base.instance_methods.include?(:to_time) # Ruby 1.9 has Date#xmlschema which converts to a string without the time component. remove_method :xmlschema if base.instance_methods.include?(:xmlschema) end end # Convert to a formatted string. See DATE_FORMATS for predefined formats. # # This method is aliased to <tt>to_s</tt>. # # ==== Examples # date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007 # # date.to_formatted_s(:db) # => "2007-11-10" # date.to_s(:db) # => "2007-11-10" # # date.to_formatted_s(:short) # => "10 Nov" # date.to_formatted_s(:long) # => "November 10, 2007" # date.to_formatted_s(:long_ordinal) # => "November 10th, 2007" # date.to_formatted_s(:rfc822) # => "10 Nov 2007" # # == Adding your own time formats to to_formatted_s # You can add your own formats to the Date::DATE_FORMATS hash. # Use the format name as the hash key and either a strftime string # or Proc instance that takes a date argument as the value. # # # config/initializers/time_formats.rb # Date::DATE_FORMATS[:month_and_year] = "%B %Y" # Date::DATE_FORMATS[:short_ordinal] = lambda { |date| date.strftime("%B #{date.day.ordinalize}") } def to_formatted_s(format = :default) if formatter = DATE_FORMATS[format] if formatter.respond_to?(:call) formatter.call(self).to_s else strftime(formatter) end else to_default_s end end # Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005" def readable_inspect strftime("%a, %d %b %Y") end # A method to keep Time, Date and DateTime instances interchangeable on conversions. # In this case, it simply returns +self+. def to_date self end if RUBY_VERSION < '1.9' # Converts a Date instance to a Time, where the time is set to the beginning of the day. # The timezone can be either :local or :utc (default :local). # # ==== Examples # date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007 # # date.to_time # => Sat Nov 10 00:00:00 0800 2007 # date.to_time(:local) # => Sat Nov 10 00:00:00 0800 2007 # # date.to_time(:utc) # => Sat Nov 10 00:00:00 UTC 2007 def to_time(form = :local) ::Time.send("#{form}_time", year, month, day) end # Converts a Date instance to a DateTime, where the time is set to the beginning of the day # and UTC offset is set to 0. # # ==== Examples # date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007 # # date.to_datetime # => Sat, 10 Nov 2007 00:00:00 0000 def to_datetime ::DateTime.civil(year, month, day, 0, 0, 0, 0) end if RUBY_VERSION < '1.9' def xmlschema to_time.xmlschema end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/date/calculations.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/date/calculations.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Date #:nodoc: # Enables the use of time calculations within Date itself module Calculations def self.included(base) #:nodoc: base.extend ClassMethods base.instance_eval do alias_method :plus_without_duration, :+ alias_method :+, :plus_with_duration alias_method :minus_without_duration, :- alias_method :-, :minus_with_duration end end module ClassMethods # Returns a new Date representing the date 1 day ago (i.e. yesterday's date). def yesterday ::Date.today.yesterday end # Returns a new Date representing the date 1 day after today (i.e. tomorrow's date). def tomorrow ::Date.today.tomorrow end # Returns Time.zone.today when config.time_zone is set, otherwise just returns Date.today. def current ::Time.zone_default ? ::Time.zone.today : ::Date.today end end # Tells whether the Date object's date lies in the past def past? self < ::Date.current end # Tells whether the Date object's date is today def today? self.to_date == ::Date.current # we need the to_date because of DateTime end # Tells whether the Date object's date lies in the future def future? self > ::Date.current end # Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00) # and then subtracts the specified number of seconds def ago(seconds) to_time.since(-seconds) end # Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00) # and then adds the specified number of seconds def since(seconds) to_time.since(seconds) end alias :in :since # Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00) def beginning_of_day to_time end alias :midnight :beginning_of_day alias :at_midnight :beginning_of_day alias :at_beginning_of_day :beginning_of_day # Converts Date to a Time (or DateTime if necessary) with the time portion set to the end of the day (23:59:59) def end_of_day to_time.end_of_day end def plus_with_duration(other) #:nodoc: if ActiveSupport::Duration === other other.since(self) else plus_without_duration(other) end end def minus_with_duration(other) #:nodoc: if ActiveSupport::Duration === other plus_with_duration(-other) else minus_without_duration(other) end end # Provides precise Date calculations for years, months, and days. The +options+ parameter takes a hash with # any of these keys: <tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>. def advance(options) options = options.dup d = self d = d >> options.delete(:years) * 12 if options[:years] d = d >> options.delete(:months) if options[:months] d = d + options.delete(:weeks) * 7 if options[:weeks] d = d + options.delete(:days) if options[:days] d end # Returns a new Date where one or more of the elements have been changed according to the +options+ parameter. # # Examples: # # Date.new(2007, 5, 12).change(:day => 1) # => Date.new(2007, 5, 1) # Date.new(2007, 5, 12).change(:year => 2005, :month => 1) # => Date.new(2005, 1, 12) def change(options) ::Date.new( options[:year] || self.year, options[:month] || self.month, options[:day] || self.day ) end # Returns a new Date/DateTime representing the time a number of specified months ago def months_ago(months) advance(:months => -months) end # Returns a new Date/DateTime representing the time a number of specified months in the future def months_since(months) advance(:months => months) end # Returns a new Date/DateTime representing the time a number of specified years ago def years_ago(years) advance(:years => -years) end # Returns a new Date/DateTime representing the time a number of specified years in the future def years_since(years) advance(:years => years) end # Short-hand for years_ago(1) def last_year years_ago(1) end # Short-hand for years_since(1) def next_year years_since(1) end # Short-hand for months_ago(1) def last_month months_ago(1) end # Short-hand for months_since(1) def next_month months_since(1) end # Returns a new Date/DateTime representing the "start" of this week (i.e, Monday; DateTime objects will have time set to 0:00) def beginning_of_week days_to_monday = self.wday!=0 ? self.wday-1 : 6 result = self - days_to_monday self.acts_like?(:time) ? result.midnight : result end alias :monday :beginning_of_week alias :at_beginning_of_week :beginning_of_week # Returns a new Date/DateTime representing the end of this week (Sunday, DateTime objects will have time set to 23:59:59) def end_of_week days_to_sunday = self.wday!=0 ? 7-self.wday : 0 result = self + days_to_sunday.days self.acts_like?(:time) ? result.end_of_day : result end alias :at_end_of_week :end_of_week # Returns a new Date/DateTime representing the start of the given day in next week (default is Monday). def next_week(day = :monday) days_into_week = { :monday => 0, :tuesday => 1, :wednesday => 2, :thursday => 3, :friday => 4, :saturday => 5, :sunday => 6} result = (self + 7).beginning_of_week + days_into_week[day] self.acts_like?(:time) ? result.change(:hour => 0) : result end # Returns a new ; DateTime objects will have time set to 0:00DateTime representing the start of the month (1st of the month; DateTime objects will have time set to 0:00) def beginning_of_month self.acts_like?(:time) ? change(:day => 1,:hour => 0, :min => 0, :sec => 0) : change(:day => 1) end alias :at_beginning_of_month :beginning_of_month # Returns a new Date/DateTime representing the end of the month (last day of the month; DateTime objects will have time set to 0:00) def end_of_month last_day = ::Time.days_in_month( self.month, self.year ) self.acts_like?(:time) ? change(:day => last_day, :hour => 23, :min => 59, :sec => 59) : change(:day => last_day) end alias :at_end_of_month :end_of_month # Returns a new Date/DateTime representing the start of the quarter (1st of january, april, july, october; DateTime objects will have time set to 0:00) def beginning_of_quarter beginning_of_month.change(:month => [10, 7, 4, 1].detect { |m| m <= self.month }) end alias :at_beginning_of_quarter :beginning_of_quarter # Returns a new Date/DateTime representing the end of the quarter (last day of march, june, september, december; DateTime objects will have time set to 23:59:59) def end_of_quarter beginning_of_month.change(:month => [3, 6, 9, 12].detect { |m| m >= self.month }).end_of_month end alias :at_end_of_quarter :end_of_quarter # Returns a new Date/DateTime representing the start of the year (1st of january; DateTime objects will have time set to 0:00) def beginning_of_year self.acts_like?(:time) ? change(:month => 1, :day => 1, :hour => 0, :min => 0, :sec => 0) : change(:month => 1, :day => 1) end alias :at_beginning_of_year :beginning_of_year # Returns a new Time representing the end of the year (31st of december; DateTime objects will have time set to 23:59:59) def end_of_year self.acts_like?(:time) ? change(:month => 12,:day => 31,:hour => 23, :min => 59, :sec => 59) : change(:month => 12, :day => 31) end alias :at_end_of_year :end_of_year # Convenience method which returns a new Date/DateTime representing the time 1 day ago def yesterday self - 1 end # Convenience method which returns a new Date/DateTime representing the time 1 day since the instance time def tomorrow self + 1 end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/date/behavior.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/date/behavior.rb
require 'date' module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Date #:nodoc: module Behavior # Enable more predictable duck-typing on Date-like classes. See # Object#acts_like?. def acts_like_date? true end # Date memoizes some instance methods using metaprogramming to wrap # the methods with one that caches the result in an instance variable. # # If a Date is frozen but the memoized method hasn't been called, the # first call will result in a frozen object error since the memo # instance variable is uninitialized. # # Work around by eagerly memoizing before freezing. # # Ruby 1.9 uses a preinitialized instance variable so it's unaffected. # This hack is as close as we can get to feature detection: begin ::Date.today.freeze.jd rescue => frozen_object_error if frozen_object_error.message =~ /frozen/ def freeze #:nodoc: self.class.private_instance_methods(false).each do |m| if m.to_s =~ /\A__\d+__\Z/ instance_variable_set(:"@#{m}", [send(m)]) end end super end end end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/float/time.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/float/time.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Float #:nodoc: module Time # Deprication helper methods not available as core_ext is loaded first. def years ::ActiveSupport::Deprecation.warn(self.class.deprecated_method_warning(:years, "Fractional years are not respected. Convert value to integer before calling #years."), caller) years_without_deprecation end def months ::ActiveSupport::Deprecation.warn(self.class.deprecated_method_warning(:months, "Fractional months are not respected. Convert value to integer before calling #months."), caller) months_without_deprecation end def months_without_deprecation ActiveSupport::Duration.new(self * 30.days, [[:months, self]]) end alias :month :months def years_without_deprecation ActiveSupport::Duration.new(self * 365.25.days, [[:years, self]]) end alias :year :years end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/float/rounding.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/float/rounding.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Float #:nodoc: module Rounding def self.included(base) #:nodoc: base.class_eval do alias_method :round_without_precision, :round alias_method :round, :round_with_precision end end # Rounds the float with the specified precision. # # x = 1.337 # x.round # => 1 # x.round(1) # => 1.3 # x.round(2) # => 1.34 def round_with_precision(precision = nil) precision.nil? ? round_without_precision : (self * (10 ** precision)).round / (10 ** precision).to_f end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/integer/even_odd.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/integer/even_odd.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Integer #:nodoc: # For checking if a fixnum is even or odd. # # 2.even? # => true # 2.odd? # => false # 1.even? # => false # 1.odd? # => true # 0.even? # => true # 0.odd? # => false # -1.even? # => false # -1.odd? # => true module EvenOdd def multiple_of?(number) self % number == 0 end def even? multiple_of? 2 end if RUBY_VERSION < '1.9' def odd? !even? end if RUBY_VERSION < '1.9' end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/integer/time.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/integer/time.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Integer #:nodoc: # Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years. # # These methods use Time#advance for precise date calculations when using from_now, ago, etc. # as well as adding or subtracting their results from a Time object. For example: # # # equivalent to Time.now.advance(:months => 1) # 1.month.from_now # # # equivalent to Time.now.advance(:years => 2) # 2.years.from_now # # # equivalent to Time.now.advance(:months => 4, :years => 5) # (4.months + 5.years).from_now # # While these methods provide precise calculation when used as in the examples above, care # should be taken to note that this is not true if the result of `months', `years', etc is # converted before use: # # # equivalent to 30.days.to_i.from_now # 1.month.to_i.from_now # # # equivalent to 365.25.days.to_f.from_now # 1.year.to_f.from_now # # In such cases, Ruby's core # Date[http://stdlib.rubyonrails.org/libdoc/date/rdoc/index.html] and # Time[http://stdlib.rubyonrails.org/libdoc/time/rdoc/index.html] should be used for precision # date and time arithmetic module Time def months ActiveSupport::Duration.new(self * 30.days, [[:months, self]]) end alias :month :months def years ActiveSupport::Duration.new(self * 365.25.days, [[:years, self]]) end alias :year :years end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/integer/inflections.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/integer/inflections.rb
require 'active_support/inflector' module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Integer #:nodoc: module Inflections # Ordinalize turns a number into an ordinal string used to denote the # position in an ordered sequence such as 1st, 2nd, 3rd, 4th. # # 1.ordinalize # => "1st" # 2.ordinalize # => "2nd" # 1002.ordinalize # => "1002nd" # 1003.ordinalize # => "1003rd" def ordinalize Inflector.ordinalize(self) end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb
module Kernel # Turns the current script into a daemon process that detaches from the console. # It can be shut down with a TERM signal. def daemonize Process.daemon end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/kernel/debugger.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/kernel/debugger.rb
module Kernel unless respond_to?(:debugger) # Starts a debugging session if ruby-debug has been loaded (call script/server --debugger to do load it). def debugger message = "\n***** Debugger requested, but was not available: Start server with --debugger to enable *****\n" defined?(Rails) ? Rails.logger.info(message) : $stderr.puts(message) end end def breakpoint message = "\n***** The 'breakpoint' command has been renamed 'debugger' -- please change *****\n" defined?(Rails) ? Rails.logger.info(message) : $stderr.puts(message) debugger end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb
module Kernel # Sets $VERBOSE to nil for the duration of the block and back to its original value afterwards. # # silence_warnings do # value = noisy_call # no warning voiced # end # # noisy_call # warning voiced def silence_warnings old_verbose, $VERBOSE = $VERBOSE, nil yield ensure $VERBOSE = old_verbose end # Sets $VERBOSE to true for the duration of the block and back to its original value afterwards. def enable_warnings old_verbose, $VERBOSE = $VERBOSE, true yield ensure $VERBOSE = old_verbose end # For compatibility def silence_stderr #:nodoc: silence_stream(STDERR) { yield } end # Silences any stream for the duration of the block. # # silence_stream(STDOUT) do # puts 'This will never be seen' # end # # puts 'But this will' def silence_stream(stream) old_stream = stream.dup stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null') stream.sync = true yield ensure stream.reopen(old_stream) end # Blocks and ignores any exception passed as argument if raised within the block. # # suppress(ZeroDivisionError) do # 1/0 # puts "This code is NOT reached" # end # # puts "This code gets executed and nothing related to ZeroDivisionError was seen" def suppress(*exception_classes) begin yield rescue Exception => e raise unless exception_classes.any? { |cls| e.kind_of?(cls) } end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/kernel/requires.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/kernel/requires.rb
module Kernel # Require a library with fallback to RubyGems. Warnings during library # loading are silenced to increase signal/noise for application warnings. def require_library_or_gem(library_name) silence_warnings do begin require library_name rescue LoadError => cannot_require # 1. Requiring the module is unsuccessful, maybe it's a gem and nobody required rubygems yet. Try. begin require 'rubygems' rescue LoadError => rubygems_not_installed raise cannot_require end # 2. Rubygems is installed and loaded. Try to load the library again begin require library_name rescue LoadError => gem_not_installed raise cannot_require end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/kernel/agnostics.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/kernel/agnostics.rb
class Object # Makes backticks behave (somewhat more) similarly on all platforms. # On win32 `nonexistent_command` raises Errno::ENOENT; on Unix, the # spawned shell prints a message to stderr and sets $?. We emulate # Unix on the former but not the latter. def `(command) #:nodoc: super rescue Errno::ENOENT => e STDERR.puts "#$0: #{e}" end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/range/conversions.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/range/conversions.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Range #:nodoc: # Getting ranges in different convenient string representations and other objects module Conversions RANGE_FORMATS = { :db => Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" } } def self.included(base) #:nodoc: base.class_eval do alias_method :to_default_s, :to_s alias_method :to_s, :to_formatted_s end end # Gives a human readable format of the range. # # ==== Example # # [1..100].to_formatted_s # => "1..100" def to_formatted_s(format = :default) RANGE_FORMATS[format] ? RANGE_FORMATS[format].call(first, last) : to_default_s end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/range/include_range.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/range/include_range.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Range #:nodoc: # Check if a Range includes another Range. module IncludeRange def self.included(base) #:nodoc: base.alias_method_chain :include?, :range end # Extends the default Range#include? to support range comparisons. # (1..5).include?(1..5) # => true # (1..5).include?(2..3) # => true # (1..5).include?(2..6) # => false # # The native Range#include? behavior is untouched. # ("a".."f").include?("c") # => true # (5..9).include?(11) # => false def include_with_range?(value) if value.is_a?(::Range) operator = exclude_end? ? :< : :<= end_value = value.exclude_end? ? last.succ : last include?(value.first) && (value.last <=> end_value).send(operator, 0) else include_without_range?(value) end end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/range/blockless_step.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/range/blockless_step.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Range #:nodoc: # Return an array when step is called without a block. module BlocklessStep def self.included(base) #:nodoc: base.alias_method_chain :step, :blockless end if RUBY_VERSION < '1.9' def step_with_blockless(value = 1, &block) if block_given? step_without_blockless(value, &block) else returning [] do |array| step_without_blockless(value) { |step| array << step } end end end else def step_with_blockless(value = 1, &block) if block_given? step_without_blockless(value, &block) else step_without_blockless(value).to_a end end end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/range/overlaps.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/range/overlaps.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Range #:nodoc: # Check if Ranges overlap. module Overlaps # Compare two ranges and see if they overlap eachother # (1..5).overlaps?(4..6) # => true # (1..5).overlaps?(7..9) # => false def overlaps?(other) include?(other.first) || other.include?(first) end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/time/conversions.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/time/conversions.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Time #:nodoc: # Converting times to formatted strings, dates, and datetimes. module Conversions DATE_FORMATS = { :db => "%Y-%m-%d %H:%M:%S", :number => "%Y%m%d%H%M%S", :time => "%H:%M", :short => "%d %b %H:%M", :long => "%B %d, %Y %H:%M", :long_ordinal => lambda { |time| time.strftime("%B #{time.day.ordinalize}, %Y %H:%M") }, :rfc822 => lambda { |time| time.strftime("%a, %d %b %Y %H:%M:%S #{time.formatted_offset(false)}") } } def self.included(base) #:nodoc: base.class_eval do alias_method :to_default_s, :to_s alias_method :to_s, :to_formatted_s end end # Converts to a formatted string. See DATE_FORMATS for builtin formats. # # This method is aliased to <tt>to_s</tt>. # # time = Time.now # => Thu Jan 18 06:10:17 CST 2007 # # time.to_formatted_s(:time) # => "06:10:17" # time.to_s(:time) # => "06:10:17" # # time.to_formatted_s(:db) # => "2007-01-18 06:10:17" # time.to_formatted_s(:number) # => "20070118061017" # time.to_formatted_s(:short) # => "18 Jan 06:10" # time.to_formatted_s(:long) # => "January 18, 2007 06:10" # time.to_formatted_s(:long_ordinal) # => "January 18th, 2007 06:10" # time.to_formatted_s(:rfc822) # => "Thu, 18 Jan 2007 06:10:17 -0600" # # == Adding your own time formats to +to_formatted_s+ # You can add your own formats to the Time::DATE_FORMATS hash. # Use the format name as the hash key and either a strftime string # or Proc instance that takes a time argument as the value. # # # config/initializers/time_formats.rb # Time::DATE_FORMATS[:month_and_year] = "%B %Y" # Time::DATE_FORMATS[:short_ordinal] = lambda { |time| time.strftime("%B #{time.day.ordinalize}") } def to_formatted_s(format = :default) return to_default_s unless formatter = DATE_FORMATS[format] formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter) end # Returns the UTC offset as an +HH:MM formatted string. # # Time.local(2000).formatted_offset # => "-06:00" # Time.local(2000).formatted_offset(false) # => "-0600" def formatted_offset(colon = true, alternate_utc_string = nil) utc? && alternate_utc_string || utc_offset.to_utc_offset_s(colon) end # Converts a Time object to a Date, dropping hour, minute, and second precision. # # my_time = Time.now # => Mon Nov 12 22:59:51 -0500 2007 # my_time.to_date # => Mon, 12 Nov 2007 # # your_time = Time.parse("1/13/2009 1:13:03 P.M.") # => Tue Jan 13 13:13:03 -0500 2009 # your_time.to_date # => Tue, 13 Jan 2009 def to_date ::Date.new(year, month, day) end # A method to keep Time, Date and DateTime instances interchangeable on conversions. # In this case, it simply returns +self+. def to_time self end # Converts a Time instance to a Ruby DateTime instance, preserving UTC offset. # # my_time = Time.now # => Mon Nov 12 23:04:21 -0500 2007 # my_time.to_datetime # => Mon, 12 Nov 2007 23:04:21 -0500 # # your_time = Time.parse("1/13/2009 1:13:03 P.M.") # => Tue Jan 13 13:13:03 -0500 2009 # your_time.to_datetime # => Tue, 13 Jan 2009 13:13:03 -0500 def to_datetime ::DateTime.civil(year, month, day, hour, min, sec, Rational(utc_offset, 86400)) end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/time/calculations.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/time/calculations.rb
require 'active_support/duration' module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Time #:nodoc: # Enables the use of time calculations within Time itself module Calculations def self.included(base) #:nodoc: base.extend ClassMethods base.class_eval do alias_method :plus_without_duration, :+ alias_method :+, :plus_with_duration alias_method :minus_without_duration, :- alias_method :-, :minus_with_duration alias_method :minus_without_coercion, :- alias_method :-, :minus_with_coercion alias_method :compare_without_coercion, :<=> alias_method :<=>, :compare_with_coercion end end COMMON_YEAR_DAYS_IN_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] module ClassMethods # Overriding case equality method so that it returns true for ActiveSupport::TimeWithZone instances def ===(other) other.is_a?(::Time) end # Return the number of days in the given month. # If no year is specified, it will use the current year. def days_in_month(month, year = now.year) return 29 if month == 2 && ::Date.gregorian_leap?(year) COMMON_YEAR_DAYS_IN_MONTH[month] end # Returns a new Time if requested year can be accommodated by Ruby's Time class # (i.e., if year is within either 1970..2038 or 1902..2038, depending on system architecture); # otherwise returns a DateTime def time_with_datetime_fallback(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0, usec=0) ::Time.send(utc_or_local, year, month, day, hour, min, sec, usec) rescue offset = utc_or_local.to_sym == :local ? ::DateTime.local_offset : 0 ::DateTime.civil(year, month, day, hour, min, sec, offset) end # Wraps class method +time_with_datetime_fallback+ with +utc_or_local+ set to <tt>:utc</tt>. def utc_time(*args) time_with_datetime_fallback(:utc, *args) end # Wraps class method +time_with_datetime_fallback+ with +utc_or_local+ set to <tt>:local</tt>. def local_time(*args) time_with_datetime_fallback(:local, *args) end end # Tells whether the Time object's time lies in the past def past? self < ::Time.current end # Tells whether the Time object's time is today def today? self.to_date == ::Date.current end # Tells whether the Time object's time lies in the future def future? self > ::Time.current end # Seconds since midnight: Time.now.seconds_since_midnight def seconds_since_midnight self.to_i - self.change(:hour => 0).to_i + (self.usec/1.0e+6) end # Returns a new Time where one or more of the elements have been changed according to the +options+ parameter. The time options # (hour, minute, sec, usec) reset cascadingly, so if only the hour is passed, then minute, sec, and usec is set to 0. If the hour and # minute is passed, then sec and usec is set to 0. def change(options) ::Time.send( self.utc? ? :utc_time : :local_time, options[:year] || self.year, options[:month] || self.month, options[:day] || self.day, options[:hour] || self.hour, options[:min] || (options[:hour] ? 0 : self.min), options[:sec] || ((options[:hour] || options[:min]) ? 0 : self.sec), options[:usec] || ((options[:hour] || options[:min] || options[:sec]) ? 0 : self.usec) ) end # Uses Date to provide precise Time calculations for years, months, and days. # The +options+ parameter takes a hash with any of these keys: <tt>:years</tt>, # <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>, <tt>:hours</tt>, # <tt>:minutes</tt>, <tt>:seconds</tt>. def advance(options) unless options[:weeks].nil? options[:weeks], partial_weeks = options[:weeks].divmod(1) options[:days] = (options[:days] || 0) + 7 * partial_weeks end unless options[:days].nil? options[:days], partial_days = options[:days].divmod(1) options[:hours] = (options[:hours] || 0) + 24 * partial_days end d = to_date.advance(options) time_advanced_by_date = change(:year => d.year, :month => d.month, :day => d.day) seconds_to_advance = (options[:seconds] || 0) + (options[:minutes] || 0) * 60 + (options[:hours] || 0) * 3600 seconds_to_advance == 0 ? time_advanced_by_date : time_advanced_by_date.since(seconds_to_advance) end # Returns a new Time representing the time a number of seconds ago, this is basically a wrapper around the Numeric extension def ago(seconds) self.since(-seconds) end # Returns a new Time representing the time a number of seconds since the instance time, this is basically a wrapper around # the Numeric extension. def since(seconds) f = seconds.since(self) if ActiveSupport::Duration === seconds f else initial_dst = self.dst? ? 1 : 0 final_dst = f.dst? ? 1 : 0 (seconds.abs >= 86400 && initial_dst != final_dst) ? f + (initial_dst - final_dst).hours : f end rescue self.to_datetime.since(seconds) end alias :in :since # Returns a new Time representing the time a number of specified months ago def months_ago(months) advance(:months => -months) end # Returns a new Time representing the time a number of specified months in the future def months_since(months) advance(:months => months) end # Returns a new Time representing the time a number of specified years ago def years_ago(years) advance(:years => -years) end # Returns a new Time representing the time a number of specified years in the future def years_since(years) advance(:years => years) end # Short-hand for years_ago(1) def last_year years_ago(1) end # Short-hand for years_since(1) def next_year years_since(1) end # Short-hand for months_ago(1) def last_month months_ago(1) end # Short-hand for months_since(1) def next_month months_since(1) end # Returns a new Time representing the "start" of this week (Monday, 0:00) def beginning_of_week days_to_monday = self.wday!=0 ? self.wday-1 : 6 (self - days_to_monday.days).midnight end alias :monday :beginning_of_week alias :at_beginning_of_week :beginning_of_week # Returns a new Time representing the end of this week (Sunday, 23:59:59) def end_of_week days_to_sunday = self.wday!=0 ? 7-self.wday : 0 (self + days_to_sunday.days).end_of_day end alias :at_end_of_week :end_of_week # Returns a new Time representing the start of the given day in next week (default is Monday). def next_week(day = :monday) days_into_week = { :monday => 0, :tuesday => 1, :wednesday => 2, :thursday => 3, :friday => 4, :saturday => 5, :sunday => 6} since(1.week).beginning_of_week.since(days_into_week[day].day).change(:hour => 0) end # Returns a new Time representing the start of the day (0:00) def beginning_of_day (self - self.seconds_since_midnight).change(:usec => 0) end alias :midnight :beginning_of_day alias :at_midnight :beginning_of_day alias :at_beginning_of_day :beginning_of_day # Returns a new Time representing the end of the day, 23:59:59.999999 (.999999999 in ruby1.9) def end_of_day change(:hour => 23, :min => 59, :sec => 59, :usec => 999999.999) end # Returns a new Time representing the start of the month (1st of the month, 0:00) def beginning_of_month #self - ((self.mday-1).days + self.seconds_since_midnight) change(:day => 1,:hour => 0, :min => 0, :sec => 0, :usec => 0) end alias :at_beginning_of_month :beginning_of_month # Returns a new Time representing the end of the month (end of the last day of the month) def end_of_month #self - ((self.mday-1).days + self.seconds_since_midnight) last_day = ::Time.days_in_month( self.month, self.year ) change(:day => last_day, :hour => 23, :min => 59, :sec => 59, :usec => 999999.999) end alias :at_end_of_month :end_of_month # Returns a new Time representing the start of the quarter (1st of january, april, july, october, 0:00) def beginning_of_quarter beginning_of_month.change(:month => [10, 7, 4, 1].detect { |m| m <= self.month }) end alias :at_beginning_of_quarter :beginning_of_quarter # Returns a new Time representing the end of the quarter (end of the last day of march, june, september, december) def end_of_quarter beginning_of_month.change(:month => [3, 6, 9, 12].detect { |m| m >= self.month }).end_of_month end alias :at_end_of_quarter :end_of_quarter # Returns a new Time representing the start of the year (1st of january, 0:00) def beginning_of_year change(:month => 1,:day => 1,:hour => 0, :min => 0, :sec => 0, :usec => 0) end alias :at_beginning_of_year :beginning_of_year # Returns a new Time representing the end of the year (end of the 31st of december) def end_of_year change(:month => 12, :day => 31, :hour => 23, :min => 59, :sec => 59, :usec => 999999.999) end alias :at_end_of_year :end_of_year # Convenience method which returns a new Time representing the time 1 day ago def yesterday advance(:days => -1) end # Convenience method which returns a new Time representing the time 1 day since the instance time def tomorrow advance(:days => 1) end def plus_with_duration(other) #:nodoc: if ActiveSupport::Duration === other other.since(self) else plus_without_duration(other) end end def minus_with_duration(other) #:nodoc: if ActiveSupport::Duration === other other.until(self) else minus_without_duration(other) end end # Time#- can also be used to determine the number of seconds between two Time instances. # We're layering on additional behavior so that ActiveSupport::TimeWithZone instances # are coerced into values that Time#- will recognize def minus_with_coercion(other) other = other.comparable_time if other.respond_to?(:comparable_time) minus_without_coercion(other) end # Layers additional behavior on Time#<=> so that DateTime and ActiveSupport::TimeWithZone instances # can be chronologically compared with a Time def compare_with_coercion(other) # if other is an ActiveSupport::TimeWithZone, coerce a Time instance from it so we can do <=> comparison other = other.comparable_time if other.respond_to?(:comparable_time) if other.acts_like?(:date) # other is a Date/DateTime, so coerce self #to_datetime and hand off to DateTime#<=> to_datetime.compare_without_coercion(other) else compare_without_coercion(other) end end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/time/behavior.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/time/behavior.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Time #:nodoc: module Behavior # Enable more predictable duck-typing on Time-like classes. See # Object#acts_like?. def acts_like_time? true end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/time/zones.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/time/zones.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Time #:nodoc: module Zones def self.included(base) #:nodoc: base.extend(ClassMethods) if base == ::Time # i.e., don't include class methods in DateTime end module ClassMethods attr_accessor :zone_default # Returns the TimeZone for the current request, if this has been set (via Time.zone=). # If <tt>Time.zone</tt> has not been set for the current request, returns the TimeZone specified in <tt>config.time_zone</tt>. def zone Thread.current[:time_zone] || zone_default end # Sets <tt>Time.zone</tt> to a TimeZone object for the current request/thread. # # This method accepts any of the following: # # * A Rails TimeZone object. # * An identifier for a Rails TimeZone object (e.g., "Eastern Time (US & Canada)", <tt>-5.hours</tt>). # * A TZInfo::Timezone object. # * An identifier for a TZInfo::Timezone object (e.g., "America/New_York"). # # Here's an example of how you might set <tt>Time.zone</tt> on a per request basis -- <tt>current_user.time_zone</tt> # just needs to return a string identifying the user's preferred TimeZone: # # class ApplicationController < ActionController::Base # before_filter :set_time_zone # # def set_time_zone # Time.zone = current_user.time_zone # end # end def zone=(time_zone) Thread.current[:time_zone] = get_zone(time_zone) end # Allows override of <tt>Time.zone</tt> locally inside supplied block; resets <tt>Time.zone</tt> to existing value when done. def use_zone(time_zone) old_zone, ::Time.zone = ::Time.zone, get_zone(time_zone) yield ensure ::Time.zone = old_zone end # Returns <tt>Time.zone.now</tt> when <tt>config.time_zone</tt> is set, otherwise just returns <tt>Time.now</tt>. def current ::Time.zone_default ? ::Time.zone.now : ::Time.now end private def get_zone(time_zone) return time_zone if time_zone.nil? || time_zone.is_a?(TimeZone) # lookup timezone based on identifier (unless we've been passed a TZInfo::Timezone) unless time_zone.respond_to?(:period_for_local) time_zone = TimeZone[time_zone] || TZInfo::Timezone.get(time_zone) rescue nil end # Return if a TimeZone instance, or wrap in a TimeZone instance if a TZInfo::Timezone if time_zone time_zone.is_a?(TimeZone) ? time_zone : TimeZone.create(time_zone.name, nil, time_zone) end end end # Returns the simultaneous time in <tt>Time.zone</tt>. # # Time.zone = 'Hawaii' # => 'Hawaii' # Time.utc(2000).in_time_zone # => Fri, 31 Dec 1999 14:00:00 HST -10:00 # # This method is similar to Time#localtime, except that it uses <tt>Time.zone</tt> as the local zone # instead of the operating system's time zone. # # You can also pass in a TimeZone instance or string that identifies a TimeZone as an argument, # and the conversion will be based on that zone instead of <tt>Time.zone</tt>. # # Time.utc(2000).in_time_zone('Alaska') # => Fri, 31 Dec 1999 15:00:00 AKST -09:00 def in_time_zone(zone = ::Time.zone) ActiveSupport::TimeWithZone.new(utc? ? self : getutc, ::Time.__send__(:get_zone, zone)) end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/object/instance_variables.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/object/instance_variables.rb
class Object # Available in 1.8.6 and later. unless respond_to?(:instance_variable_defined?) def instance_variable_defined?(variable) instance_variables.include?(variable.to_s) end end # Returns a hash that maps instance variable names without "@" to their # corresponding values. Keys are strings both in Ruby 1.8 and 1.9. # # class C # def initialize(x, y) # @x, @y = x, y # end # end # # C.new(0, 1).instance_values # => {"x" => 0, "y" => 1} def instance_values #:nodoc: instance_variables.inject({}) do |values, name| values[name.to_s[1..-1]] = instance_variable_get(name) values end end # Returns an array of instance variable names including "@". They are strings # both in Ruby 1.8 and 1.9. # # class C # def initialize(x, y) # @x, @y = x, y # end # end # # C.new(0, 1).instance_variable_names # => ["@y", "@x"] if RUBY_VERSION >= '1.9' def instance_variable_names instance_variables.map { |var| var.to_s } end else alias_method :instance_variable_names, :instance_variables end # Copies the instance variables of +object+ into +self+. # # Instance variable names in the +exclude+ array are ignored. If +object+ # responds to <tt>protected_instance_variables</tt> the ones returned are # also ignored. For example, Rails controllers implement that method. # # In both cases strings and symbols are understood, and they have to include # the at sign. # # class C # def initialize(x, y, z) # @x, @y, @z = x, y, z # end # # def protected_instance_variables # %w(@z) # end # end # # a = C.new(0, 1, 2) # b = C.new(3, 4, 5) # # a.copy_instance_variables_from(b, [:@y]) # # a is now: @x = 3, @y = 1, @z = 2 def copy_instance_variables_from(object, exclude = []) #:nodoc: exclude += object.protected_instance_variables if object.respond_to? :protected_instance_variables vars = object.instance_variables.map(&:to_s) - exclude.map(&:to_s) vars.each { |name| instance_variable_set(name, object.instance_variable_get(name)) } end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/object/extending.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/object/extending.rb
class Object def remove_subclasses_of(*superclasses) #:nodoc: Class.remove_class(*subclasses_of(*superclasses)) end begin ObjectSpace.each_object(Class.new) {} # Exclude this class unless it's a subclass of our supers and is defined. # We check defined? in case we find a removed class that has yet to be # garbage collected. This also fails for anonymous classes -- please # submit a patch if you have a workaround. def subclasses_of(*superclasses) #:nodoc: subclasses = [] superclasses.each do |sup| ObjectSpace.each_object(class << sup; self; end) do |k| if k != sup && (k.name.blank? || eval("defined?(::#{k}) && ::#{k}.object_id == k.object_id")) subclasses << k end end end subclasses end rescue RuntimeError # JRuby and any implementations which cannot handle the objectspace traversal # above fall back to this implementation def subclasses_of(*superclasses) #:nodoc: subclasses = [] superclasses.each do |sup| ObjectSpace.each_object(Class) do |k| if superclasses.any? { |superclass| k < superclass } && (k.name.blank? || eval("defined?(::#{k}) && ::#{k}.object_id == k.object_id")) subclasses << k end end subclasses.uniq! end subclasses end end def extended_by #:nodoc: ancestors = class << self; ancestors end ancestors.select { |mod| mod.class == Module } - [ Object, Kernel ] end def extend_with_included_modules_from(object) #:nodoc: object.extended_by.each { |mod| extend mod } end unless defined? instance_exec # 1.9 module InstanceExecMethods #:nodoc: end include InstanceExecMethods # Evaluate the block with the given arguments within the context of # this object, so self is set to the method receiver. # # From Mauricio's http://eigenclass.org/hiki/bounded+space+instance_exec def instance_exec(*args, &block) begin old_critical, Thread.critical = Thread.critical, true n = 0 n += 1 while respond_to?(method_name = "__instance_exec#{n}") InstanceExecMethods.module_eval { define_method(method_name, &block) } ensure Thread.critical = old_critical end begin send(method_name, *args) ensure InstanceExecMethods.module_eval { remove_method(method_name) } rescue nil end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/object/conversions.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/object/conversions.rb
class Object # Alias of <tt>to_s</tt>. def to_param to_s end # Converts an object into a string suitable for use as a URL query string, using the given <tt>key</tt> as the # param name. # # Note: This method is defined as a default implementation for all Objects for Hash#to_query to work. def to_query(key) require 'cgi' unless defined?(CGI) && defined?(CGI::escape) "#{CGI.escape(key.to_s)}=#{CGI.escape(to_param.to_s)}" end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/object/misc.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/object/misc.rb
class Object # Returns +value+ after yielding +value+ to the block. This simplifies the # process of constructing an object, performing work on the object, and then # returning the object from a method. It is a Ruby-ized realization of the K # combinator, courtesy of Mikael Brockman. # # ==== Examples # # # Without returning # def foo # values = [] # values << "bar" # values << "baz" # return values # end # # foo # => ['bar', 'baz'] # # # returning with a local variable # def foo # returning values = [] do # values << 'bar' # values << 'baz' # end # end # # foo # => ['bar', 'baz'] # # # returning with a block argument # def foo # returning [] do |values| # values << 'bar' # values << 'baz' # end # end # # foo # => ['bar', 'baz'] def returning(value) yield(value) value end # Yields <code>x</code> to the block, and then returns <code>x</code>. # The primary purpose of this method is to "tap into" a method chain, # in order to perform operations on intermediate results within the chain. # # (1..10).tap { |x| puts "original: #{x.inspect}" }.to_a. # tap { |x| puts "array: #{x.inspect}" }. # select { |x| x%2 == 0 }. # tap { |x| puts "evens: #{x.inspect}" }. # map { |x| x*x }. # tap { |x| puts "squares: #{x.inspect}" } def tap yield self self end unless Object.respond_to?(:tap) # An elegant way to factor duplication out of options passed to a series of # method calls. Each method called in the block, with the block variable as # the receiver, will have its options merged with the default +options+ hash # provided. Each method called on the block variable must take an options # hash as its final argument. # # with_options :order => 'created_at', :class_name => 'Comment' do |post| # post.has_many :comments, :conditions => ['approved = ?', true], :dependent => :delete_all # post.has_many :unapproved_comments, :conditions => ['approved = ?', false] # post.has_many :all_comments # end # # Can also be used with an explicit receiver: # # map.with_options :controller => "people" do |people| # people.connect "/people", :action => "index" # people.connect "/people/:id", :action => "show" # end # def with_options(options) yield ActiveSupport::OptionMerger.new(self, options) end # A duck-type assistant method. For example, Active Support extends Date # to define an acts_like_date? method, and extends Time to define # acts_like_time?. As a result, we can do "x.acts_like?(:time)" and # "x.acts_like?(:date)" to do duck-type-safe comparisons, since classes that # we want to act like Time simply need to define an acts_like_time? method. def acts_like?(duck) respond_to? "acts_like_#{duck}?" end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/object/metaclass.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/object/metaclass.rb
class Object # Get object's meta (ghost, eigenclass, singleton) class def metaclass class << self self end end # If class_eval is called on an object, add those methods to its metaclass def class_eval(*args, &block) metaclass.class_eval(*args, &block) end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/bigdecimal/conversions.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/bigdecimal/conversions.rb
require 'yaml' module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module BigDecimal #:nodoc: module Conversions DEFAULT_STRING_FORMAT = 'F'.freeze YAML_TAG = 'tag:yaml.org,2002:float'.freeze YAML_MAPPING = { 'Infinity' => '.Inf', '-Infinity' => '-.Inf', 'NaN' => '.NaN' } def self.included(base) #:nodoc: base.class_eval do alias_method :_original_to_s, :to_s alias_method :to_s, :to_formatted_s yaml_as YAML_TAG end end def to_formatted_s(format = DEFAULT_STRING_FORMAT) _original_to_s(format) end # This emits the number without any scientific notation. # This is better than self.to_f.to_s since it doesn't lose precision. # # Note that reconstituting YAML floats to native floats may lose precision. def to_yaml(opts = {}) YAML.quick_emit(nil, opts) do |out| string = to_s out.scalar(YAML_TAG, YAML_MAPPING[string] || string, :plain) end end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/base64/encoding.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/base64/encoding.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Base64 #:nodoc: module Encoding # Encodes the value as base64 without the newline breaks. This makes the base64 encoding readily usable as URL parameters # or memcache keys without further processing. # # ActiveSupport::Base64.encode64s("Original unencoded string") # # => "T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==" def encode64s(value) encode64(value).gsub(/\n/, '') end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/array/conversions.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/array/conversions.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Array #:nodoc: module Conversions # Converts the array to a comma-separated sentence where the last element is joined by the connector word. Options: # * <tt>:words_connector</tt> - The sign or word used to join the elements in arrays with two or more elements (default: ", ") # * <tt>:two_words_connector</tt> - The sign or word used to join the elements in arrays with two elements (default: " and ") # * <tt>:last_word_connector</tt> - The sign or word used to join the last element in arrays with three or more elements (default: ", and ") def to_sentence(options = {}) default_words_connector = I18n.translate(:'support.array.words_connector', :locale => options[:locale]) default_two_words_connector = I18n.translate(:'support.array.two_words_connector', :locale => options[:locale]) default_last_word_connector = I18n.translate(:'support.array.last_word_connector', :locale => options[:locale]) # Try to emulate to_senteces previous to 2.3 if options.has_key?(:connector) || options.has_key?(:skip_last_comma) ::ActiveSupport::Deprecation.warn(":connector has been deprecated. Use :words_connector instead", caller) if options.has_key? :connector ::ActiveSupport::Deprecation.warn(":skip_last_comma has been deprecated. Use :last_word_connector instead", caller) if options.has_key? :skip_last_comma skip_last_comma = options.delete :skip_last_comma if connector = options.delete(:connector) options[:last_word_connector] ||= skip_last_comma ? connector : ", #{connector}" else options[:last_word_connector] ||= skip_last_comma ? default_two_words_connector : default_last_word_connector end end options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale) options.reverse_merge! :words_connector => default_words_connector, :two_words_connector => default_two_words_connector, :last_word_connector => default_last_word_connector case length when 0 "" when 1 self[0].to_s when 2 "#{self[0]}#{options[:two_words_connector]}#{self[1]}" else "#{self[0...-1].join(options[:words_connector])}#{options[:last_word_connector]}#{self[-1]}" end end # Calls <tt>to_param</tt> on all its elements and joins the result with # slashes. This is used by <tt>url_for</tt> in Action Pack. def to_param collect { |e| e.to_param }.join '/' end # Converts an array into a string suitable for use as a URL query string, # using the given +key+ as the param name. # # ['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding" def to_query(key) prefix = "#{key}[]" collect { |value| value.to_query(prefix) }.join '&' end def self.included(base) #:nodoc: base.class_eval do alias_method :to_default_s, :to_s alias_method :to_s, :to_formatted_s end end # Converts a collection of elements into a formatted string by calling # <tt>to_s</tt> on all elements and joining them: # # Blog.find(:all).to_formatted_s # => "First PostSecond PostThird Post" # # Adding in the <tt>:db</tt> argument as the format yields a prettier # output: # # Blog.find(:all).to_formatted_s(:db) # => "First Post,Second Post,Third Post" def to_formatted_s(format = :default) case format when :db if respond_to?(:empty?) && self.empty? "null" else collect { |element| element.id }.join(",") end else to_default_s end end # Returns a string that represents this array in XML by sending +to_xml+ # to each element. Active Record collections delegate their representation # in XML to this method. # # All elements are expected to respond to +to_xml+, if any of them does # not an exception is raised. # # The root node reflects the class name of the first element in plural # if all elements belong to the same type and that's not Hash: # # customer.projects.to_xml # # <?xml version="1.0" encoding="UTF-8"?> # <projects type="array"> # <project> # <amount type="decimal">20000.0</amount> # <customer-id type="integer">1567</customer-id> # <deal-date type="date">2008-04-09</deal-date> # ... # </project> # <project> # <amount type="decimal">57230.0</amount> # <customer-id type="integer">1567</customer-id> # <deal-date type="date">2008-04-15</deal-date> # ... # </project> # </projects> # # Otherwise the root element is "records": # # [{:foo => 1, :bar => 2}, {:baz => 3}].to_xml # # <?xml version="1.0" encoding="UTF-8"?> # <records type="array"> # <record> # <bar type="integer">2</bar> # <foo type="integer">1</foo> # </record> # <record> # <baz type="integer">3</baz> # </record> # </records> # # If the collection is empty the root element is "nil-classes" by default: # # [].to_xml # # <?xml version="1.0" encoding="UTF-8"?> # <nil-classes type="array"/> # # To ensure a meaningful root element use the <tt>:root</tt> option: # # customer_with_no_projects.projects.to_xml(:root => "projects") # # <?xml version="1.0" encoding="UTF-8"?> # <projects type="array"/> # # By default root children have as node name the one of the root # singularized. You can change it with the <tt>:children</tt> option. # # The +options+ hash is passed downwards: # # Message.all.to_xml(:skip_types => true) # # <?xml version="1.0" encoding="UTF-8"?> # <messages> # <message> # <created-at>2008-03-07T09:58:18+01:00</created-at> # <id>1</id> # <name>1</name> # <updated-at>2008-03-07T09:58:18+01:00</updated-at> # <user-id>1</user-id> # </message> # </messages> # def to_xml(options = {}) raise "Not all elements respond to to_xml" unless all? { |e| e.respond_to? :to_xml } require 'builder' unless defined?(Builder) options = options.dup options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize : "records" options[:children] ||= options[:root].singularize options[:indent] ||= 2 options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent]) root = options.delete(:root).to_s children = options.delete(:children) if !options.has_key?(:dasherize) || options[:dasherize] root = root.dasherize end options[:builder].instruct! unless options.delete(:skip_instruct) opts = options.merge({ :root => children }) xml = options[:builder] if empty? xml.tag!(root, options[:skip_types] ? {} : {:type => "array"}) else xml.tag!(root, options[:skip_types] ? {} : {:type => "array"}) { yield xml if block_given? each { |e| e.to_xml(opts.merge({ :skip_instruct => true })) } } end end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/array/extract_options.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/array/extract_options.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Array #:nodoc: module ExtractOptions # Extracts options from a set of arguments. Removes and returns the last # element in the array if it's a hash, otherwise returns a blank hash. # # def options(*args) # args.extract_options! # end # # options(1, 2) # => {} # options(1, 2, :a => :b) # => {:a=>:b} def extract_options! last.is_a?(::Hash) ? pop : {} end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/array/random_access.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/array/random_access.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Array #:nodoc: module RandomAccess # Returns a random element from the array. def rand self[Kernel.rand(length)] end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/array/grouping.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/array/grouping.rb
require 'enumerator' module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Array #:nodoc: module Grouping # Splits or iterates over the array in groups of size +number+, # padding any remaining slots with +fill_with+ unless it is +false+. # # %w(1 2 3 4 5 6 7).in_groups_of(3) {|group| p group} # ["1", "2", "3"] # ["4", "5", "6"] # ["7", nil, nil] # # %w(1 2 3).in_groups_of(2, '&nbsp;') {|group| p group} # ["1", "2"] # ["3", "&nbsp;"] # # %w(1 2 3).in_groups_of(2, false) {|group| p group} # ["1", "2"] # ["3"] def in_groups_of(number, fill_with = nil) if fill_with == false collection = self else # size % number gives how many extra we have; # subtracting from number gives how many to add; # modulo number ensures we don't add group of just fill. padding = (number - size % number) % number collection = dup.concat([fill_with] * padding) end if block_given? collection.each_slice(number) { |slice| yield(slice) } else returning [] do |groups| collection.each_slice(number) { |group| groups << group } end end end # Splits or iterates over the array in +number+ of groups, padding any # remaining slots with +fill_with+ unless it is +false+. # # %w(1 2 3 4 5 6 7 8 9 10).in_groups(3) {|group| p group} # ["1", "2", "3", "4"] # ["5", "6", "7", nil] # ["8", "9", "10", nil] # # %w(1 2 3 4 5 6 7).in_groups(3, '&nbsp;') {|group| p group} # ["1", "2", "3"] # ["4", "5", "&nbsp;"] # ["6", "7", "&nbsp;"] # # %w(1 2 3 4 5 6 7).in_groups(3, false) {|group| p group} # ["1", "2", "3"] # ["4", "5"] # ["6", "7"] def in_groups(number, fill_with = nil) # size / number gives minor group size; # size % number gives how many objects need extra accomodation; # each group hold either division or division + 1 items. division = size / number modulo = size % number # create a new array avoiding dup groups = [] start = 0 number.times do |index| length = division + (modulo > 0 && modulo > index ? 1 : 0) padding = fill_with != false && modulo > 0 && length == division ? 1 : 0 groups << slice(start, length).concat([fill_with] * padding) start += length end if block_given? groups.each{|g| yield(g) } else groups end end # Divides the array into one or more subarrays based on a delimiting +value+ # or the result of an optional block. # # [1, 2, 3, 4, 5].split(3) # => [[1, 2], [4, 5]] # (1..10).to_a.split { |i| i % 3 == 0 } # => [[1, 2], [4, 5], [7, 8], [10]] def split(value = nil) using_block = block_given? inject([[]]) do |results, element| if (using_block && yield(element)) || (value == element) results << [] else results.last << element end results end end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/array/access.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/array/access.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Array #:nodoc: # Makes it easier to access parts of an array. module Access # Returns the tail of the array from +position+. # # %w( a b c d ).from(0) # => %w( a b c d ) # %w( a b c d ).from(2) # => %w( c d ) # %w( a b c d ).from(10) # => nil # %w().from(0) # => nil def from(position) self[position..-1] end # Returns the beginning of the array up to +position+. # # %w( a b c d ).to(0) # => %w( a ) # %w( a b c d ).to(2) # => %w( a b c ) # %w( a b c d ).to(10) # => %w( a b c d ) # %w().to(0) # => %w() def to(position) self[0..position] end # Equal to <tt>self[1]</tt>. def second self[1] end # Equal to <tt>self[2]</tt>. def third self[2] end # Equal to <tt>self[3]</tt>. def fourth self[3] end # Equal to <tt>self[4]</tt>. def fifth self[4] end # Equal to <tt>self[41]</tt>. Also known as accessing "the reddit". def forty_two self[41] end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/array/wrapper.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/array/wrapper.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Array #:nodoc: module Wrapper # Wraps the object in an Array unless it's an Array. Converts the # object to an Array using #to_ary if it implements that. def wrap(object) case object when nil [] when self object else if object.respond_to?(:to_ary) object.to_ary else [object] end end end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/class/removal.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/class/removal.rb
class Class #:nodoc: # Unassociates the class with its subclasses and removes the subclasses # themselves. # # Integer.remove_subclasses # => [Bignum, Fixnum] # Fixnum # => NameError: uninitialized constant Fixnum def remove_subclasses Object.remove_subclasses_of(self) end # Returns an array with the names of the subclasses of +self+ as strings. # # Integer.subclasses # => ["Bignum", "Fixnum"] def subclasses Object.subclasses_of(self).map { |o| o.to_s } end # Removes the classes in +klasses+ from their parent module. # # Ordinary classes belong to some module via a constant. This method computes # that constant name from the class name and removes it from the module it # belongs to. # # Object.remove_class(Integer) # => [Integer] # Integer # => NameError: uninitialized constant Integer # # Take into account that in general the class object could be still stored # somewhere else. # # i = Integer # => Integer # Object.remove_class(Integer) # => [Integer] # Integer # => NameError: uninitialized constant Integer # i.subclasses # => ["Bignum", "Fixnum"] # Fixnum.superclass # => Integer def remove_class(*klasses) klasses.flatten.each do |klass| # Skip this class if there is nothing bound to this name next unless defined?(klass.name) basename = klass.to_s.split("::").last parent = klass.parent # Skip this class if it does not match the current one bound to this name next unless parent.const_defined?(basename) && klass = parent.const_get(basename) parent.instance_eval { remove_const basename } unless parent == klass end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
# These class attributes behave something like the class # inheritable accessors. But instead of copying the hash over at # the time the subclass is first defined, the accessors simply # delegate to their superclass unless they have been given a # specific value. This stops the strange situation where values # set after class definition don't get applied to subclasses. class Class def superclass_delegating_reader(*names) class_name_to_stop_searching_on = self.superclass.name.blank? ? "Object" : self.superclass.name names.each do |name| class_eval <<-EOS def self.#{name} # def self.only_reader if defined?(@#{name}) # if defined?(@only_reader) @#{name} # @only_reader elsif superclass < #{class_name_to_stop_searching_on} && # elsif superclass < Object && superclass.respond_to?(:#{name}) # superclass.respond_to?(:only_reader) superclass.#{name} # superclass.only_reader end # end end # end def #{name} # def only_reader self.class.#{name} # self.class.only_reader end # end def self.#{name}? # def self.only_reader? !!#{name} # !!only_reader end # end def #{name}? # def only_reader? !!#{name} # !!only_reader end # end EOS end end def superclass_delegating_writer(*names) names.each do |name| class_eval <<-EOS def self.#{name}=(value) # def self.only_writer=(value) @#{name} = value # @only_writer = value end # end EOS end end def superclass_delegating_accessor(*names) superclass_delegating_reader(*names) superclass_delegating_writer(*names) end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
# Extends the class object with class and instance accessors for class attributes, # just like the native attr* accessors for instance attributes. # # class Person # cattr_accessor :hair_colors # end # # Person.hair_colors = [:brown, :black, :blonde, :red] class Class def cattr_reader(*syms) syms.flatten.each do |sym| next if sym.is_a?(Hash) class_eval(<<-EOS, __FILE__, __LINE__) unless defined? @@#{sym} # unless defined? @@hair_colors @@#{sym} = nil # @@hair_colors = nil end # end # def self.#{sym} # def self.hair_colors @@#{sym} # @@hair_colors end # end # def #{sym} # def hair_colors @@#{sym} # @@hair_colors end # end EOS end end def cattr_writer(*syms) options = syms.extract_options! syms.flatten.each do |sym| class_eval(<<-EOS, __FILE__, __LINE__) unless defined? @@#{sym} # unless defined? @@hair_colors @@#{sym} = nil # @@hair_colors = nil end # end # def self.#{sym}=(obj) # def self.hair_colors=(obj) @@#{sym} = obj # @@hair_colors = obj end # end # #{" # def #{sym}=(obj) # def hair_colors=(obj) @@#{sym} = obj # @@hair_colors = obj end # end " unless options[:instance_writer] == false } # # instance writer above is generated unless options[:instance_writer] == false EOS end end def cattr_accessor(*syms) cattr_reader(*syms) cattr_writer(*syms) end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
# Retain for backward compatibility. Methods are now included in Class. module ClassInheritableAttributes # :nodoc: end # Allows attributes to be shared within an inheritance hierarchy, but where each descendant gets a copy of # their parents' attributes, instead of just a pointer to the same. This means that the child can add elements # to, for example, an array without those additions being shared with either their parent, siblings, or # children, which is unlike the regular class-level attributes that are shared across the entire hierarchy. class Class # :nodoc: def class_inheritable_reader(*syms) syms.each do |sym| next if sym.is_a?(Hash) class_eval <<-EOS def self.#{sym} # def self.before_add_for_comments read_inheritable_attribute(:#{sym}) # read_inheritable_attribute(:before_add_for_comments) end # end # def #{sym} # def before_add_for_comments self.class.#{sym} # self.class.before_add_for_comments end # end EOS end end def class_inheritable_writer(*syms) options = syms.extract_options! syms.each do |sym| class_eval <<-EOS def self.#{sym}=(obj) # def self.color=(obj) write_inheritable_attribute(:#{sym}, obj) # write_inheritable_attribute(:color, obj) end # end # #{" # def #{sym}=(obj) # def color=(obj) self.class.#{sym} = obj # self.class.color = obj end # end " unless options[:instance_writer] == false } # # the writer above is generated unless options[:instance_writer] == false EOS end end def class_inheritable_array_writer(*syms) options = syms.extract_options! syms.each do |sym| class_eval <<-EOS def self.#{sym}=(obj) # def self.levels=(obj) write_inheritable_array(:#{sym}, obj) # write_inheritable_array(:levels, obj) end # end # #{" # def #{sym}=(obj) # def levels=(obj) self.class.#{sym} = obj # self.class.levels = obj end # end " unless options[:instance_writer] == false } # # the writer above is generated unless options[:instance_writer] == false EOS end end def class_inheritable_hash_writer(*syms) options = syms.extract_options! syms.each do |sym| class_eval <<-EOS def self.#{sym}=(obj) # def self.nicknames=(obj) write_inheritable_hash(:#{sym}, obj) # write_inheritable_hash(:nicknames, obj) end # end # #{" # def #{sym}=(obj) # def nicknames=(obj) self.class.#{sym} = obj # self.class.nicknames = obj end # end " unless options[:instance_writer] == false } # # the writer above is generated unless options[:instance_writer] == false EOS end end def class_inheritable_accessor(*syms) class_inheritable_reader(*syms) class_inheritable_writer(*syms) end def class_inheritable_array(*syms) class_inheritable_reader(*syms) class_inheritable_array_writer(*syms) end def class_inheritable_hash(*syms) class_inheritable_reader(*syms) class_inheritable_hash_writer(*syms) end def inheritable_attributes @inheritable_attributes ||= EMPTY_INHERITABLE_ATTRIBUTES end def write_inheritable_attribute(key, value) if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES) @inheritable_attributes = {} end inheritable_attributes[key] = value end def write_inheritable_array(key, elements) write_inheritable_attribute(key, []) if read_inheritable_attribute(key).nil? write_inheritable_attribute(key, read_inheritable_attribute(key) + elements) end def write_inheritable_hash(key, hash) write_inheritable_attribute(key, {}) if read_inheritable_attribute(key).nil? write_inheritable_attribute(key, read_inheritable_attribute(key).merge(hash)) end def read_inheritable_attribute(key) inheritable_attributes[key] end def reset_inheritable_attributes @inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES end private # Prevent this constant from being created multiple times EMPTY_INHERITABLE_ATTRIBUTES = {}.freeze unless const_defined?(:EMPTY_INHERITABLE_ATTRIBUTES) def inherited_with_inheritable_attributes(child) inherited_without_inheritable_attributes(child) if respond_to?(:inherited_without_inheritable_attributes) if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES) new_inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES else new_inheritable_attributes = inheritable_attributes.inject({}) do |memo, (key, value)| memo.update(key => value.duplicable? ? value.dup : value) end end child.instance_variable_set('@inheritable_attributes', new_inheritable_attributes) end alias inherited_without_inheritable_attributes inherited alias inherited inherited_with_inheritable_attributes end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/module/model_naming.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/module/model_naming.rb
module ActiveSupport class ModelName < String attr_reader :singular, :plural, :element, :collection, :partial_path alias_method :cache_key, :collection def initialize(name) super @singular = ActiveSupport::Inflector.underscore(self).tr('/', '_').freeze @plural = ActiveSupport::Inflector.pluralize(@singular).freeze @element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)).freeze @collection = ActiveSupport::Inflector.tableize(self).freeze @partial_path = "#{@collection}/#{@element}".freeze end end module CoreExtensions module Module # Returns an ActiveSupport::ModelName object for module. It can be # used to retrieve all kinds of naming-related information. def model_name @model_name ||= ::ActiveSupport::ModelName.new(name) end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
require "active_support/core_ext/array" # Extends the module object with module and instance accessors for class attributes, # just like the native attr* accessors for instance attributes. # # module AppConfiguration # mattr_accessor :google_api_key # self.google_api_key = "123456789" # # mattr_accessor :paypal_url # self.paypal_url = "www.sandbox.paypal.com" # end # # AppConfiguration.google_api_key = "overriding the api key!" class Module def mattr_reader(*syms) syms.each do |sym| next if sym.is_a?(Hash) class_eval(<<-EOS, __FILE__, __LINE__) unless defined? @@#{sym} # unless defined? @@pagination_options @@#{sym} = nil # @@pagination_options = nil end # end # def self.#{sym} # def self.pagination_options @@#{sym} # @@pagination_options end # end # def #{sym} # def pagination_options @@#{sym} # @@pagination_options end # end EOS end end def mattr_writer(*syms) options = syms.extract_options! syms.each do |sym| class_eval(<<-EOS, __FILE__, __LINE__) unless defined? @@#{sym} # unless defined? @@pagination_options @@#{sym} = nil # @@pagination_options = nil end # end # def self.#{sym}=(obj) # def self.pagination_options=(obj) @@#{sym} = obj # @@pagination_options = obj end # end # #{" # def #{sym}=(obj) # def pagination_options=(obj) @@#{sym} = obj # @@pagination_options = obj end # end " unless options[:instance_writer] == false } # # instance writer above is generated unless options[:instance_writer] == false EOS end end def mattr_accessor(*syms) mattr_reader(*syms) mattr_writer(*syms) end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb
class Module # Declare an attribute accessor with an initial default return value. # # To give attribute <tt>:age</tt> the initial value <tt>25</tt>: # # class Person # attr_accessor_with_default :age, 25 # end # # some_person.age # => 25 # some_person.age = 26 # some_person.age # => 26 # # To give attribute <tt>:element_name</tt> a dynamic default value, evaluated # in scope of self: # # attr_accessor_with_default(:element_name) { name.underscore } # def attr_accessor_with_default(sym, default = nil, &block) raise 'Default value or block required' unless !default.nil? || block define_method(sym, block_given? ? block : Proc.new { default }) module_eval(<<-EVAL, __FILE__, __LINE__) def #{sym}=(value) # def age=(value) class << self; attr_reader :#{sym} end # class << self; attr_reader :age end @#{sym} = value # @age = value end # end EVAL end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/module/introspection.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/module/introspection.rb
module ActiveSupport module CoreExtensions module Module # Returns the name of the module containing this one. # # p M::N.parent_name # => "M" def parent_name unless defined? @parent_name @parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil end @parent_name end # Returns the module which contains this one according to its name. # # module M # module N # end # end # X = M::N # # p M::N.parent # => M # p X.parent # => M # # The parent of top-level and anonymous modules is Object. # # p M.parent # => Object # p Module.new.parent # => Object # def parent parent_name ? parent_name.constantize : Object end # Returns all the parents of this module according to its name, ordered from # nested outwards. The receiver is not contained within the result. # # module M # module N # end # end # X = M::N # # p M.parents # => [Object] # p M::N.parents # => [M, Object] # p X.parents # => [M, Object] # def parents parents = [] if parent_name parts = parent_name.split('::') until parts.empty? parents << (parts * '::').constantize parts.pop end end parents << Object unless parents.include? Object parents end if RUBY_VERSION < '1.9' # Returns the constants that have been defined locally by this object and # not in an ancestor. This method is exact if running under Ruby 1.9. In # previous versions it may miss some constants if their definition in some # ancestor is identical to their definition in the receiver. def local_constants inherited = {} ancestors.each do |anc| next if anc == self anc.constants.each { |const| inherited[const] = anc.const_get(const) } end constants.select do |const| !inherited.key?(const) || inherited[const].object_id != const_get(const).object_id end end else def local_constants #:nodoc: constants(false) end end # Returns the names of the constants defined locally rather than the # constants themselves. See <tt>local_constants</tt>. def local_constant_names local_constants.map { |c| c.to_s } end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/module/loading.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/module/loading.rb
class Module # Returns String#underscore applied to the module name minus trailing classes. # # ActiveRecord.as_load_path # => "active_record" # ActiveRecord::Associations.as_load_path # => "active_record/associations" # ActiveRecord::Base.as_load_path # => "active_record" (Base is a class) # # The Kernel module gives an empty string by definition. # # Kernel.as_load_path # => "" # Math.as_load_path # => "math" def as_load_path if self == Object || self == Kernel '' elsif is_a? Class parent == self ? '' : parent.as_load_path else name.split('::').collect do |word| word.underscore end * '/' end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/module/inclusion.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/module/inclusion.rb
class Module # Returns the classes in the current ObjectSpace where this module has been # mixed in according to Module#included_modules. # # module M # end # # module N # include M # end # # class C # include M # end # # class D < C # end # # p M.included_in_classes # => [C, D] # def included_in_classes classes = [] ObjectSpace.each_object(Class) { |k| classes << k if k.included_modules.include?(self) } classes.reverse.inject([]) do |unique_classes, klass| unique_classes << klass unless unique_classes.collect { |k| k.to_s }.include?(klass.to_s) unique_classes end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/module/delegation.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/module/delegation.rb
class Module # Provides a delegate class method to easily expose contained objects' methods # as your own. Pass one or more methods (specified as symbols or strings) # and the name of the target object as the final <tt>:to</tt> option (also a symbol # or string). At least one method and the <tt>:to</tt> option are required. # # Delegation is particularly useful with Active Record associations: # # class Greeter < ActiveRecord::Base # def hello() "hello" end # def goodbye() "goodbye" end # end # # class Foo < ActiveRecord::Base # belongs_to :greeter # delegate :hello, :to => :greeter # end # # Foo.new.hello # => "hello" # Foo.new.goodbye # => NoMethodError: undefined method `goodbye' for #<Foo:0x1af30c> # # Multiple delegates to the same target are allowed: # # class Foo < ActiveRecord::Base # belongs_to :greeter # delegate :hello, :goodbye, :to => :greeter # end # # Foo.new.goodbye # => "goodbye" # # Methods can be delegated to instance variables, class variables, or constants # by providing them as a symbols: # # class Foo # CONSTANT_ARRAY = [0,1,2,3] # @@class_array = [4,5,6,7] # # def initialize # @instance_array = [8,9,10,11] # end # delegate :sum, :to => :CONSTANT_ARRAY # delegate :min, :to => :@@class_array # delegate :max, :to => :@instance_array # end # # Foo.new.sum # => 6 # Foo.new.min # => 4 # Foo.new.max # => 11 # # Delegates can optionally be prefixed using the <tt>:prefix</tt> option. If the value # is <tt>true</tt>, the delegate methods are prefixed with the name of the object being # delegated to. # # Person = Struct.new(:name, :address) # # class Invoice < Struct.new(:client) # delegate :name, :address, :to => :client, :prefix => true # end # # john_doe = Person.new("John Doe", "Vimmersvej 13") # invoice = Invoice.new(john_doe) # invoice.client_name # => "John Doe" # invoice.client_address # => "Vimmersvej 13" # # It is also possible to supply a custom prefix. # # class Invoice < Struct.new(:client) # delegate :name, :address, :to => :client, :prefix => :customer # end # # invoice = Invoice.new(john_doe) # invoice.customer_name # => "John Doe" # invoice.customer_address # => "Vimmersvej 13" # # If the object to which you delegate can be nil, you may want to use the # :allow_nil option. In that case, it returns nil instead of raising a # NoMethodError exception: # # class Foo # attr_accessor :bar # def initialize(bar = nil) # @bar = bar # end # delegate :zoo, :to => :bar # end # # Foo.new.zoo # raises NoMethodError exception (you called nil.zoo) # # class Foo # attr_accessor :bar # def initialize(bar = nil) # @bar = bar # end # delegate :zoo, :to => :bar, :allow_nil => true # end # # Foo.new.zoo # returns nil # def delegate(*methods) options = methods.pop unless options.is_a?(Hash) && to = options[:to] raise ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter)." end if options[:prefix] == true && options[:to].to_s =~ /^[^a-z_]/ raise ArgumentError, "Can only automatically set the delegation prefix when delegating to a method." end prefix = options[:prefix] && "#{options[:prefix] == true ? to : options[:prefix]}_" file, line = caller.first.split(':', 2) line = line.to_i methods.each do |method| on_nil = if options[:allow_nil] 'return' else %(raise "#{prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}") end module_eval(<<-EOS, file, line) def #{prefix}#{method}(*args, &block) # def customer_name(*args, &block) #{to}.__send__(#{method.inspect}, *args, &block) # client.__send__(:name, *args, &block) rescue NoMethodError # rescue NoMethodError if #{to}.nil? # if client.nil? #{on_nil} else # else raise # raise end # end end # end EOS end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/module/synchronization.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/module/synchronization.rb
class Module # Synchronize access around a method, delegating synchronization to a # particular mutex. A mutex (either a Mutex, or any object that responds to # #synchronize and yields to a block) must be provided as a final :with option. # The :with option should be a symbol or string, and can represent a method, # constant, or instance or class variable. # Example: # class SharedCache # @@lock = Mutex.new # def expire # ... # end # synchronize :expire, :with => :@@lock # end def synchronize(*methods) options = methods.extract_options! unless options.is_a?(Hash) && with = options[:with] raise ArgumentError, "Synchronization needs a mutex. Supply an options hash with a :with key as the last argument (e.g. synchronize :hello, :with => :@mutex)." end methods.each do |method| aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1 if method_defined?("#{aliased_method}_without_synchronization#{punctuation}") raise ArgumentError, "#{method} is already synchronized. Double synchronization is not currently supported." end module_eval(<<-EOS, __FILE__, __LINE__) def #{aliased_method}_with_synchronization#{punctuation}(*args, &block) # def expire_with_synchronization(*args, &block) #{with}.synchronize do # @@lock.synchronize do #{aliased_method}_without_synchronization#{punctuation}(*args, &block) # expire_without_synchronization(*args, &block) end # end end # end EOS alias_method_chain method, :synchronization end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/module/aliasing.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/module/aliasing.rb
module ActiveSupport module CoreExtensions module Module # Encapsulates the common pattern of: # # alias_method :foo_without_feature, :foo # alias_method :foo, :foo_with_feature # # With this, you simply do: # # alias_method_chain :foo, :feature # # And both aliases are set up for you. # # Query and bang methods (foo?, foo!) keep the same punctuation: # # alias_method_chain :foo?, :feature # # is equivalent to # # alias_method :foo_without_feature?, :foo? # alias_method :foo?, :foo_with_feature? # # so you can safely chain foo, foo?, and foo! with the same feature. def alias_method_chain(target, feature) # Strip out punctuation on predicates or bang methods since # e.g. target?_without_feature is not a valid method name. aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1 yield(aliased_target, punctuation) if block_given? with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}" alias_method without_method, target alias_method target, with_method case when public_method_defined?(without_method) public target when protected_method_defined?(without_method) protected target when private_method_defined?(without_method) private target end end # Allows you to make aliases for attributes, which includes # getter, setter, and query methods. # # Example: # # class Content < ActiveRecord::Base # # has a title attribute # end # # class Email < Content # alias_attribute :subject, :title # end # # e = Email.find(1) # e.title # => "Superstars" # e.subject # => "Superstars" # e.subject? # => true # e.subject = "Megastars" # e.title # => "Megastars" def alias_attribute(new_name, old_name) module_eval <<-STR, __FILE__, __LINE__+1 def #{new_name}; self.#{old_name}; end # def subject; self.title; end def #{new_name}?; self.#{old_name}?; end # def subject?; self.title?; end def #{new_name}=(v); self.#{old_name} = v; end # def subject=(v); self.title = v; end STR end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/module/attr_internal.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/module/attr_internal.rb
class Module # Declares an attribute reader backed by an internally-named instance variable. def attr_internal_reader(*attrs) attrs.each do |attr| module_eval "def #{attr}() #{attr_internal_ivar_name(attr)} end" end end # Declares an attribute writer backed by an internally-named instance variable. def attr_internal_writer(*attrs) attrs.each do |attr| module_eval "def #{attr}=(v) #{attr_internal_ivar_name(attr)} = v end" end end # Declares an attribute reader and writer backed by an internally-named instance # variable. def attr_internal_accessor(*attrs) attr_internal_reader(*attrs) attr_internal_writer(*attrs) end alias_method :attr_internal, :attr_internal_accessor private mattr_accessor :attr_internal_naming_format self.attr_internal_naming_format = '@_%s' def attr_internal_ivar_name(attr) attr_internal_naming_format % attr end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false
ThoughtWorksStudios/oauth2_provider
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/provider/vendor/rails/activesupport/lib/active_support/core_ext/date_time/conversions.rb
provider/vendor/rails/activesupport/lib/active_support/core_ext/date_time/conversions.rb
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module DateTime #:nodoc: # Converting datetimes to formatted strings, dates, and times. module Conversions def self.append_features(base) #:nodoc: base.class_eval do alias_method :default_inspect, :inspect alias_method :to_default_s, :to_s unless (instance_methods(false) & [:to_s, 'to_s']).empty? # Ruby 1.9 has DateTime#to_time which internally relies on Time. We define our own #to_time which allows # DateTimes outside the range of what can be created with Time. remove_method :to_time if instance_methods.include?(:to_time) end super base.class_eval do alias_method :to_s, :to_formatted_s alias_method :inspect, :readable_inspect end end # Convert to a formatted string. See Time::DATE_FORMATS for predefined formats. # # This method is aliased to <tt>to_s</tt>. # # === Examples # datetime = DateTime.civil(2007, 12, 4, 0, 0, 0, 0) # => Tue, 04 Dec 2007 00:00:00 +0000 # # datetime.to_formatted_s(:db) # => "2007-12-04 00:00:00" # datetime.to_s(:db) # => "2007-12-04 00:00:00" # datetime.to_s(:number) # => "20071204000000" # datetime.to_formatted_s(:short) # => "04 Dec 00:00" # datetime.to_formatted_s(:long) # => "December 04, 2007 00:00" # datetime.to_formatted_s(:long_ordinal) # => "December 4th, 2007 00:00" # datetime.to_formatted_s(:rfc822) # => "Tue, 04 Dec 2007 00:00:00 +0000" # # == Adding your own datetime formats to to_formatted_s # DateTime formats are shared with Time. You can add your own to the # Time::DATE_FORMATS hash. Use the format name as the hash key and # either a strftime string or Proc instance that takes a time or # datetime argument as the value. # # # config/initializers/time_formats.rb # Time::DATE_FORMATS[:month_and_year] = "%B %Y" # Time::DATE_FORMATS[:short_ordinal] = lambda { |time| time.strftime("%B #{time.day.ordinalize}") } def to_formatted_s(format = :default) return to_default_s unless formatter = ::Time::DATE_FORMATS[format] formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter) end # Returns the +utc_offset+ as an +HH:MM formatted string. Examples: # # datetime = DateTime.civil(2000, 1, 1, 0, 0, 0, Rational(-6, 24)) # datetime.formatted_offset # => "-06:00" # datetime.formatted_offset(false) # => "-0600" def formatted_offset(colon = true, alternate_utc_string = nil) utc? && alternate_utc_string || utc_offset.to_utc_offset_s(colon) end # Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005 14:30:00 +0000" def readable_inspect to_s(:rfc822) end # Converts self to a Ruby Date object; time portion is discarded def to_date ::Date.new(year, month, day) end # Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class # If self has an offset other than 0, self will just be returned unaltered, since there's no clean way to map it to a Time def to_time self.offset == 0 ? ::Time.utc_time(year, month, day, hour, min, sec) : self end # To be able to keep Times, Dates and DateTimes interchangeable on conversions def to_datetime self end # Converts datetime to an appropriate format for use in XML def xmlschema strftime("%Y-%m-%dT%H:%M:%S%Z") end if RUBY_VERSION < '1.9' # Converts self to a floating-point number of seconds since the Unix epoch def to_f days_since_unix_epoch = self - ::DateTime.civil(1970) (days_since_unix_epoch * 86_400).to_f end end end end end
ruby
MIT
d54702f194edd05389968cf8947465860abccc5d
2026-01-04T17:46:04.645080Z
false