activesupport 3.0.7 → 3.0.8.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ *Rails 3.0.8 (unreleased)*
2
+
3
+ * No changes.
4
+
1
5
  *Rails 3.0.7 (April 18, 2011)*
2
6
 
3
7
  * Hash.from_xml no longer loses attributes on tags containing only whitespace [André Arko]
@@ -41,19 +41,17 @@ module ActiveSupport
41
41
 
42
42
  def initialize(log, level = DEBUG)
43
43
  @level = level
44
- @buffer = {}
44
+ @buffer = Hash.new { |h,k| h[k] = [] }
45
45
  @auto_flushing = 1
46
46
  @guard = Mutex.new
47
47
 
48
48
  if log.respond_to?(:write)
49
49
  @log = log
50
50
  elsif File.exist?(log)
51
- @log = open(log, (File::WRONLY | File::APPEND))
52
- @log.sync = true
51
+ @log = open_log(log, (File::WRONLY | File::APPEND))
53
52
  else
54
53
  FileUtils.mkdir_p(File.dirname(log))
55
- @log = open(log, (File::WRONLY | File::APPEND | File::CREAT))
56
- @log.sync = true
54
+ @log = open_log(log, (File::WRONLY | File::APPEND | File::CREAT))
57
55
  end
58
56
  end
59
57
 
@@ -100,13 +98,8 @@ module ActiveSupport
100
98
 
101
99
  def flush
102
100
  @guard.synchronize do
103
- unless buffer.empty?
104
- old_buffer = buffer
105
- all_content = StringIO.new
106
- old_buffer.each do |content|
107
- all_content << content
108
- end
109
- @log.write(all_content.string)
101
+ buffer.each do |content|
102
+ @log.write(content)
110
103
  end
111
104
 
112
105
  # Important to do this even if buffer was empty or else @buffer will
@@ -127,11 +120,20 @@ module ActiveSupport
127
120
  end
128
121
 
129
122
  def buffer
130
- @buffer[Thread.current] ||= []
123
+ @buffer[Thread.current]
131
124
  end
132
125
 
133
126
  def clear_buffer
134
127
  @buffer.delete(Thread.current)
135
128
  end
129
+
130
+ private
131
+
132
+ def open_log(log, mode)
133
+ open(log, mode).tap do |log|
134
+ log.set_encoding(Encoding::BINARY) if log.respond_to?(:set_encoding)
135
+ log.sync = true
136
+ end
137
+ end
136
138
  end
137
139
  end
@@ -120,7 +120,7 @@ module ActiveSupport
120
120
  # Lock a file for a block so only one process can modify it at a time.
121
121
  def lock_file(file_name, &block) # :nodoc:
122
122
  if File.exist?(file_name)
123
- File.open(file_name, 'r') do |f|
123
+ File.open(file_name, 'r+') do |f|
124
124
  begin
125
125
  f.flock File::LOCK_EX
126
126
  yield
@@ -1,4 +1,10 @@
1
1
  require 'bigdecimal'
2
+
3
+ begin
4
+ require 'psych'
5
+ rescue LoadError
6
+ end
7
+
2
8
  require 'yaml'
3
9
 
4
10
  class BigDecimal
@@ -12,12 +18,19 @@ class BigDecimal
12
18
  #
13
19
  # Note that reconstituting YAML floats to native floats may lose precision.
14
20
  def to_yaml(opts = {})
21
+ return super if defined?(YAML::ENGINE) && !YAML::ENGINE.syck?
22
+
15
23
  YAML.quick_emit(nil, opts) do |out|
16
24
  string = to_s
17
25
  out.scalar(YAML_TAG, YAML_MAPPING[string] || string, :plain)
18
26
  end
19
27
  end
20
28
 
29
+ def encode_with(coder)
30
+ string = to_s
31
+ coder.represent_scalar(nil, YAML_MAPPING[string] || string)
32
+ end
33
+
21
34
  def to_d
22
35
  self
23
36
  end
@@ -96,7 +96,8 @@ class Hash
96
96
  raise "can't typecast #{entries.inspect}"
97
97
  end
98
98
  end
99
- elsif value['type'] == 'file' || value["__content__"].present?
99
+ elsif value['type'] == 'file' ||
100
+ (value["__content__"] && (value.keys.size == 1 || value["__content__"].present?))
100
101
  content = value["__content__"]
101
102
  if parser = ActiveSupport::XmlMini::PARSING[value["type"]]
102
103
  parser.arity == 1 ? parser.call(content) : parser.call(content, value)
@@ -7,14 +7,21 @@ module ActiveSupport
7
7
  ParseError = ::StandardError
8
8
  extend self
9
9
 
10
+ EXCEPTIONS = [::ArgumentError] # :nodoc:
11
+ begin
12
+ require 'psych'
13
+ EXCEPTIONS << Psych::SyntaxError
14
+ rescue LoadError
15
+ end
16
+
10
17
  # Parses a JSON string or IO and converts it into an object
11
18
  def decode(json)
12
19
  if json.respond_to?(:read)
13
20
  json = json.read
14
21
  end
15
22
  YAML.load(convert_json_to_yaml(json))
16
- rescue ArgumentError
17
- raise ParseError, "Invalid JSON string"
23
+ rescue *EXCEPTIONS => e
24
+ raise ParseError, "Invalid JSON string: '%s'" % json
18
25
  end
19
26
 
20
27
  protected
@@ -32,7 +39,7 @@ module ActiveSupport
32
39
  if valid_date?(json[pos..scanner.pos-2])
33
40
  # found a date, track the exact positions of the quotes so we can
34
41
  # overwrite them with spaces later.
35
- times << pos << scanner.pos
42
+ times << pos
36
43
  end
37
44
  quoting = false
38
45
  end
@@ -63,7 +70,7 @@ module ActiveSupport
63
70
  chunk = scanner.peek(right_pos[i] - scanner.pos + 1)
64
71
  # overwrite the quotes found around the dates with spaces
65
72
  while times.size > 0 && times[0] <= right_pos[i]
66
- chunk[times.shift - scanner.pos - 1] = ' '
73
+ chunk.insert(times.shift - scanner.pos - 1, '! ')
67
74
  end
68
75
  chunk.gsub!(/\\([\\\/]|u[[:xdigit:]]{4})/) do
69
76
  ustr = $1
@@ -81,7 +81,7 @@ module ActiveSupport
81
81
 
82
82
  # Flush all log_subscribers' logger.
83
83
  def flush_all!
84
- flushable_loggers.each(&:flush)
84
+ flushable_loggers.each { |log| log.flush }
85
85
  end
86
86
  end
87
87
 
@@ -1,3 +1,8 @@
1
+ begin
2
+ require 'psych'
3
+ rescue LoadError
4
+ end
5
+
1
6
  require 'yaml'
2
7
 
3
8
  YAML.add_builtin_type("omap") do |type, val|
@@ -11,9 +16,17 @@ module ActiveSupport
11
16
  "!tag:yaml.org,2002:omap"
12
17
  end
13
18
 
19
+ def encode_with(coder)
20
+ coder.represent_seq '!omap', map { |k,v| { k => v } }
21
+ end
22
+
14
23
  def to_yaml(opts = {})
24
+ if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?
25
+ return super
26
+ end
27
+
15
28
  YAML.quick_emit(self, opts) do |out|
16
- out.seq(taguri, to_yaml_style) do |seq|
29
+ out.seq(taguri) do |seq|
17
30
  each do |k, v|
18
31
  seq.add(k => v)
19
32
  end
@@ -135,14 +135,20 @@ module ActiveSupport
135
135
  end
136
136
  end
137
137
 
138
- def to_yaml(options = {})
139
- if options.kind_of?(YAML::Emitter)
140
- utc.to_yaml(options)
138
+ def encode_with(coder)
139
+ if coder.respond_to?(:represent_object)
140
+ coder.represent_object(nil, utc)
141
141
  else
142
- time.to_yaml(options).gsub('Z', formatted_offset(true, 'Z'))
142
+ coder.represent_scalar(nil, utc.strftime("%Y-%m-%d %H:%M:%S.%9NZ"))
143
143
  end
144
144
  end
145
145
 
146
+ def to_yaml(options = {})
147
+ return super if defined?(YAML::ENGINE) && !YAML::ENGINE.syck?
148
+
149
+ utc.to_yaml(options)
150
+ end
151
+
146
152
  def httpdate
147
153
  utc.httpdate
148
154
  end
@@ -2,8 +2,8 @@ module ActiveSupport
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- TINY = 7
6
- PRE = nil
5
+ TINY = 8
6
+ PRE = "rc1"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
9
  end
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activesupport
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
5
- prerelease:
4
+ hash: 15424055
5
+ prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 7
10
- version: 3.0.7
9
+ - 8
10
+ - rc
11
+ - 1
12
+ version: 3.0.8.rc1
11
13
  platform: ruby
12
14
  authors:
13
15
  - David Heinemeier Hansson
@@ -15,7 +17,7 @@ autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
19
 
18
- date: 2011-04-18 00:00:00 Z
20
+ date: 2011-05-25 00:00:00 Z
19
21
  dependencies: []
20
22
 
21
23
  description: A toolkit of support libraries and Ruby core extensions extracted from the Rails framework. Rich support for multibyte strings, internationalization, time zones, and testing.
@@ -258,16 +260,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
258
260
  required_rubygems_version: !ruby/object:Gem::Requirement
259
261
  none: false
260
262
  requirements:
261
- - - ">="
263
+ - - ">"
262
264
  - !ruby/object:Gem::Version
263
- hash: 3
265
+ hash: 25
264
266
  segments:
265
- - 0
266
- version: "0"
267
+ - 1
268
+ - 3
269
+ - 1
270
+ version: 1.3.1
267
271
  requirements: []
268
272
 
269
273
  rubyforge_project: activesupport
270
- rubygems_version: 1.7.2
274
+ rubygems_version: 1.8.2
271
275
  signing_key:
272
276
  specification_version: 3
273
277
  summary: A toolkit of support libraries and Ruby core extensions extracted from the Rails framework.