aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/buffered_logger.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/array/conversions.rb19
-rw-r--r--activesupport/lib/active_support/core_ext/exception.rb19
-rw-r--r--activesupport/lib/active_support/core_ext/logger.rb2
-rw-r--r--activesupport/lib/active_support/inflector.rb2
-rw-r--r--activesupport/lib/active_support/locale/en.yml5
-rw-r--r--activesupport/lib/active_support/multibyte/chars.rb8
7 files changed, 37 insertions, 20 deletions
diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb
index 77e0b1d33f..b2c863c893 100644
--- a/activesupport/lib/active_support/buffered_logger.rb
+++ b/activesupport/lib/active_support/buffered_logger.rb
@@ -13,6 +13,8 @@ module ActiveSupport
MAX_BUFFER_SIZE = 1000
+ ##
+ # :singleton-method:
# Set to false to disable the silencer
cattr_accessor :silencer
self.silencer = true
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb
index f0d6591135..69d35dafd3 100644
--- a/activesupport/lib/active_support/core_ext/array/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -3,15 +3,16 @@ module ActiveSupport #: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>:connector</tt> - The word used to join the last element in arrays with two or more elements (default: "and")
- # * <tt>:skip_last_comma</tt> - Set to true to return "a, b and c" instead of "a, b, and c".
+ # * <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 = {})
- options.assert_valid_keys(:connector, :skip_last_comma, :locale)
+ options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale)
- default = I18n.translate(:'support.array.sentence_connector', :locale => options[:locale])
- default_skip_last_comma = I18n.translate(:'support.array.skip_last_comma', :locale => options[:locale])
- options.reverse_merge! :connector => default, :skip_last_comma => default_skip_last_comma
- options[:connector] = "#{options[:connector]} " unless options[:connector].nil? || options[:connector].strip == ''
+ 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])
+ 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
@@ -19,9 +20,9 @@ module ActiveSupport #:nodoc:
when 1
self[0].to_s
when 2
- "#{self[0]} #{options[:connector]}#{self[1]}"
+ "#{self[0]}#{options[:two_words_connector]}#{self[1]}"
else
- "#{self[0...-1].join(', ')}#{options[:skip_last_comma] ? '' : ','} #{options[:connector]}#{self[-1]}"
+ "#{self[0...-1].join(options[:words_connector])}#{options[:last_word_connector]}#{self[-1]}"
end
end
diff --git a/activesupport/lib/active_support/core_ext/exception.rb b/activesupport/lib/active_support/core_ext/exception.rb
index 73470cbe05..cde0df4153 100644
--- a/activesupport/lib/active_support/core_ext/exception.rb
+++ b/activesupport/lib/active_support/core_ext/exception.rb
@@ -11,10 +11,11 @@ class Exception # :nodoc:
def clean_message
Pathname.clean_within message
end
-
+
TraceSubstitutions = []
- FrameworkRegexp = /generated|vendor|dispatch|ruby|script\/\w+/
-
+ 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)|
@@ -22,20 +23,22 @@ class Exception # :nodoc:
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
- non_app_frame && ! before_application_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
diff --git a/activesupport/lib/active_support/core_ext/logger.rb b/activesupport/lib/active_support/core_ext/logger.rb
index c622554860..24fe7294c9 100644
--- a/activesupport/lib/active_support/core_ext/logger.rb
+++ b/activesupport/lib/active_support/core_ext/logger.rb
@@ -30,6 +30,8 @@ require 'logger'
#
# 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
diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb
index 683af4556e..4921b99677 100644
--- a/activesupport/lib/active_support/inflector.rb
+++ b/activesupport/lib/active_support/inflector.rb
@@ -254,7 +254,7 @@ module ActiveSupport
# @person = Person.find(1)
# # => #<Person id: 1, name: "Donald E. Knuth">
#
- # <%= link_to(@person.name, person_path %>
+ # <%= link_to(@person.name, person_path(@person)) %>
# # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
def parameterize(string, sep = '-')
re_sep = Regexp.escape(sep)
diff --git a/activesupport/lib/active_support/locale/en.yml b/activesupport/lib/active_support/locale/en.yml
index 92132cacd5..e604c9ee8c 100644
--- a/activesupport/lib/active_support/locale/en.yml
+++ b/activesupport/lib/active_support/locale/en.yml
@@ -28,5 +28,6 @@ en:
# Used in array.to_sentence.
support:
array:
- sentence_connector: "and"
- skip_last_comma: false
+ words_connector: ", "
+ two_words_connector: " and "
+ last_word_connector: ", and "
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb
index be9c6d3567..a00b165222 100644
--- a/activesupport/lib/active_support/multibyte/chars.rb
+++ b/activesupport/lib/active_support/multibyte/chars.rb
@@ -344,6 +344,14 @@ module ActiveSupport #:nodoc:
end
alias_method :[], :slice
+ # Converts first character in the string to Unicode value
+ #
+ # Example:
+ # 'こんにちは'.mb_chars.ord #=> 12371
+ def ord
+ self.class.u_unpack(@wrapped_string)[0]
+ end
+
# Convert characters in the string to uppercase.
#
# Example: