lib/bond/missions/object_mission.rb in bond-0.1.1 vs lib/bond/missions/object_mission.rb in bond-0.1.3
- old
+ new
@@ -5,43 +5,41 @@
#:stopdoc:
attr_reader :object_condition
def initialize(options={})
@object_condition = options.delete(:object)
- @object_condition = /^#{Regexp.quote(@object_condition.to_s)}$/ unless @object_condition.is_a?(Regexp)
- options[:on] = /^((\.?[^.]+)+)\.([^.]*)$/
+ @object_condition = /^#{Regexp.escape(@object_condition.to_s)}$/ unless @object_condition.is_a?(Regexp)
+ options[:on] ||= /(\S+|[^.]+)\.([^.\s]*)$/
@eval_binding = options[:eval_binding]
super
end
def handle_valid_match(input)
- match = super
- if match && eval_object(match) && (match = @evaled_object.class.ancestors.any? {|e| e.to_s =~ @object_condition })
- @list_prefix = @matched[1] + "."
- @input = @matched[3]
- @input.instance_variable_set("@object", @evaled_object)
- @input.instance_eval("def self.object; @object ; end")
- @action ||= lambda {|e| default_action(e.object) }
- else
- match = false
+ if (match = super)
+ begin
+ eval_object(match)
+ rescue Exception
+ return false
+ end
+ if (match = @evaled_object.class.ancestors.any? {|e| e.to_s =~ @object_condition })
+ @completion_prefix = @matched[1] + "."
+ @input = @matched[2]
+ @input.instance_variable_set("@object", @evaled_object)
+ @input.instance_eval("def self.object; @object ; end")
+ @action ||= lambda {|e| default_action(e.object) }
+ else
+ match = false
+ end
end
match
end
def eval_object(match)
@matched = match
- @evaled_object = begin eval("#{match[1]}", eval_binding); rescue Exception; nil end
+ @evaled_object = self.class.current_eval(match[1], @eval_binding)
end
def default_action(obj)
obj.methods.map {|e| e.to_s} - OPERATORS
- end
-
- def eval_binding
- @eval_binding ||= default_eval_binding
- end
-
- def default_eval_binding
- Object.const_defined?(:IRB) ? IRB.CurrentContext.workspace.binding : ::TOPLEVEL_BINDING
end
#:startdoc:
end
\ No newline at end of file