module AASM::Persistence::ActiveFedoraPersistence

Public Class Methods

included(base) click to toggle source
# File lib/aasm-active_fedora/active_fedora_persistence.rb, line 12
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