Module: AASM::Persistence::ActiveFedoraPersistence

Defined in:
lib/aasm-active_fedora/active_fedora_persistence.rb

Defined Under Namespace

Modules: InstanceMethods Classes: AASMTerms

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



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
# File 'lib/aasm-active_fedora/active_fedora_persistence.rb', line 9

def self.included(base)
  base.send(:include, AASM::Persistence::Base)
  base.send(:include, AASM::Persistence::ActiveFedoraPersistence::InstanceMethods)

  attribute_name = base.send(:aasm, :default).attribute_name.to_sym
  # we need to add a backing-store property whose name is given to us by AASM, BUT AASM wants to own the
  # setter for it, and defines it before we get a chance to. Which is great EXCEPT that ActiveTriples
  # freaks out if that setter is already defined when you call property. Therefore we temporarily
  # hide the setter, define the property, and then put the setter back in place
  base.send(:alias_method, :temp_af_moveaside, "#{attribute_name}=")
  base.send(:remove_method, "#{attribute_name}=")

  base.send(:property, attribute_name, predicate: AASM::Persistence::ActiveFedoraPersistence::AASMTerms::aasmstate, multiple: false) do |index|
    index.as :stored_searchable
  end

  base.send(:alias_method, "#{attribute_name}=", :temp_af_moveaside)
  base.send(:remove_method, :temp_af_moveaside)

  base.after_initialize :aasm_ensure_initial_state

  # add the property to SolrDocuments as well
  Sufia::SolrDocumentBehavior.module_eval do
    define_method attribute_name do
      self[Solrizer.solr_name(attribute_name)]
    end
  end
end