Module: Rooftop::Base
- Included in:
- MediaItem, Menu, Taxonomy, TaxonomyTerm
- Defined in:
- lib/rooftop/base.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rooftop/base.rb', line 3 def self.included(base) base.extend ClassMethods base.include Her::Model # Paths to get to the API base.api_namespace = Rooftop::DEFAULT_API_NAMESPACE base.api_version = Rooftop::DEFAULT_API_VERSION base.setup_path! # Coercions allow you to pass a block to do something with a returned field base.include Rooftop::Coercions # Aliases allow you to specify a field (or fields) to alias 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 # 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 # 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)}) # 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) # Set up the hooks identified in other mixins. This method is defined in Rooftop::HookCalls base.send(:"setup_hooks!") end |