previous changes were made to Dsl that built on the options hash that was passed to it.

Except the options hash is actually a
    Thor::CoreExt::HashWithIndifferentAccess

so, i reorganized the internal access and storage to read original data from the passed hash, but stores it into a local hash.

No tests changed since no external behavior changed.  All tests passed.

This fixes the issue when the binary is run and results in a
     can't modify frozen hash (RuntimeError)
This commit is contained in:
Scott Parrish 2011-05-07 12:04:59 -06:00
parent 562c367383
commit 2a834e1228

View File

@ -4,7 +4,8 @@ module Guard
def evaluate_guardfile(options = {}) def evaluate_guardfile(options = {})
options.is_a?(Hash) or raise ArgumentError.new("evaluate_guardfile not passed a hash") options.is_a?(Hash) or raise ArgumentError.new("evaluate_guardfile not passed a hash")
@@options = options @@orig_options = options
@@options = {}
prep_guardfile_contents prep_guardfile_contents
instance_eval_guardfile(guardfile_contents, actual_guardfile(), 1) instance_eval_guardfile(guardfile_contents, actual_guardfile(), 1)
end end
@ -24,6 +25,7 @@ module Guard
def read_guardfile(my_file) def read_guardfile(my_file)
@@options[:actual_guardfile] = my_file @@options[:actual_guardfile] = my_file
@@options[:guardfile] = @@orig_options[:guardfile]
begin begin
@@options[:guardfile_contents] = File.read(my_file) @@options[:guardfile_contents] = File.read(my_file)
rescue rescue
@ -34,10 +36,11 @@ module Guard
def prep_guardfile_contents def prep_guardfile_contents
#todo do we need .rc file interaction? #todo do we need .rc file interaction?
if @@options.has_key?(:guardfile_contents) if @@orig_options.has_key?(:guardfile_contents)
UI.info "Using options[:guardfile_contents] for Guardfile" UI.info "Using options[:guardfile_contents] for Guardfile"
@@options[:actual_guardfile] = 'options[:guardfile_contents]' @@options[:actual_guardfile] = 'options[:guardfile_contents]'
elsif @@options.has_key?(:guardfile) @@options[:guardfile_contents] = @@orig_options[:guardfile_contents]
elsif @@orig_options.has_key?(:guardfile)
UI.info "Using -command Guardfile" UI.info "Using -command Guardfile"
if File.exist?(guardfile_file()) if File.exist?(guardfile_file())
read_guardfile(guardfile_file) read_guardfile(guardfile_file)
@ -55,13 +58,13 @@ module Guard
end end
end end
unless guardfile_contents_usable? unless guardfile_contents_usable?
UI.error "The command file(#{@@options[:guardfile_file]}) seems to be empty." UI.error "The command file(#{@@orig_options[:guardfile_file]}) seems to be empty."
exit 1 exit 1
end end
end end
def guardfile_contents def guardfile_contents
@@options[:guardfile_contents] @@options[:guardfile_contents] || @@orig_options[:guardfile_contents]
end end
def guardfile_file def guardfile_file
@ -86,7 +89,7 @@ module Guard
end end
def group(name, &guard_definition) def group(name, &guard_definition)
guard_definition.call if guard_definition && (@@options[:group].empty? || @@options[:group].include?(name)) guard_definition.call if guard_definition && (@@orig_options[:group].empty? || @@orig_options[:group].include?(name))
end end
def guard(name, options = {}, &watch_definition) def guard(name, options = {}, &watch_definition)