Class: DepsGrapher::Source
- Inherits:
-
Object
- Object
- DepsGrapher::Source
- Defined in:
- lib/deps_grapher/source.rb
Instance Attribute Summary collapse
- #exclude_pattern ⇒ Object writeonly
-
#glob_pattern ⇒ Object
Returns the value of attribute glob_pattern.
- #include_pattern ⇒ Object writeonly
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #files ⇒ Object
-
#initialize(name, &block) ⇒ Source
constructor
A new instance of Source.
- #to_s ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Source
Returns a new instance of Source.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/deps_grapher/source.rb', line 7 def initialize(name, &block) @name = name @include_pattern = nil @exclude_pattern = nil DSL.new(self).instance_eval(&block) assert! @glob_pattern = Array(glob_pattern.presence || File.join("**", "*.rb")).each_with_object([]) do |pattern, array| array << File.join(root, pattern) end end |
Instance Attribute Details
#exclude_pattern=(pattern) ⇒ Object
34 35 36 |
# File 'lib/deps_grapher/source.rb', line 34 def exclude_pattern=(pattern) @exclude_pattern = Matcher.new pattern end |
#glob_pattern ⇒ Object
Returns the value of attribute glob_pattern.
5 6 7 |
# File 'lib/deps_grapher/source.rb', line 5 def glob_pattern @glob_pattern end |
#include_pattern=(pattern) ⇒ Object
30 31 32 |
# File 'lib/deps_grapher/source.rb', line 30 def include_pattern=(pattern) @include_pattern = Matcher.new pattern end |
#root ⇒ Object
Returns the value of attribute root.
5 6 7 |
# File 'lib/deps_grapher/source.rb', line 5 def root @root end |
Instance Method Details
#files ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/deps_grapher/source.rb', line 21 def files Dir.glob(glob_pattern).sort.uniq.each_with_object([]) do |file, files| next if include_pattern && !include_pattern.match?(file) next if exclude_pattern&.match?(file) files << file end end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/deps_grapher/source.rb', line 38 def to_s "glob_pattern: #{glob_pattern.inspect}, include_pattern: #{include_pattern.inspect}, exclude_pattern: #{exclude_pattern.inspect}" end |