Skip to content

Commit

Permalink
introduces the concept of allowed configuration options rather than c…
Browse files Browse the repository at this point in the history
…hecking the options hash instance var
  • Loading branch information
markrebec committed May 20, 2015
1 parent ceaca94 commit acb161d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/transactor/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Transactor
class Configuration

def configure(argh={}, &block)
@options ||= {}
save_state! do
configure_with_args argh
configure_with_block &block
Expand All @@ -25,6 +26,8 @@ def configure_with_block(&block)
end

def configure_option(key, val)
raise ArgumentError, "#{key} is not an allowed configuration option" unless @allowed.include?(key)

save_state! do
@changed[key] = [@options[key], val]
@options[key] = val
Expand Down Expand Up @@ -74,9 +77,9 @@ def save_state?
def method_missing(meth, *args, &block)
if meth.to_s.match(/=\Z/)
opt = meth.to_s.gsub(/=/,'').to_sym
return configure_option(opt, args.first) if @options.key?(opt)
return configure_option(opt, args.first) if @allowed.include?(opt)
else
return @options[meth] if @options.key?(meth)
return @options[meth] if @allowed.include?(meth)
end

super
Expand All @@ -85,9 +88,10 @@ def method_missing(meth, *args, &block)
protected

def initialize(*args, &block)
@options = {}
options = args.extract_options!
@allowed = options.symbolize_keys.keys
enable_state_saves!
configure args.extract_options!, &block
configure options, &block
end
end
end

0 comments on commit acb161d

Please sign in to comment.