Class: SCNR::Introspector::Scope
- Inherits:
-
Object
- Object
- SCNR::Introspector::Scope
- Defined in:
- lib/scnr/introspector/scope.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#path_end_with ⇒ String?
Include trace points whose file path ends with this string.
-
#path_exclude_patterns ⇒ Array<Regexp>
Exclude trace points whose file path matches this pattern.
-
#path_include_patterns ⇒ Array<Regexp>
Include trace points whose file path matches this pattern.
-
#path_start_with ⇒ String?
Include trace points whose file path starts with this string.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#empty? ⇒ Bool
‘true` if scope has no configuration, `false` otherwise.
- #hash ⇒ Object
-
#in?(path) ⇒ Bool
‘true` if `path` is `#in?` scope, `false` otherwise.
-
#initialize(options = {}) ⇒ Scope
constructor
A new instance of Scope.
-
#out?(path) ⇒ Bool
‘true` if `path` is not `#in?` scope, `false` otherwise.
Constructor Details
#initialize(options = {}) ⇒ Scope
Returns a new instance of Scope.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/scnr/introspector/scope.rb', line 31 def initialize( = {} ) .each do |k, v| begin send( "#{k}=", v ) rescue NoMethodError fail "Unknown option: #{k}", Error::UnknownOption end end @path_include_patterns ||= [] @path_exclude_patterns ||= [] end |
Instance Attribute Details
#path_end_with ⇒ String?
Returns Include trace points whose file path ends with this string.
19 20 21 |
# File 'lib/scnr/introspector/scope.rb', line 19 def path_end_with @path_end_with end |
#path_exclude_patterns ⇒ Array<Regexp>
Returns Exclude trace points whose file path matches this pattern.
27 28 29 |
# File 'lib/scnr/introspector/scope.rb', line 27 def path_exclude_patterns @path_exclude_patterns end |
#path_include_patterns ⇒ Array<Regexp>
Returns Include trace points whose file path matches this pattern.
23 24 25 |
# File 'lib/scnr/introspector/scope.rb', line 23 def path_include_patterns @path_include_patterns end |
#path_start_with ⇒ String?
Returns Include trace points whose file path starts with this string.
15 16 17 |
# File 'lib/scnr/introspector/scope.rb', line 15 def path_start_with @path_start_with end |
Instance Method Details
#==(other) ⇒ Object
95 96 97 |
# File 'lib/scnr/introspector/scope.rb', line 95 def ==( other ) hash == other.hash end |
#empty? ⇒ Bool
Returns ‘true` if scope has no configuration, `false` otherwise.
46 47 48 49 |
# File 'lib/scnr/introspector/scope.rb', line 46 def empty? !@path_start_with && !@path_end_with && @path_include_patterns.empty? && @path_exclude_patterns.empty? end |
#hash ⇒ Object
91 92 93 |
# File 'lib/scnr/introspector/scope.rb', line 91 def hash [@path_start_with, @path_end_with, @path_include_patterns, @path_exclude_patterns].hash end |
#in?(path) ⇒ Bool
Returns ‘true` if `path` is `#in?` scope, `false` otherwise.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/scnr/introspector/scope.rb', line 65 def in?( path ) if @path_start_with return path.to_s.start_with?( @path_start_with ) end if @path_end_with return path.to_s.end_with?( @path_end_with ) end if @path_include_patterns.any? @path_include_patterns.each do |pattern| return true if path =~ pattern end return false end if @path_exclude_patterns.any? @path_exclude_patterns.each do |pattern| return false if path =~ pattern end end true end |
#out?(path) ⇒ Bool
Returns ‘true` if `path` is not `#in?` scope, `false` otherwise.
56 57 58 |
# File 'lib/scnr/introspector/scope.rb', line 56 def out?( path ) !in?( path ) end |