Skip to content

Commit 6494f59

Browse files
author
Jon Evans
committed
reverse the argument order for the root method. It seemed more logical this way.
1 parent 90e0437 commit 6494f59

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

lib/grape/entity.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,19 @@ def self.exposures
8787

8888
# This allows you to set a root element name for your representation.
8989
#
90-
# @param singular [String] the root key to use when representing a single object
91-
# @param plural [String] the root key to use when representing a collection of objects
90+
# @param plural [String] the root key to use when representing
91+
# a collection of objects. If missing or nil, no root key will be used
92+
# when representing collections of objects.
93+
# @param singular [String] the root key to use when representing
94+
# a single object. If missing or nil, no root key will be used when
95+
# representing an individual object.
9296
#
9397
# @example Entity Definition
9498
#
9599
# module API
96100
# module Entities
97101
# class User < Grape::Entity
98-
# root 'user', 'users'
102+
# root 'users', 'user'
99103
# expose :id
100104
# end
101105
# end
@@ -120,9 +124,9 @@ def self.exposures
120124
# end
121125
# end
122126
# end
123-
def self.root(singular, plural=nil)
124-
@root = singular
127+
def self.root(plural, singular=nil)
125128
@collection_root = plural
129+
@root = singular
126130
end
127131

128132
# This convenience method allows you to instantiate one or more entities by

spec/grape/entity_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
describe '.root' do
6363
context 'with singular and plural root keys' do
6464
before(:each) do
65-
subject.root 'thing', 'things'
65+
subject.root 'things', 'thing'
6666
end
6767

6868
context 'with a single object' do
@@ -88,7 +88,7 @@
8888

8989
context 'with singular root key' do
9090
before(:each) do
91-
subject.root 'thing'
91+
subject.root nil, 'thing'
9292
end
9393

9494
context 'with a single object' do
@@ -112,7 +112,7 @@
112112

113113
context 'with plural root key' do
114114
before(:each) do
115-
subject.root nil, 'things'
115+
subject.root 'things'
116116
end
117117

118118
context 'with a single object' do

0 commit comments

Comments
 (0)