diff --git a/lib/statesman.rb b/lib/statesman.rb index 336d7e87..b11d6984 100644 --- a/lib/statesman.rb +++ b/lib/statesman.rb @@ -20,12 +20,12 @@ module Adapters # Example: # Statesman.configure do # storage_adapter Statesman::ActiveRecordAdapter + # enable_mysql_gaplock_protection # end # def self.configure(&block) - config = Config.new(block) + @config = Config.new(block) @storage_adapter = config.adapter_class - @mysql_gaplock_protection = config.mysql_gaplock_protection end def self.storage_adapter @@ -33,6 +33,12 @@ def self.storage_adapter end def self.mysql_gaplock_protection? - @mysql_gaplock_protection + return @mysql_gaplock_protection unless @mysql_gaplock_protection.nil? + + @mysql_gaplock_protection = config.mysql_gaplock_protection? + end + + def self.config + @config ||= Config.new end end diff --git a/lib/statesman/config.rb b/lib/statesman/config.rb index 58aa1600..c18bcf1c 100644 --- a/lib/statesman/config.rb +++ b/lib/statesman/config.rb @@ -5,18 +5,23 @@ module Statesman class Config - attr_reader :adapter_class, :mysql_gaplock_protection + attr_reader :adapter_class def initialize(block = nil) instance_eval(&block) unless block.nil? end def storage_adapter(adapter_class) + @adapter_class = adapter_class + end + + def mysql_gaplock_protection? + return @mysql_gaplock_protection unless @mysql_gaplock_protection.nil? + # If our adapter class suggests we're using mysql, enable gaplock protection by # default. enable_mysql_gaplock_protection if mysql_adapter?(adapter_class) - - @adapter_class = adapter_class + @mysql_gaplock_protection end def enable_mysql_gaplock_protection