Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
little persistence refactoring to improve readability
- Loading branch information
Showing
2 changed files
with
23 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
module AASM | ||
module Persistence | ||
# Checks to see this class or any of it's superclasses inherit from | ||
# ActiveRecord::Base and if so includes ActiveRecordPersistence | ||
def self.set_persistence(base) | ||
# Use a fancier auto-loading thingy, perhaps. When there are more persistence engines. | ||
hierarchy = base.ancestors.map {|klass| klass.to_s} | ||
class << self | ||
|
||
require File.join(File.dirname(__FILE__), 'persistence', 'base') | ||
require File.join(File.dirname(__FILE__), 'persistence', 'read_state') | ||
if hierarchy.include?("ActiveRecord::Base") | ||
require File.join(File.dirname(__FILE__), 'persistence', 'active_record_persistence') | ||
base.send(:include, AASM::Persistence::ActiveRecordPersistence) | ||
elsif hierarchy.include?("Mongoid::Document") | ||
require File.join(File.dirname(__FILE__), 'persistence', 'mongoid_persistence') | ||
base.send(:include, AASM::Persistence::MongoidPersistence) | ||
def load_persistence(base) | ||
# Use a fancier auto-loading thingy, perhaps. When there are more persistence engines. | ||
hierarchy = base.ancestors.map {|klass| klass.to_s} | ||
|
||
if hierarchy.include?("ActiveRecord::Base") | ||
require_files_for('active_record_persistence') | ||
base.send(:include, AASM::Persistence::ActiveRecordPersistence) | ||
elsif hierarchy.include?("Mongoid::Document") | ||
require_files_for('mongoid_persistence') | ||
base.send(:include, AASM::Persistence::MongoidPersistence) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def require_files_for(persistence) | ||
require File.join(File.dirname(__FILE__), 'persistence', 'base') | ||
require File.join(File.dirname(__FILE__), 'persistence', 'read_state') | ||
require File.join(File.dirname(__FILE__), 'persistence', persistence) | ||
end | ||
|
||
end # class << self | ||
end | ||
end # AASM |