Module: PowerAssert
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Classes:
| |
Defined in: | lib/power_assert.rb, lib/power_assert/configuration.rb, lib/power_assert/context.rb, lib/power_assert/inspector.rb, lib/power_assert/parser.rb, lib/power_assert/version.rb |
Constant Summary
-
CLEAR_CACHE_ISEQ =
private
# File 'lib/power_assert.rb', line 86RubyVM::InstructionSequence.compile('using PowerAssert.const_get(:Empty)')
-
IGNORED_LIB_DIRS =
private
For backward compatibility
INTERNAL_LIB_DIRS
-
INTERNAL_LIB_DIRS =
private
# File 'lib/power_assert.rb', line 26{PowerAssert => POWER_ASSERT_LIB_DIR}
-
POWER_ASSERT_LIB_DIR =
private
# File 'lib/power_assert.rb', line 25File.dirname(caller_locations(1, 1).first.path)
-
SUPPORT_ALIAS_METHOD =
private
# File 'lib/power_assert/configuration.rb', line 12TracePoint.public_method_defined?(:callee_id)
-
VERSION =
# File 'lib/power_assert/version.rb', line 2"1.1.3"
Class Attribute Summary
- .app_context? ⇒ Boolean readonly
Class Method Summary
- .app_caller_locations
- .configuration
- .configure {|configuration| ... }
- .start(assertion_proc_or_source, assertion_method: nil, source_binding: TOPLEVEL_BINDING) {|BlockContext.new(assertion_proc_or_source, assertion_method, source_binding)| ... }
- .trace(frame)
- .clear_global_method_cache private
- .internal_file?(file) ⇒ Boolean private
- .lib_dir(obj, mid, depth) private
- .setup_internal_lib_dir(lib, mid, depth, lib_obj = lib) private
Class Attribute Details
.app_context? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/power_assert.rb', line 59
def app_context? top_frame = caller_locations.drop_while {|i| i.path.start_with?(POWER_ASSERT_LIB_DIR) }.first top_frame and ! internal_file?(top_frame.path) end
Class Method Details
.app_caller_locations
[ GitHub ]# File 'lib/power_assert.rb', line 55
def app_caller_locations caller_locations.drop_while {|i| internal_file?(i.path) }.take_while {|i| ! internal_file?(i.path) } end
.clear_global_method_cache (private)
[ GitHub ]# File 'lib/power_assert.rb', line 89
def clear_global_method_cache CLEAR_CACHE_ISEQ.eval end
.configuration
[ GitHub ]# File 'lib/power_assert/configuration.rb', line 3
def configuration @configuration ||= Configuration[false, false, true, false, false] end
.configure {|configuration| ... }
# File 'lib/power_assert/configuration.rb', line 7
def configure yield configuration end
.internal_file?(file) ⇒ Boolean
(private)
# File 'lib/power_assert.rb', line 66
def internal_file?(file) setup_internal_lib_dir(Byebug, :attach, 2) if defined?(Byebug) setup_internal_lib_dir(PryByebug, :start_with_pry_byebug, 2, Pry) if defined?(PryByebug) INTERNAL_LIB_DIRS.find do |_, dir| file.start_with?(dir) end end
.lib_dir(obj, mid, depth) (private)
[ GitHub ]# File 'lib/power_assert.rb', line 81
def lib_dir(obj, mid, depth) File. ('../' * depth, obj.method(mid).source_location[0]) end
.setup_internal_lib_dir(lib, mid, depth, lib_obj = lib) (private)
[ GitHub ]# File 'lib/power_assert.rb', line 74
def setup_internal_lib_dir(lib, mid, depth, lib_obj = lib) unless INTERNAL_LIB_DIRS.key?(lib) INTERNAL_LIB_DIRS[lib] = lib_dir(lib_obj, mid, depth) end rescue NameError end
.start(assertion_proc_or_source, assertion_method: nil, source_binding: TOPLEVEL_BINDING) {|BlockContext.new(assertion_proc_or_source, assertion_method, source_binding)| ... }
# File 'lib/power_assert.rb', line 37
def start(assertion_proc_or_source, assertion_method: nil, source_binding: TOPLEVEL_BINDING) if respond_to?(:clear_global_method_cache, true) clear_global_method_cache end yield BlockContext.new(assertion_proc_or_source, assertion_method, source_binding) end
.trace(frame)
[ GitHub ]# File 'lib/power_assert.rb', line 44
def trace(frame) begin raise 'Byebug is not started yet' unless Byebug.started? rescue NameError raise "PowerAssert.#{__method__} requires Byebug" end ctx = TraceContext.new(frame._binding) ctx.enable ctx end