Module: DatabaseConsistency::FilesHelper
- Defined in:
- lib/database_consistency/files_helper.rb
Overview
The module contains file system helper methods for locating project source files.
Class Method Summary collapse
- .collect_source_files ⇒ Object
- .excluded_by_ruby_stdlib?(file) ⇒ Boolean
- .excluded_source_file?(file) ⇒ Boolean
-
.project_source_files ⇒ Object
Returns all unique project source file paths (non-gem Ruby files from loaded constants).
- .source_file_path(mod) ⇒ Object
Class Method Details
.collect_source_files ⇒ Object
19 20 21 22 23 |
# File 'lib/database_consistency/files_helper.rb', line 19 def collect_source_files files = [] ObjectSpace.each_object(Module) { |mod| files << source_file_path(mod) } files.compact.uniq end |
.excluded_by_ruby_stdlib?(file) ⇒ Boolean
44 45 46 47 48 49 50 |
# File 'lib/database_consistency/files_helper.rb', line 44 def excluded_by_ruby_stdlib?(file) return false unless defined?(RbConfig) file.include?(RbConfig::CONFIG['rubylibdir']) || file.include?(RbConfig::CONFIG['bindir']) || file.include?(RbConfig::CONFIG['sbindir']) end |
.excluded_source_file?(file) ⇒ Boolean
37 38 39 40 41 42 |
# File 'lib/database_consistency/files_helper.rb', line 37 def excluded_source_file?(file) return true if defined?(Bundler) && file.include?(Bundler.bundle_path.to_s) return true if defined?(Gem) && file.include?(Gem::RUBYGEMS_DIR) excluded_by_ruby_stdlib?(file) end |
.project_source_files ⇒ Object
Returns all unique project source file paths (non-gem Ruby files from loaded constants). Memoized so the file system walk happens once per database_consistency run.
10 11 12 13 14 15 16 17 |
# File 'lib/database_consistency/files_helper.rb', line 10 def project_source_files @project_source_files ||= if Module.respond_to?(:const_source_location) collect_source_files else [] end end |
.source_file_path(mod) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/database_consistency/files_helper.rb', line 25 def source_file_path(mod) return unless (name = mod.name) file, = Module.const_source_location(name) return unless file && File.exist?(file) return if excluded_source_file?(file) file rescue NameError, ArgumentError nil end |