lib/real_savvy/document.rb in real_savvy-0.0.7 vs lib/real_savvy/document.rb in real_savvy-0.0.8
- old
+ new
@@ -3,20 +3,10 @@
class RealSavvy::Document
attr_reader :document
- TYPE_TO_RESOURCE = {
- 'properties' => RealSavvy::Resource::Property,
- 'listings' => RealSavvy::Resource::Property,
- 'collections' => RealSavvy::Resource::Collection,
- 'saved_searches' => RealSavvy::Resource::SavedSearch,
- 'users' => RealSavvy::Resource::User,
- }.tap do |lookup|
- lookup.default = RealSavvy::Resource::Base
- end.freeze
-
def initialize(document, status: nil)
@document = document
@status = status
end
@@ -25,11 +15,11 @@
end
alias results data
def result
- data[0]
+ data
end
def included
@included ||= self.class.process_resources(document['included'], self)
end
@@ -53,8 +43,12 @@
def inspect
document.inspect
end
def self.process_resources(resources, document=nil)
- ::RealSavvy.safe_wrap(resources).map { |object| TYPE_TO_RESOURCE[object['type']].new(object, document) }
+ if resources.is_a?(Array)
+ resources.map { |object| RealSavvy::Resource.new(object, document) }
+ elsif resources
+ RealSavvy::Resource.new(resources, document)
+ end
end
end