Module: Workflow::Join::ActiveRecord
- Includes:
- PendingCallbacks, PendingTransitions
- Defined in:
- lib/workflow/join/active_record.rb,
lib/workflow/join/active_record/pending_callbacks.rb,
lib/workflow/join/active_record/pending_transitions.rb
Defined Under Namespace
Modules: PendingCallbacks, PendingTransitions
Constant Summary collapse
- ENSURE_COLUMNS =
lambda do |model, *columns| columns.reduce(true) do |memo, column| next memo if model.column_names.include?(column.to_s) ::ActiveRecord::Base.connection.execute( "ALTER TABLE #{model.table_name} ADD #{column} VARCHAR(255)" ) false end end
Class Method Summary collapse
Methods included from PendingCallbacks
#pending_callback!, #pending_callbacks, #pending_callbacks!, #pending_callbacks?
Methods included from PendingTransitions
#pending_transition!, #pending_transitions, #pending_transitions!, #pending_transitions?, #try_pending_transitions!
Class Method Details
.included(base) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/workflow/join/active_record.rb', line 21 def self.included(base) base.singleton_class.send :define_method, :prepended do |model| fail LoadError, "This module might be included in ActiveRecord::Base instances only (#{base} given.)" \ unless model < ::ActiveRecord::Base # unless ENSURE_COLUMNS.call(model, :workflow_pending_transitions, :workflow_pending_callbacks) # fail LoadError, <<-MSG # ======================================================================================= # This is an intended fail, next time the class is requested, it’ll be loaded properly! # To avoid this one should explicitly specify columns: # — workflow_pending_transitions, # — workflow_pending_callbacks # in all models, that are willing to use joined workflows. # ======================================================================================= # MSG # end end end |