Class: SCNR::Introspector::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/scnr/introspector/scope.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Scope



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/scnr/introspector/scope.rb', line 31

def initialize( options = {} )
    options.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_withString?



19
20
21
# File 'lib/scnr/introspector/scope.rb', line 19

def path_end_with
  @path_end_with
end

#path_exclude_patternsArray<Regexp>



27
28
29
# File 'lib/scnr/introspector/scope.rb', line 27

def path_exclude_patterns
  @path_exclude_patterns
end

#path_include_patternsArray<Regexp>



23
24
25
# File 'lib/scnr/introspector/scope.rb', line 23

def path_include_patterns
  @path_include_patterns
end

#path_start_withString?



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



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

#hashObject



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



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



56
57
58
# File 'lib/scnr/introspector/scope.rb', line 56

def out?( path )
    !in?( path )
end