lib/rooftop/base.rb in rooftop-0.0.6 vs lib/rooftop/base.rb in rooftop-0.0.7.4
- old
+ new
@@ -17,20 +17,30 @@
base.include Rooftop::FieldAliases
# Queries mixin includes a fixup for there `where()` method
base.include Rooftop::Queries
# Links mixin handles the _links key in a response
base.include Rooftop::ResourceLinks
+
+ # Pagination mixin - uses pagination metadata set in the PaginationMiddleware
+ base.include Rooftop::Pagination
+
# Use the API instance we have configured - in a proc because we can't control load order
base.send(:use_api,->{Rooftop.configuration.connection})
# Turn calls to `content` into a collection of Rooftop::ContentField objects
base.include Rooftop::Content
+ # Add some useful scopes
+ base.include Rooftop::Scopes
+
+ # Coerce the title field from an object to a string
+ base.include Rooftop::Coercions::TitleCoercion
+
# Date and Modified fields are pretty universal in responses from WP, so we can automatically
# coerce these to DateTime.
- base.send(:coerce_field,date: ->(date) {DateTime.parse(date)})
- base.send(:coerce_field,modified: ->(modified) {DateTime.parse(modified)})
+ base.send(:coerce_field,date: ->(date) {DateTime.parse(date.to_s) unless date.nil?})
+ base.send(:coerce_field,modified: ->(modified) {DateTime.parse(modified.to_s) unless modified.nil?})
# Having coerced the fields, we can alias them (order is important - coerce first.)
base.send(:alias_field, date: :created_at)
base.send(:alias_field, modified: :updated_at)
@@ -62,20 +72,18 @@
end
def setup_path!
@api_endpoint ||= collection_path
self.collection_path "#{@api_namespace}/v#{@api_version}/#{@api_endpoint}"
-
end
# Allow calling 'first'
def first
all.first
end
-
-
-
+ def reload!
+ self.class.find(self.id) if self.id
+ end
end
-
end
-end
\ No newline at end of file
+end