Module: ArDocStore::EmbeddableModel

Defined in:
lib/ar_doc_store/embeddable_model.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



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
# File 'lib/ar_doc_store/embeddable_model.rb', line 7

def self.included(mod)
  mod.send :include, ActiveModel::Model
  mod.send :include, ActiveModel::Attributes
  mod.send :include, ActiveModel::AttributeMethods
  mod.send :include, ActiveModel::Dirty
  mod.send :include, ActiveModel::Serialization
  mod.send :include, ArDocStore::Storage
  mod.send :include, ArDocStore::Embedding
  mod.send :include, ActiveSupport::Callbacks
  mod.send :include, InstanceMethods
  mod.send :extend,  ClassMethods

  mod.class_eval do
    define_callbacks :persist
    attr_accessor :_destroy
    attr_accessor :parent
    attr_accessor :embedded_as

    # class_attribute :json_attributes
    # self.json_attributes = HashWithIndifferentAccess.new

    json_attribute :id, :string #, default: -> { SecureRandom.uuid }

    set_callback :persist, :before, :ensure_id
    set_callback :persist, :after, :mark_embeds_as_persisted
  end
end