Last active
December 16, 2015 12:49
-
-
Save gmcinnes/5437134 to your computer and use it in GitHub Desktop.
Simplify?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Model | |
module Core | |
include ExtensionLadder | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ExtensionLadder #yuk yuk | |
include Mongoid::Document | |
include Mongoid::Pagination | |
# useful extras, see: http://mongoid.org/en/mongoid/docs/extras.html | |
include Mongoid::Paranoia # soft deletes | |
index { deleted_at: 1 } | |
include Mongoid::Timestamps | |
index { created_at: 1 } | |
index { updated_at: 1 } | |
include Mongoid::Tree | |
include Mongoid::Tree::Ordering | |
include Mongoid::History::Trackable | |
# ElasticSearch integration | |
# don't index group since they are only a structural construct | |
unless 'Group' == name | |
include, Tire::Model::Search | |
include, Tire::Model::Callbacks | |
# index name is dynamically set to the mongoid database name | |
index_name, Proc.new {Search.index_name} | |
end | |
# Generate MD5 fingerprint for this document | |
field :md5, type: Moped::BSON::Binary | |
index { md5: 1 } | |
set_callback :save, :before, :generate_md5 | |
# Make :headings a readable class variable | |
class_eval %(class << self; attr_reader :headings end) | |
# Create rdf_types field and accessor | |
class_eval %(class << self; attr_reader :rdf_types end) | |
field :rdf_types | |
# Include default embedded vocabularies | |
embeds_one :dbpedia, class_name: 'DBpedia', cascade_callbacks: true, autobuild: true unless 'Group' == base.name | |
embeds_one :rdfs, class_name: 'RDFS', cascade_callbacks: true, autobuild: true | |
# add useful class methods | |
extend ClassMethods | |
# NB: This has to be at the end to overload Mongoid | |
extend FOCB | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment