Class: Steep::Services::FileLoader
- Defined in:
- lib/steep/services/file_loader.rb
Instance Attribute Summary collapse
-
#base_dir ⇒ Object
readonly
Returns the value of attribute base_dir.
Instance Method Summary collapse
- #each_path_in_patterns(pattern, commandline_patterns = []) ⇒ Object
- #each_path_in_target(target, command_line_patterns = [], &block) ⇒ Object
-
#initialize(base_dir:) ⇒ FileLoader
constructor
A new instance of FileLoader.
- #load_changes(pattern, command_line_patterns = [], changes:) ⇒ Object
Constructor Details
#initialize(base_dir:) ⇒ FileLoader
Returns a new instance of FileLoader.
6 7 8 |
# File 'lib/steep/services/file_loader.rb', line 6 def initialize(base_dir:) @base_dir = base_dir end |
Instance Attribute Details
#base_dir ⇒ Object (readonly)
Returns the value of attribute base_dir.
4 5 6 |
# File 'lib/steep/services/file_loader.rb', line 4 def base_dir @base_dir end |
Instance Method Details
#each_path_in_patterns(pattern, commandline_patterns = []) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/steep/services/file_loader.rb', line 35 def each_path_in_patterns(pattern, commandline_patterns = []) if block_given? pats = commandline_patterns.empty? ? pattern.patterns : commandline_patterns pats.each do |path| Pathname(base_dir).glob(path.to_s).each do |absolute_path| if absolute_path.file? relative_path = absolute_path.relative_path_from(base_dir) if pattern =~ relative_path yield relative_path end else files = Pathname(absolute_path).glob("**/*#{pattern.ext}") files.sort.each do |source_path| if source_path.file? relative_path = source_path.relative_path_from(base_dir) unless pattern.ignore?(relative_path) yield relative_path end end end end end end else enum_for :each_path_in_patterns, pattern, commandline_patterns end end |
#each_path_in_target(target, command_line_patterns = [], &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/steep/services/file_loader.rb', line 10 def each_path_in_target(target, command_line_patterns = [], &block) if block done = Set[] #: Set[Pathname] handler = -> (path) do unless done.include?(path) done << path yield path end end target.groups.each do |group| each_path_in_patterns(group.source_pattern, command_line_patterns, &handler) each_path_in_patterns(group.inline_source_pattern, command_line_patterns, &handler) each_path_in_patterns(group.signature_pattern, &handler) end each_path_in_patterns(target.source_pattern, command_line_patterns, &handler) each_path_in_patterns(target.inline_source_pattern, command_line_patterns, &handler) each_path_in_patterns(target.signature_pattern, &handler) else enum_for :each_path_in_target, target, command_line_patterns end end |
#load_changes(pattern, command_line_patterns = [], changes:) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/steep/services/file_loader.rb', line 65 def load_changes(pattern, command_line_patterns = [], changes:) each_path_in_patterns(pattern, command_line_patterns) do |path| unless changes.key?(path) changes[path] = [ContentChange.string((base_dir + path).read)] end end changes end |