Sha256: a6c3a9d3dac41faea781f9c8f2f273c77668c5c6b7362145ddf0ca15a1a7ef0f

Contents?: true

Size: 1.04 KB

Versions: 33

Compression:

Stored size: 1.04 KB

Contents

require 'json' unless defined?(JSON)

module ActiveSupport
  module JSON
    module Backends
      module JSONGem
        ParseError = ::JSON::ParserError
        extend self

        # Parses a JSON string or IO and convert it into an object
        def decode(json)
          if json.respond_to?(:read)
            json = json.read
          end
          data = ::JSON.parse(json)
          if ActiveSupport.parse_json_times
            convert_dates_from(data)
          else
            data
          end
        end

      private
        def convert_dates_from(data)
          case data
          when nil
            nil
          when DATE_REGEX
            begin
              DateTime.parse(data)
            rescue ArgumentError
              data
            end
          when Array
            data.map! { |d| convert_dates_from(d) }
          when Hash
            data.each do |key, value|
              data[key] = convert_dates_from(value)
            end
          else
            data
          end
        end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 2 rubygems

Version Path
activesupport-3.0.20 lib/active_support/json/backends/jsongem.rb
activesupport-3.0.19 lib/active_support/json/backends/jsongem.rb
activesupport-3.0.18 lib/active_support/json/backends/jsongem.rb
activesupport-3.0.17 lib/active_support/json/backends/jsongem.rb
activesupport-3.0.16 lib/active_support/json/backends/jsongem.rb
activesupport-3.0.15 lib/active_support/json/backends/jsongem.rb
activesupport-3.0.14 lib/active_support/json/backends/jsongem.rb
activesupport-3.0.13 lib/active_support/json/backends/jsongem.rb
activesupport-3.0.13.rc1 lib/active_support/json/backends/jsongem.rb
activesupport-3.0.12 lib/active_support/json/backends/jsongem.rb
activesupport-3.0.12.rc1 lib/active_support/json/backends/jsongem.rb
activesupport-3.0.11 lib/active_support/json/backends/jsongem.rb
messagebus_ruby_api-0.4.7 spec/ruby/1.9.1/gems/activesupport-3.0.9/lib/active_support/json/backends/jsongem.rb
messagebus_ruby_api-0.4.4 spec/ruby/1.9.1/gems/activesupport-3.0.9/lib/active_support/json/backends/jsongem.rb
activesupport-3.0.10 lib/active_support/json/backends/jsongem.rb
activesupport-3.0.10.rc1 lib/active_support/json/backends/jsongem.rb
activesupport-3.0.9 lib/active_support/json/backends/jsongem.rb
activesupport-3.0.9.rc5 lib/active_support/json/backends/jsongem.rb
activesupport-3.0.9.rc4 lib/active_support/json/backends/jsongem.rb
activesupport-3.0.9.rc3 lib/active_support/json/backends/jsongem.rb