Class: ComicVine::Resource
- Inherits:
-
Object
- Object
- ComicVine::Resource
- Defined in:
- lib/comicvine/mongo.rb
Direct Known Subclasses
Character, Concept, Episode, Issue, Location, Movie, Object, Origin, Person, Power, Promo, Publisher, Series, StoryArc, Team, Volume
Defined Under Namespace
Classes: Character, Concept, Episode, Issue, Location, Movie, Object, Origin, Person, Power, Promo, Publisher, Series, StoryArc, Team, Volume
Class Method Summary collapse
-
.create_resource(attr) ⇒ Resource::Character, ...
Takes hash and returns a Mongoid::Document subclass of Resource based on identified type.
Class Method Details
.create_resource(attr) ⇒ Resource::Character, ...
Takes hash and returns a Mongoid::Document subclass of ComicVine::Resource based on identified type
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/comicvine/mongo.rb', line 111 def self.create_resource(attr) type = ComicVine::Resource::identify_and_update_response(attr) if type # if its a review the api doesnt actually exist, so return the hash return attr if type.equal? :review c = Object.class_eval('ComicVine::Resource::' + type.to_s.camelcase) if c.where(id: attr['id']).exists? c.find(attr['id']) else c.new attr end else raise ScriptError, 'Unknown type for api_detail_url: ' + attr['api_detail_url'] end end |