Class: Consyncful::Base

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Attributes::Dynamic, Mongoid::Document
Defined in:
lib/consyncful/base.rb

Overview

Provides common functionality of Mongoid models created from contentful entries

Class Method Summary collapse

Class Method Details

.contentful_model_name(name) ⇒ Object



16
17
18
19
20
# File 'lib/consyncful/base.rb', line 16

def self.contentful_model_name(name)
  self.model_map ||= {}

  self.model_map[name] = self
end

.references_many(name) ⇒ Object

rubocop:disable Lint/NestedMethodDefinition



23
24
25
26
27
28
29
30
31
# File 'lib/consyncful/base.rb', line 23

def self.references_many(name)
  has_and_belongs_to_many name.to_sym, class_name: 'Consyncful::Base', inverse_of: nil do
    def in_order
      _target.to_a.sort_by do |reference|
        _base[foreign_key].index(reference.id)
      end
    end
  end
end

.references_one(name) ⇒ Object

rubocop:enable Lint/NestedMethodDefinition



34
35
36
# File 'lib/consyncful/base.rb', line 34

def self.references_one(name)
  belongs_to name.to_sym, optional: true, class_name: 'Consyncful::Base'
end