Class: Gitingest::Generator
- Inherits:
-
Object
- Object
- Gitingest::Generator
- Defined in:
- lib/gitingest/generator.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#repo_files ⇒ Object
readonly
Returns the value of attribute repo_files.
Instance Method Summary collapse
-
#excluded_patterns ⇒ Object
Exposed for testing.
- #generate_directory_structure ⇒ Object
- #generate_file ⇒ Object
- #generate_prompt ⇒ Object
-
#initialize(options = {}) ⇒ Generator
constructor
A new instance of Generator.
- #run ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Generator
Returns a new instance of Generator.
10 11 12 13 14 15 16 17 |
# File 'lib/gitingest/generator.rb', line 10 def initialize( = {}) @options = @repo_files = [] setup_logger configure_client @exclusion_filter = ExclusionFilter.new(@options[:exclude]) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/gitingest/generator.rb', line 8 def client @client end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
8 9 10 |
# File 'lib/gitingest/generator.rb', line 8 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/gitingest/generator.rb', line 8 def @options end |
#repo_files ⇒ Object (readonly)
Returns the value of attribute repo_files.
8 9 10 |
# File 'lib/gitingest/generator.rb', line 8 def repo_files @repo_files end |
Instance Method Details
#excluded_patterns ⇒ Object
Exposed for testing
58 59 60 61 62 63 64 |
# File 'lib/gitingest/generator.rb', line 58 def excluded_patterns # This is a bit of a hack to maintain backward compatibility with tests # that check for excluded_patterns. In the new design, this is handled # by ExclusionFilter. @exclusion_filter.instance_variable_get(:@default_patterns) + @exclusion_filter.instance_variable_get(:@custom_glob_patterns).map { |p| Regexp.new(p.gsub("*", ".*")) } end |
#generate_directory_structure ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/gitingest/generator.rb', line 48 def generate_directory_structure fetch_repository_contents if @repo_files.empty? @logger.info "Generating directory structure for #{@options[:repository]}" repo_name = @options[:repository].split("/").last structure = DirectoryStructureBuilder.new(repo_name, @repo_files).build @logger.info "\n" structure end |
#generate_file ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/gitingest/generator.rb', line 28 def generate_file fetch_repository_contents if @repo_files.empty? @logger.info "Generating file for #{@options[:repository]}" File.open(@options[:output_file], "w") do |file| process_content_to_output(file) end @logger.info "Prompt generated and saved to #{@options[:output_file]}" @options[:output_file] end |
#generate_prompt ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/gitingest/generator.rb', line 38 def generate_prompt @logger.info "Generating in-memory prompt for #{@options[:repository]}" fetch_repository_contents if @repo_files.empty? content = StringIO.new process_content_to_output(content) result = content.string @logger.info "Generated #{result.size} bytes of content in memory" result end |
#run ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/gitingest/generator.rb', line 19 def run fetch_repository_contents if @options[:show_structure] puts generate_directory_structure return end generate_file end |