Skip to content

Commit 987eae9

Browse files
RogersRogers
authored andcommitted
Small refactor and a bit clean up
1 parent a725043 commit 987eae9

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/zendesk_api/resource.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ def resource_path
3939
def namespace(namespace)
4040
@namespace = namespace
4141
end
42+
43+
def new_from_response(client, response, includes = nil)
44+
new(client).tap do |resource|
45+
resource.handle_response(response)
46+
resource.set_includes(resource, includes, response.body) if includes
47+
resource.attributes.clear_changes
48+
end
49+
end
4250
end
4351

4452
# @return [Hash] The resource's attributes
@@ -123,17 +131,17 @@ def to_s
123131

124132
# Compares resources by class and id. If id is nil, then by object_id
125133
def ==(other)
126-
return true if other.object_id == object_id
134+
return false unless other
127135

128-
if other && !(other.is_a?(Data) || other.is_a?(Integer))
129-
warn "Trying to compare #{other.class} to a Resource from #{caller.first}"
130-
end
136+
return true if other.object_id == object_id
131137

132138
if other.is_a?(Data)
133139
other.id && other.id == id
134140
elsif other.is_a?(Integer)
135141
id == other
136142
else
143+
warn "Trying to compare #{other.class} to a Resource from #{caller.first}"
144+
137145
false
138146
end
139147
end

0 commit comments

Comments
 (0)