Module: Statelogic::ActiveRecord::ClassMethods
- Defined in:
- lib/statelogic/activerecord.rb
Defined Under Namespace
Classes: ConfigHelper, StateScopeHelper
Constant Summary collapse
- DEFAULT_OPTIONS =
{:attribute => :state}.freeze
Instance Method Summary collapse
Instance Method Details
#statelogic(options = {}, &block) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/statelogic/activerecord.rb', line 101 def statelogic( = {}, &block) = DEFAULT_OPTIONS.merge() attr = [:attribute] = [:attribute].to_sym [:states], [:initial] = [], Array([:initial]) ConfigHelper.new(self, ).instance_eval(&block) initial = [[:initial], [:states]].find(&:present?) validates_inclusion_of attr, :in => initial, :on => :create if initial const = attr.to_s.pluralize.upcase const_set(const, [:states].freeze.each(&:freeze)) unless const_defined?(const) end |