Skip to content

Commit 9711510

Browse files
committed
[Deprecate] Resource#attributes is now deprecated
`select` is a preferred way.
1 parent e2789a4 commit 9711510

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/alba/resource.rb

+4
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ def attributes_to_hash(obj, hash)
217217

218218
# This is default behavior for getting attributes for serialization
219219
# Override this method to filter certain attributes
220+
#
221+
# @deprecated in favor of `select`
220222
def attributes
221223
@_attributes
222224
end
@@ -328,6 +330,8 @@ def method_added(method_name) # rubocop:disable Metrics/MethodLength
328330
private(:serializable_hash_for_collection)
329331
alias_method :serializable_hash, :deprecated_serializable_hash
330332
alias_method :to_h, :deprecated_serializable_hash
333+
when :attributes
334+
warn 'Overriding `attributes` is deprecated, use `select` instead.', category: :deprecated, uplevel: 1
331335
when :_setup # noop
332336
else
333337
_resource_methods << method_name.to_sym

test/resource_test.rb

+15
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,19 @@ def collection_converter
157157
def test_deprecated_collection_converter
158158
assert_equal [@foo], DeprecatedConverterCollectionResource.new([@foo]).as_json
159159
end
160+
161+
def test_deprecated_attributes
162+
assert_output('', /Overriding `attributes` is deprecated, use `select` instead./) do
163+
Class.new do
164+
include Alba::Resource
165+
attributes :id
166+
167+
private
168+
169+
def attributes # rubocop:disable Lint/UselessMethodDefinition
170+
super
171+
end
172+
end
173+
end
174+
end
160175
end

0 commit comments

Comments
 (0)