Skip to content

Commit

Permalink
Relocate DslHelper from root namespace to under AASM namespace
Browse files Browse the repository at this point in the history
`DslHelper` is a module for AASM and should not be located in the root
namespace.
  • Loading branch information
yujideveloper authored and Anil Kumar Maurya committed Oct 10, 2020
1 parent 42b66b8 commit ccdb217
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/aasm/core/event.rb
Expand Up @@ -2,7 +2,7 @@

module AASM::Core
class Event
include DslHelper
include AASM::DslHelper

attr_reader :name, :state_machine, :options

Expand Down
2 changes: 1 addition & 1 deletion lib/aasm/core/transition.rb
Expand Up @@ -2,7 +2,7 @@

module AASM::Core
class Transition
include DslHelper
include AASM::DslHelper

attr_reader :from, :to, :event, :opts, :failures
alias_method :options, :opts
Expand Down
46 changes: 24 additions & 22 deletions lib/aasm/dsl_helper.rb
@@ -1,30 +1,32 @@
module DslHelper
module AASM
module DslHelper

class Proxy
attr_accessor :options
class Proxy
attr_accessor :options

def initialize(options, valid_keys, source)
@valid_keys = valid_keys
@source = source
def initialize(options, valid_keys, source)
@valid_keys = valid_keys
@source = source

@options = options
end
@options = options
end

def method_missing(name, *args, &block)
if @valid_keys.include?(name)
options[name] = Array(options[name])
options[name] << block if block
options[name] += Array(args)
else
@source.send name, *args, &block
def method_missing(name, *args, &block)
if @valid_keys.include?(name)
options[name] = Array(options[name])
options[name] << block if block
options[name] += Array(args)
else
@source.send name, *args, &block
end
end
end
end

def add_options_from_dsl(options, valid_keys, &block)
proxy = Proxy.new(options, valid_keys, self)
proxy.instance_eval(&block)
proxy.options
end
def add_options_from_dsl(options, valid_keys, &block)
proxy = Proxy.new(options, valid_keys, self)
proxy.instance_eval(&block)
proxy.options
end

end
end
end

0 comments on commit ccdb217

Please sign in to comment.