aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-10-22 14:27:55 -0500
committerFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-10-22 14:27:55 -0500
commit2ef4d5ed5cbbb2a9266c99535e5f51918ae3e3b6 (patch)
tree406457f6157c5b6b6ec86572ac9fb748b6a50422
parent77eb1fb22d0f25183eb608b8ae55d9f1eb8bec59 (diff)
downloadrails-2ef4d5ed5cbbb2a9266c99535e5f51918ae3e3b6.tar.gz
rails-2ef4d5ed5cbbb2a9266c99535e5f51918ae3e3b6.tar.bz2
rails-2ef4d5ed5cbbb2a9266c99535e5f51918ae3e3b6.zip
fix output messages - docs [ci skip]
-rw-r--r--activemodel/lib/active_model/errors.rb32
-rw-r--r--activesupport/lib/active_support/core_ext/array/extract_options.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/array/wrap.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/hash/deep_merge.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/hash/slice.rb6
-rw-r--r--guides/source/active_record_validations_callbacks.md4
-rw-r--r--guides/source/active_support_core_extensions.md36
-rw-r--r--guides/source/active_support_instrumentation.md4
-rw-r--r--guides/source/i18n.md2
9 files changed, 45 insertions, 45 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index 473bb7d9b7..6882b59e26 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -75,14 +75,14 @@ module ActiveModel
@messages = {}
end
- def initialize_dup(other) #:nodoc:
+ def initialize_dup(other) # :nodoc:
@messages = other.messages.dup
super
end
# Clear the error messages.
#
- # person.errors.full_messages # => ["name can not be nil"]
+ # person.errors.full_messages # => ["name can not be nil"]
# person.errors.clear
# person.errors.full_messages # => []
def clear
@@ -92,9 +92,9 @@ module ActiveModel
# Returns +true+ if the error messages include an error for the given key
# +attribute+, +false+ otherwise.
#
- # person.errors.messages # => { name: ["can not be nil"] }
+ # person.errors.messages # => {:name=>["can not be nil"]}
# person.errors.include?(:name) # => true
- # person.errors.include?(:age) # => false
+ # person.errors.include?(:age) # => false
def include?(attribute)
(v = messages[attribute]) && v.any?
end
@@ -103,7 +103,7 @@ module ActiveModel
# Get messages for +key+.
#
- # person.errors.messages # => { name: ["can not be nil"] }
+ # person.errors.messages # => {:name=>["can not be nil"]}
# person.errors.get(:name) # => ["can not be nil"]
# person.errors.get(:age) # => nil
def get(key)
@@ -177,7 +177,7 @@ module ActiveModel
# Returns all message values.
#
- # person.errors.messages # => { name: ["can not be nil", "must be specified"] }
+ # person.errors.messages # => {:name=>["can not be nil", "must be specified"]}
# person.errors.values # => [["can not be nil", "must be specified"]]
def values
messages.values
@@ -185,7 +185,7 @@ module ActiveModel
# Returns all message keys.
#
- # person.errors.messages # => { name: ["can not be nil", "must be specified"] }
+ # person.errors.messages # => {:name=>["can not be nil", "must be specified"]}
# person.errors.keys # => [:name]
def keys
messages.keys
@@ -240,8 +240,8 @@ module ActiveModel
# object. You can pass the <tt>:full_messages</tt> option. This determines
# if the json object should contain full messages or not (false by default).
#
- # person.as_json # => { name: ["can not be nil"] }
- # person.as_json(full_messages: true) # => { name: ["name can not be nil"] }
+ # person.as_json # => {:name=>["can not be nil"]}
+ # person.as_json(full_messages: true) # => {:name=>["name can not be nil"]}
def as_json(options=nil)
to_hash(options && options[:full_messages])
end
@@ -249,8 +249,8 @@ module ActiveModel
# Returns a Hash of attributes with their error messages. If +full_messages+
# is +true+, it will contain full messages (see +full_message+).
#
- # person.to_hash # => { name: ["can not be nil"] }
- # person.to_hash(true) # => { name: ["name can not be nil"] }
+ # person.to_hash # => {:name=>["can not be nil"]}
+ # person.to_hash(true) # => {:name=>["name can not be nil"]}
def to_hash(full_messages = false)
if full_messages
messages = {}
@@ -273,7 +273,7 @@ module ActiveModel
# # => ["is invalid", "must be implemented"]
#
# person.errors.messages
- # # => { name: ["must be implemented", "is invalid"] }
+ # # => {:name=>["must be implemented", "is invalid"]}
#
# If +message+ is a symbol, it will be translated using the appropriate
# scope (see +generate_message+).
@@ -286,9 +286,9 @@ module ActiveModel
# <tt>:strict</tt> option can also be set to any other exception.
#
# person.errors.add(:name, nil, strict: true)
- # # => ActiveModel::StrictValidationFailed: name is invalid
+ # # => ActiveModel::StrictValidationFailed: name is invalid
# person.errors.add(:name, nil, strict: NameIsInvalid)
- # # => NameIsInvalid: name is invalid
+ # # => NameIsInvalid: name is invalid
#
# person.errors.messages # => {}
def add(attribute, message = nil, options = {})
@@ -306,7 +306,7 @@ module ActiveModel
#
# person.errors.add_on_empty(:name)
# person.errors.messages
- # # => { name: ["can't be empty"] }
+ # # => {:name=>["can't be empty"]}
def add_on_empty(attributes, options = {})
[attributes].flatten.each do |attribute|
value = @base.send(:read_attribute_for_validation, attribute)
@@ -320,7 +320,7 @@ module ActiveModel
#
# person.errors.add_on_blank(:name)
# person.errors.messages
- # # => { name: ["can't be blank"] }
+ # # => {:name=>["can't be blank"]}
def add_on_blank(attributes, options = {})
[attributes].flatten.each do |attribute|
value = @base.send(:read_attribute_for_validation, attribute)
diff --git a/activesupport/lib/active_support/core_ext/array/extract_options.rb b/activesupport/lib/active_support/core_ext/array/extract_options.rb
index 5f153a2cc3..9008a0df2a 100644
--- a/activesupport/lib/active_support/core_ext/array/extract_options.rb
+++ b/activesupport/lib/active_support/core_ext/array/extract_options.rb
@@ -18,7 +18,7 @@ class Array
# end
#
# options(1, 2) # => {}
- # options(1, 2, a: :b) # => {a: :b}
+ # options(1, 2, a: :b) # => {:a=>:b}
def extract_options!
if last.is_a?(Hash) && last.extractable_options?
pop
diff --git a/activesupport/lib/active_support/core_ext/array/wrap.rb b/activesupport/lib/active_support/core_ext/array/wrap.rb
index ffaf6ef024..05b09a4c7f 100644
--- a/activesupport/lib/active_support/core_ext/array/wrap.rb
+++ b/activesupport/lib/active_support/core_ext/array/wrap.rb
@@ -23,7 +23,7 @@ class Array
# The last point is particularly worth comparing for some enumerables:
#
# Array(foo: :bar) # => [[:foo, :bar]]
- # Array.wrap(foo: :bar) # => [{foo: :bar}]
+ # Array.wrap(foo: :bar) # => [{:foo=>:bar}]
#
# There's also a related idiom that uses the splat operator:
#
diff --git a/activesupport/lib/active_support/core_ext/hash/deep_merge.rb b/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
index 6ce2847ab5..e07db50b77 100644
--- a/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
+++ b/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
@@ -7,7 +7,7 @@ class Hash
# h1.deep_merge(h2) #=> {x: {y: [7, 8, 9]}, z: "xyz"}
# h2.deep_merge(h1) #=> {x: {y: [4, 5, 6]}, z: [7, 8, 9]}
# h1.deep_merge(h2) { |key, old, new| Array.wrap(old) + Array.wrap(new) }
- # #=> {x: {y: [4, 5, 6, 7, 8, 9]}, z: [7, 8, 9, "xyz"]}
+ # #=> {:x=>{:y=>[4, 5, 6, 7, 8, 9]}, :z=>[7, 8, 9, "xyz"]}
def deep_merge(other_hash, &block)
dup.deep_merge!(other_hash, &block)
end
diff --git a/activesupport/lib/active_support/core_ext/hash/slice.rb b/activesupport/lib/active_support/core_ext/hash/slice.rb
index a92c5968ed..9fa9b3dac4 100644
--- a/activesupport/lib/active_support/core_ext/hash/slice.rb
+++ b/activesupport/lib/active_support/core_ext/hash/slice.rb
@@ -21,7 +21,7 @@ class Hash
# Returns a hash containing the removed key/value pairs.
#
# { a: 1, b: 2, c: 3, d: 4 }.slice!(:a, :b)
- # # => {c: 3, d: 4}
+ # # => {:c=>3, :d=>4}
def slice!(*keys)
keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
omit = slice(*self.keys - keys)
@@ -32,8 +32,8 @@ class Hash
# Removes and returns the key/value pairs matching the given keys.
#
- # { a: 1, b: 2, c: 3, d: 4 }.extract!(:a, :b) # => { a: 1, b: 2 }
- # { a: 1, b: 2 }.extract!(:a, :x) # => { a: 1 }
+ # { a: 1, b: 2, c: 3, d: 4 }.extract!(:a, :b) # => {:a=>1, :b=>2}
+ # { a: 1, b: 2 }.extract!(:a, :x) # => {:a=>1}
def extract!(*keys)
keys.each_with_object(self.class.new) { |key, result| result[key] = delete(key) if has_key?(key) }
end
diff --git a/guides/source/active_record_validations_callbacks.md b/guides/source/active_record_validations_callbacks.md
index 7555ef4226..5c27ccbf9e 100644
--- a/guides/source/active_record_validations_callbacks.md
+++ b/guides/source/active_record_validations_callbacks.md
@@ -736,7 +736,7 @@ end
person = Person.new
person.valid? # => false
person.errors
- # => {name: ["can't be blank", "is too short (minimum is 3 characters)"]}
+ # => {:name=>["can't be blank", "is too short (minimum is 3 characters)"]}
person = Person.new(name: "John Doe")
person.valid? # => true
@@ -1003,7 +1003,7 @@ Callbacks can also be registered to only fire on certain lifecycle events:
```ruby
class User < ActiveRecord::Base
before_validation :normalize_name, on: :create
-
+
# :on takes an array as well
after_validation :set_location, on: [ :create, :update ]
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md
index c08ad1ee90..e7ed62ef47 100644
--- a/guides/source/active_support_core_extensions.md
+++ b/guides/source/active_support_core_extensions.md
@@ -2372,7 +2372,7 @@ This method is similar in purpose to `Kernel#Array`, but there are some differen
The last point is particularly worth comparing for some enumerables:
```ruby
-Array.wrap(foo: :bar) # => [{foo: :bar}]
+Array.wrap(foo: :bar) # => [{:foo=>:bar}]
Array(foo: :bar) # => [[:foo, :bar]]
```
@@ -2557,7 +2557,7 @@ Ruby has a built-in method `Hash#merge` that merges two hashes:
```ruby
{a: 1, b: 1}.merge(a: 0, c: 2)
-# => {a: 0, b: 1, c: 2}
+# => {:a=>0, :b=>1, :c=>2}
```
Active Support defines a few more ways of merging hashes that may be convenient.
@@ -2602,7 +2602,7 @@ Active Support defines `Hash#deep_merge`. In a deep merge, if a key is found in
```ruby
{a: {b: 1}}.deep_merge(a: {c: 2})
-# => {a: {b: 1, c: 2}}
+# => {:a=>{:b=>1, :c=>2}}
```
The method `deep_merge!` performs a deep merge in place.
@@ -2641,17 +2641,17 @@ The method `diff` returns a hash that represents a diff of the receiver and the
# => {}, first rule
{a: 1}.diff(a: 2)
-# => {a: 1}, second rule
+# => {:a=>1}, second rule
{a: 1}.diff(b: 2)
-# => {a: 1, b: 2}, third rule
+# => {:a=>1, :b=>2}, third rule
{a: 1, b: 2, c: 3}.diff(b: 1, c: 3, d: 4)
-# => {a: 1, b: 2, d: 4}, all rules
+# => {:a=>1, :b=>2, :d=>4}, all rules
{}.diff({}) # => {}
-{a: 1}.diff({}) # => {a: 1}
-{}.diff(a: 1) # => {a: 1}
+{a: 1}.diff({}) # => {:a=>1}
+{}.diff(a: 1) # => {:a=>1}
```
An important property of this diff hash is that you can retrieve the original hash by applying `diff` twice:
@@ -2671,7 +2671,7 @@ NOTE: Defined in `active_support/core_ext/hash/diff.rb`.
The method `except` returns a hash with the keys in the argument list removed, if present:
```ruby
-{a: 1, b: 2}.except(:a) # => {b: 2}
+{a: 1, b: 2}.except(:a) # => {:b=>2}
```
If the receiver responds to `convert_key`, the method is called on each of the arguments. This allows `except` to play nice with hashes with indifferent access for instance:
@@ -2776,7 +2776,7 @@ The method `symbolize_keys` returns a hash that has a symbolized version of the
```ruby
{nil => nil, 1 => 1, "a" => "a"}.symbolize_keys
-# => {1 => 1, nil => nil, a: "a"}
+# => {1=>1, nil=>nil, :a=>"a"}
```
WARNING. Note in the previous example only one key was symbolized.
@@ -2785,7 +2785,7 @@ The result in case of collision is undefined:
```ruby
{"a" => 1, a: 2}.symbolize_keys
-# => {a: 2}, in my test, can't rely on this result though
+# => {:a=>2}, in my test, can't rely on this result though
```
This method may be useful for example to easily accept both symbols and strings as options. For instance `ActionController::UrlRewriter` defines
@@ -2836,17 +2836,17 @@ Ruby has built-in support for taking slices out of strings and arrays. Active Su
```ruby
{a: 1, b: 2, c: 3}.slice(:a, :c)
-# => {c: 3, a: 1}
+# => {:c=>3, :a=>1}
{a: 1, b: 2, c: 3}.slice(:b, :X)
-# => {b: 2} # non-existing keys are ignored
+# => {:b=>2} # non-existing keys are ignored
```
If the receiver responds to `convert_key` keys are normalized:
```ruby
{a: 1, b: 2}.with_indifferent_access.slice("a")
-# => {a: 1}
+# => {:a=>1}
```
NOTE. Slicing may come in handy for sanitizing option hashes with a white list of keys.
@@ -2855,8 +2855,8 @@ There's also `slice!` which in addition to perform a slice in place returns what
```ruby
hash = {a: 1, b: 2}
-rest = hash.slice!(:a) # => {b: 2}
-hash # => {a: 1}
+rest = hash.slice!(:a) # => {:b=>2}
+hash # => {:a=>1}
```
NOTE: Defined in `active_support/core_ext/hash/slice.rb`.
@@ -2867,8 +2867,8 @@ The method `extract!` removes and returns the key/value pairs matching the given
```ruby
hash = {a: 1, b: 2}
-rest = hash.extract!(:a) # => {a: 1}
-hash # => {b: 2}
+rest = hash.extract!(:a) # => {:a=>1}
+hash # => {:b=>2}
```
The method `extract!` returns the same subclass of Hash, that the receiver is.
diff --git a/guides/source/active_support_instrumentation.md b/guides/source/active_support_instrumentation.md
index b35691bbcc..1163940f10 100644
--- a/guides/source/active_support_instrumentation.md
+++ b/guides/source/active_support_instrumentation.md
@@ -434,7 +434,7 @@ ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*a
event.name # => "process_action.action_controller"
event.duration # => 10 (in milliseconds)
- event.payload # => { extra: :information }
+ event.payload # => {:extra=>information}
Rails.logger.info "#{event} Received!"
end
@@ -477,7 +477,7 @@ Now you can listen to this event with:
```ruby
ActiveSupport::Notifications.subscribe "my.custom.event" do |name, started, finished, unique_id, data|
- puts data.inspect # { this: :data }
+ puts data.inspect # {:this=>:data}
end
```
diff --git a/guides/source/i18n.md b/guides/source/i18n.md
index e916bda630..9d8287ab7c 100644
--- a/guides/source/i18n.md
+++ b/guides/source/i18n.md
@@ -546,7 +546,7 @@ Also, a key can translate to a (potentially nested) hash of grouped translations
```ruby
I18n.t 'activerecord.errors.messages'
-# => { inclusion: "is not included in the list", exclusion: ... }
+# => {:inclusion=>"is not included in the list", :exclusion=> ... }
```
#### "Lazy" Lookup