Skip to content

Commit

Permalink
upgrade hash syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
teeparham committed May 30, 2013
1 parent b686b73 commit 74ba9dc
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ task :bench do
load 'bench/perf.rb'
end

task :default => :test
task default: :test
2 changes: 1 addition & 1 deletion lib/active_model/array_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def serializable_array
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
Expand Down
26 changes: 13 additions & 13 deletions lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
#
Expand All @@ -46,7 +46,7 @@ class Serializer
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
Expand Down Expand Up @@ -86,7 +86,7 @@ def attributes(*attrs)

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
Expand Down Expand Up @@ -172,20 +172,20 @@ def has_one(*attrs)
#
# 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+.
Expand Down Expand Up @@ -232,7 +232,7 @@ def schema
end
end

{ :attributes => attrs, :associations => associations }
{ attributes: attrs, associations: associations }
end

# The model class associated with this serializer.
Expand All @@ -244,7 +244,7 @@ def model_class
#
# 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
Expand Down Expand Up @@ -323,7 +323,7 @@ def url_options
# 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
Expand Down Expand Up @@ -451,8 +451,8 @@ def instrument(name, payload = {}, &block)

def default_embed_options
{
:embed => _embed,
:include => _root_embed
embed: _embed,
include: _root_embed
}
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/active_model/serializer/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Association #:nodoc:
# 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.
#
Expand Down Expand Up @@ -158,8 +158,8 @@ def serialize_ids

if polymorphic?
{
:type => polymorphic_key,
:id => id
type: polymorphic_key,
id: id
}
else
id
Expand Down
4 changes: 2 additions & 2 deletions lib/active_model_serializers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def active_model_serializer
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
Expand Down
6 changes: 3 additions & 3 deletions lib/generators/serializer/serializer_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 74ba9dc

Please sign in to comment.