Permalink
Browse files

Working on a Railtie

  • Loading branch information...
1 parent 72c8ba7 commit 629c70d75e59a24d0799c18f0376b11ce9072a3e Ryan Oberholzer committed Apr 8, 2011
Showing with 25 additions and 2 deletions.
  1. +5 −0 lib/stateflow.rb
  2. +5 −2 lib/stateflow/persistence.rb
  3. +11 −0 lib/stateflow/railtie.rb
  4. +4 −0 spec/stateflow_spec.rb
View
@@ -1,4 +1,5 @@
require 'active_support'
+require 'stateflow/railtie' if defined?(Rails)
module Stateflow
extend ActiveSupport::Concern
@@ -15,6 +16,10 @@ def self.persistence=(persistence)
@@persistence = persistence
end
+ def self.active_persistences
+ @@active_persistences ||= []
+ end
+
module ClassMethods
attr_reader :machine
@@ -1,7 +1,10 @@
module Stateflow
module Persistence
- Dir[File.dirname(__FILE__) + '/persistence/*.rb'].each do |file|
- autoload File.basename(file, File.extname(file)).camelize.to_sym, file
+ Dir[File.dirname(__FILE__) + '/persistence/*.rb'].each do |file|
+ name = File.basename(file, File.extname(file))
+
+ Stateflow.active_persistences << name.underscore.to_sym
+ autoload name.camelize.to_sym, file
end
end
end
View
@@ -0,0 +1,11 @@
+module Stateflow
+ class Railtie < Rails::Railtie
+ def default_orm
+ config.app_generators.options[:rails][:orm]
+ end
+
+ initializer "stateflow.set_persistence" do
+ Stateflow.persistence = default_orm if Stateflow.persistence.blank? && Stateflow.active_persistences.include?(default_orm)
+ end
+ end
+end
View
@@ -136,6 +136,10 @@ class Stater
it "should respond to the machine attr accessor" do
Robot.should respond_to(:machine)
end
+
+ it "should return all active persistence layers" do
+ Stateflow.active_persistences.should == [:active_record, :mongo_mapper, :mongoid, :none]
+ end
end
describe "instance methods" do

0 comments on commit 629c70d

Please sign in to comment.