From 74ba9dc76c4258e7c0aac84e76a1c72bfb060a61 Mon Sep 17 00:00:00 2001 From: Tee Parham Date: Wed, 29 May 2013 21:59:17 -0600 Subject: [PATCH] upgrade hash syntax --- Gemfile | 2 +- Rakefile | 2 +- lib/active_model/array_serializer.rb | 2 +- lib/active_model/serializer.rb | 26 +++++++++---------- lib/active_model/serializer/associations.rb | 6 ++--- lib/active_model_serializers.rb | 4 +-- .../serializer/serializer_generator.rb | 6 ++--- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Gemfile b/Gemfile index 71303738..79ab2b93 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Rakefile b/Rakefile index 23f17c4a..8c5bd75a 100644 --- a/Rakefile +++ b/Rakefile @@ -15,4 +15,4 @@ task :bench do load 'bench/perf.rb' end -task :default => :test +task default: :test diff --git a/lib/active_model/array_serializer.rb b/lib/active_model/array_serializer.rb index a1b92c4c..e752c812 100644 --- a/lib/active_model/array_serializer.rb +++ b/lib/active_model/array_serializer.rb @@ -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 diff --git a/lib/active_model/serializer.rb b/lib/active_model/serializer.rb index c3768f75..e2a6228b 100644 --- a/lib/active_model/serializer.rb +++ b/lib/active_model/serializer.rb @@ -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 diff --git a/lib/active_model/serializer/associations.rb b/lib/active_model/serializer/associations.rb index 888b94fd..1f2b0b53 100644 --- a/lib/active_model/serializer/associations.rb +++ b/lib/active_model/serializer/associations.rb @@ -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 diff --git a/lib/active_model_serializers.rb b/lib/active_model_serializers.rb index a708585c..c1357c75 100644 --- a/lib/active_model_serializers.rb +++ b/lib/active_model_serializers.rb @@ -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 diff --git a/lib/generators/serializer/serializer_generator.rb b/lib/generators/serializer/serializer_generator.rb index 0da6c873..129da440 100644 --- a/lib/generators/serializer/serializer_generator.rb +++ b/lib/generators/serializer/serializer_generator.rb @@ -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")