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
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/statelogic/activerecord.rb', line 67 def statelogic( = {}, &block) = DEFAULT_OPTIONS.merge() attr = [:attribute] = [:attribute].to_sym [:states], [:initial] = [], Array([:initial]) ConfigHelper.new(self, ).instance_eval(&block) initial = [:initial] || [:states] validates_inclusion_of attr, :in => initial, :on => :create unless initial.blank? const = attr.to_s.pluralize.upcase const_set(const, [:states].freeze.each(&:freeze)) unless const_defined?(const) end |