Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relocate DslHelper from root namespace to under AASM namespace #711

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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