Module: Stateflow::Persistence

Defined in:
lib/stateflow/persistence.rb,
lib/stateflow/persistence/none.rb,
lib/stateflow/persistence/mongoid.rb,
lib/stateflow/persistence/mongo_mapper.rb,
lib/stateflow/persistence/active_record.rb

Defined Under Namespace

Modules: ActiveRecord, MongoMapper, Mongoid, None

Class Method Summary (collapse)

Class Method Details

+ (Object) active



3
4
5
6
7
8
9
10
11
# File 'lib/stateflow/persistence.rb', line 3

def self.active
  persistences = Array.new
  
  Dir[File.dirname(__FILE__) + '/persistence/*.rb'].each do |file|
    persistences << File.basename(file, File.extname(file)).underscore.to_sym
  end
  
  persistences
end

+ (Object) load!(base)



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/stateflow/persistence.rb', line 13

def self.load!(base)
  begin
    base.send :include, "Stateflow::Persistence::#{Stateflow.persistence.to_s.camelize}".constantize
  rescue NameError
    puts "[Stateflow] The ORM you are using does not have a Persistence layer. Defaulting to ActiveRecord."
    puts "[Stateflow] You can overwrite the persistence with Stateflow.persistence = :new_persistence_layer"

    Stateflow.persistence = :active_record 
    base.send :include, "Stateflow::Persistence::ActiveRecord".constantize
  end
end