upgrade hash syntax

This commit is contained in:
Tee Parham 2013-05-29 21:59:17 -06:00
parent b686b73edf
commit 74ba9dc76c
7 changed files with 24 additions and 24 deletions

View File

@ -3,4 +3,4 @@ source 'https://rubygems.org'
# Specify gem dependencies in active_model_serializers.gemspec
gemspec
gem "coveralls", :require => false
gem "coveralls", require: false

View File

@ -15,4 +15,4 @@ task :bench do
load 'bench/perf.rb'
end
task :default => :test
task default: :test

View File

@ -52,7 +52,7 @@ module ActiveModel
end
serializer ||= DefaultSerializer
serializable = serializer.new(item, options.merge(:root => nil))
serializable = serializer.new(item, options.merge(root: nil))
if serializable.respond_to?(:serializable_hash)
serializable.serializable_hash

View File

@ -13,7 +13,7 @@ module ActiveModel
# it expects two objects as arguments, a resource and options. For example,
# one may do in a controller:
#
# PostSerializer.new(@post, :scope => current_user).to_json
# PostSerializer.new(@post, scope: current_user).to_json
#
# The object to be serialized is the +@post+ and the current user is passed
# in for authorization purposes.
@ -30,7 +30,7 @@ module ActiveModel
#
# def attributes
# hash = super
# hash.merge!(:email => post.email) if author?
# hash.merge!(email: post.email) if author?
# hash
# end
#
@ -46,7 +46,7 @@ module ActiveModel
include ActiveModel::Serializer::Caching
INCLUDE_METHODS = {}
INSTRUMENT = { :serialize => :"serialize.serializer", :associations => :"associations.serializer" }
INSTRUMENT = { serialize: :"serialize.serializer", associations: :"associations.serializer" }
class IncludeError < StandardError
attr_reader :source, :association
@ -86,7 +86,7 @@ module ActiveModel
attrs.each do |attr|
if Hash === attr
attr.each {|attr_real, key| attribute attr_real, :key => key }
attr.each {|attr_real, key| attribute(attr_real, key: key) }
else
attribute attr
end
@ -172,20 +172,20 @@ module ActiveModel
#
# The +attributes+ hash looks like this:
#
# { :name => :string, :age => :integer }
# { name: :string, age: :integer }
#
# The +associations+ hash looks like this:
# { :posts => { :has_many => :posts } }
# { posts: { has_many: :posts } }
#
# If :key is used:
#
# class PostsSerializer < ActiveModel::Serializer
# has_many :posts, :key => :my_posts
# has_many :posts, key: :my_posts
# end
#
# the hash looks like this:
#
# { :my_posts => { :has_many => :posts }
# { my_posts: { has_many: :posts }
#
# This information is extracted from the serializer's model class,
# which is provided by +SerializerClass.model_class+.
@ -232,7 +232,7 @@ module ActiveModel
end
end
{ :attributes => attrs, :associations => associations }
{ attributes: attrs, associations: associations }
end
# The model class associated with this serializer.
@ -244,7 +244,7 @@ module ActiveModel
#
# embed :objects # Embed associations as full objects
# embed :ids # Embed only the association ids
# embed :ids, :include => true # Embed the association ids and include objects in the root
# embed :ids, include: true # Embed the association ids and include objects in the root
#
def embed(type, options={})
self._embed = type
@ -323,7 +323,7 @@ module ActiveModel
# Returns a json representation of the serializable
# object including the root.
def as_json(args={})
super(:root => args.fetch(:root, options.fetch(:root, root_name)))
super(root: args.fetch(:root, options.fetch(:root, root_name)))
end
def serialize_object
@ -451,8 +451,8 @@ module ActiveModel
def default_embed_options
{
:embed => _embed,
:include => _root_embed
embed: _embed,
include: _root_embed
}
end
end

View File

@ -12,7 +12,7 @@ module ActiveModel
# embed: Define how associations should be embedded.
# - :objects # Embed associations as full objects.
# - :ids # Embed only the association ids.
# - :ids, :include => true # Embed the association ids and include objects in the root.
# - :ids, include: true # Embed the association ids and include objects in the root.
#
# include: Used in conjunction with embed :ids. Includes the objects in the root.
#
@ -158,8 +158,8 @@ module ActiveModel
if polymorphic?
{
:type => polymorphic_key,
:id => id
type: polymorphic_key,
id: id
}
else
id

View File

@ -74,8 +74,8 @@ Array.send(:include, ActiveModel::ArraySerializerSupport)
Set.send(:include, ActiveModel::ArraySerializerSupport)
{
:active_record => 'ActiveRecord::Relation',
:mongoid => 'Mongoid::Criteria'
active_record: 'ActiveRecord::Relation',
mongoid: 'Mongoid::Criteria'
}.each do |orm, rel_class|
ActiveSupport.on_load(orm) do
include ActiveModel::SerializerSupport

View File

@ -2,11 +2,11 @@ module Rails
module Generators
class SerializerGenerator < NamedBase
source_root File.expand_path("../templates", __FILE__)
check_class_collision :suffix => "Serializer"
check_class_collision suffix: "Serializer"
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
argument :attributes, type: :array, default: [], banner: "field:type field:type"
class_option :parent, :type => :string, :desc => "The parent class for the generated serializer"
class_option :parent, type: :string, desc: "The parent class for the generated serializer"
def create_serializer_file
template 'serializer.rb', File.join('app/serializers', class_path, "#{file_name}_serializer.rb")