Commit 7b04cd93 by Ivan Lan

feat: 更改 DslHelper Proxy 的命名空间

parent 7d590efa
module Shotengai module Shotengai
module AASM_DLC module AASM_DLC
require 'aasm' require "aasm"
def self.included(base) def self.included(base)
add_event_callbacks add_event_callbacks
base.include AASM base.include AASM
...@@ -8,49 +8,47 @@ module Shotengai ...@@ -8,49 +8,47 @@ module Shotengai
end end
def self.add_event_callbacks def self.add_event_callbacks
# DslHelper::Proxy.class_eval do AASM::DslHelper::Proxy.class_eval do
# def initialize(options, valid_keys, source)
# def initialize(options, valid_keys, source) # original
# # original @valid_keys = valid_keys
# @valid_keys = valid_keys @source = source # event or transition
# @source = source # event or transition @options = options
# @options = options # dlc
# # dlc expend_options if AASM::Core::Event === source
# expend_options if AASM::Core::Event === source end
# end
# def expend_options
# def expend_options preset_methods = []
# preset_methods = [] # add callbacks for valid_keys to definite event
# # add callbacks for valid_keys to definite event # vaild_keys in aasm 4.12.2
# # vaild_keys in aasm 4.12.2 # [ :after, :after_commit, :after_transaction, :before,
# # [ :after, :after_commit, :after_transaction, :before, # :before_transaction, :ensure, :error, :before_success, :success ]
# # :before_transaction, :ensure, :error, :before_success, :success ] # e.g.
# # e.g. # event :pay ---> :after_pay, after_commit_pay ...
# # event :pay ---> :after_pay, after_commit_pay ... #
# # # NOTE: QUESTION: add key :error would cancel all exception ?
# # NOTE: QUESTION: add key :error would cancel all exception ? (@valid_keys - [:error, :ensure]).each do |callback|
# (@valid_keys - [:error, :ensure]).each do |callback| preset_methods << "#{callback}_#{@source.name}"
# preset_methods << "#{callback}_#{@source.name}" @options[callback] = Array(@options[callback]) << "#{callback}_#{@source.name}"
# @options[callback] = Array(@options[callback]) << "#{callback}_#{@source.name}" end
# end
# # ignore the method missing if it was in preset_methods
# # ignore the method missing if it was in preset_methods @source.class_eval("
# @source.class_eval(" def invoke_callbacks(code, record, args)
# def invoke_callbacks(code, record, args) super(code, record, args)
# super(code, record, args) rescue NoMethodError
# rescue NoMethodError code.to_s.in?(#{preset_methods}) ? true : raise
# code.to_s.in?(#{preset_methods}) ? true : raise end
# end ")
# ") end
# end end
#
# end
end end
# module ClassMethods # module ClassMethods
# def aasm *arg, &block # def aasm *arg, &block
# super(*arg, &block) # super(*arg, &block)
# # @aasm[:default].instance_eval(&@aasm_patch) if @aasm_patch # new DSL # # @aasm[:default].instance_eval(&@aasm_patch) if @aasm_patch # new DSL
# # @aasm_patch = nil # # @aasm_patch = nil
# # p '-------' # # p '-------'
# # sleep 1 # # sleep 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment