From 54ce37b9560293de1cf403c7e64d9a6e49680cce Mon Sep 17 00:00:00 2001 From: Andre Meij Date: Tue, 18 Jun 2013 16:40:14 +0200 Subject: [PATCH] Change to 1.9 Hash syntax in docs --- DESIGN.textile | 8 ++++---- README.md | 34 +++++++++++++++++----------------- cruft.md | 4 ++-- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/DESIGN.textile b/DESIGN.textile index 336d85d9..559982e4 100644 --- a/DESIGN.textile +++ b/DESIGN.textile @@ -358,8 +358,8 @@ Here is an example:
 class UserSerializer < ActiveModel::Serializer
-  has_many :followed_posts, :key => :posts
-  has_one :owned_account, :key => :account
+  has_many :followed_posts, key: :posts
+  has_one :owned_account, key: :account
 end
 
@@ -370,8 +370,8 @@ to set it explicitly:
 class UserSerializer < ActiveModel::Serializer
-  has_many :followed_posts, :key => :posts, :serializer => CustomPostSerializer
-  has_one :owne_account, :key => :account, :serializer => PrivateAccountSerializer
+  has_many :followed_posts, key: :posts, serializer: CustomPostSerializer
+  has_one :owne_account, key: :account, serializer: PrivateAccountSerializer
 end
 
diff --git a/README.md b/README.md index 117fd0d8..00880659 100644 --- a/README.md +++ b/README.md @@ -217,7 +217,7 @@ end ## Getting the old version If you find that your project is already relying on the old rails to_json -change `render :json` to `render :json => @your_object.to_json`. +change `render :json` to `render json: @your_object.to_json`. # Attributes and Associations @@ -293,7 +293,7 @@ type of a computed attribute: ```ruby class PersonSerializer < ActiveModel::Serializer - attributes :first_name, :last_name, {:full_name => :string} + attributes :first_name, :last_name, {full_name: :string} def full_name "#{object.first_name} #{object.last_name}" @@ -309,7 +309,7 @@ class PostSerializer < ActiveModel::Serializer attributes :id, :body # look up :subject on the model, but use +title+ in the JSON - attribute :subject, :key => :title + attribute :subject, key: :title has_many :comments end ``` @@ -318,7 +318,7 @@ If you would like to add meta information to the outputted JSON, use the `:meta` option: ```ruby -render :json => @posts, :serializer => CustomArraySerializer, :meta => {:total => 10} +render json: @posts, serializer: CustomArraySerializer, meta: {total: 10} ``` The above usage of `:meta` will produce the following: @@ -336,7 +336,7 @@ The above usage of `:meta` will produce the following: If you would like to change the meta key name you can use the `:meta_key` option: ```ruby -render :json => @posts, :serializer => CustomArraySerializer, :meta => {:total => 10}, :meta_key => 'meta_object' +render json: @posts, serializer: CustomArraySerializer, meta: {total: 10}, meta_key: 'meta_object' ``` The above usage of `:meta_key` will produce the following: @@ -388,7 +388,7 @@ class PostSerializer < ActiveModel::Serializer # only let the user see comments he created. def comments - object.comments.where(:created_by => current_user) + object.comments.where(created_by: current_user) end end ``` @@ -401,7 +401,7 @@ class PostSerializer < ActiveModel::Serializer attributes :id, :title, :body # look up comments, but use +my_comments+ as the key in JSON - has_many :comments, :key => :my_comments + has_many :comments, key: :my_comments end ``` @@ -439,8 +439,8 @@ end You may also use the `:serializer` option to specify a custom serializer class and the `:polymorphic` option to specify an association that is polymorphic (STI), e.g.: ```ruby - has_many :comments, :serializer => CommentShortSerializer - has_one :reviewer, :polymorphic => true + has_many :comments, serializer: CommentShortSerializer + has_one :reviewer, polymorphic: true ``` Serializers are only concerned with multiplicity, and not ownership. `belongs_to` ActiveRecord associations can be included using `has_one` in your serializer. @@ -528,7 +528,7 @@ You can specify that the data be included like this: ```ruby class PostSerializer < ActiveModel::Serializer - embed :ids, :include => true + embed :ids, include: true attributes :id, :title, :body has_many :comments @@ -563,10 +563,10 @@ used to reference them: ```ruby class PostSerializer < ActiveModel::Serializer - embed :ids, :include => true + embed :ids, include: true attributes :id, :title, :body - has_many :comments, :key => :comment_ids, :root => :comment_objects + has_many :comments, key: :comment_ids, root: :comment_objects end ``` @@ -591,10 +591,10 @@ objects: ```ruby class PostSerializer < ActiveModel::Serializer - embed :ids, :include => true + embed :ids, include: true attributes :id, :title, :body - has_many :comments, :embed_key => :external_id + has_many :comments, embed_key: :external_id end ``` @@ -646,7 +646,7 @@ To be clear, it's not possible, yet, to do something like this: ```ruby class SomeController < ApplicationController - serialization_scope :current_admin, :except => [:index, :show] + serialization_scope :current_admin, except: [:index, :show] end ``` @@ -660,13 +660,13 @@ class CitiesController < ApplicationController def index @cities = City.all - render :json => @cities, :each_serializer => CitySerializer + render json: @cities, each_serializer: CitySerializer end def show @city = City.find(params[:id]) - render :json => @city, :scope => current_admin, :scope_name => :current_admin + render json: @city, scope: current_admin, scope_name: :current_admin end end ``` diff --git a/cruft.md b/cruft.md index 3de9d682..22cbf7d3 100644 --- a/cruft.md +++ b/cruft.md @@ -9,8 +9,8 @@ have a constant with a Hash of events: ```ruby INSTRUMENT = { - :serialize => :"serialize.serializer", - :associations => :"associations.serializer" + serialize: :"serialize.serializer", + associations: :"associations.serializer" } ```