Class: GitStatistics::GitStatistics
- Inherits:
-
Object
- Object
- GitStatistics::GitStatistics
- Defined in:
- lib/git_statistics.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize ⇒ GitStatistics
constructor
A new instance of GitStatistics.
- #parse_options ⇒ Object
Constructor Details
#initialize ⇒ GitStatistics
Returns a new instance of GitStatistics.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/git_statistics.rb', line 8 def initialize @options = OpenStruct.new( email: false, merges: false, pretty: false, update: false, sort: "commits", top: 0, branch: false, verbose: false, debug: false, limit: 100 ) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/git_statistics.rb', line 7 def @options end |
Instance Method Details
#execute ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 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 |
# File 'lib/git_statistics.rb', line 24 def execute if .debug Log.level = Logger::DEBUG Log.use_debug elsif .verbose Log.level = Logger::INFO end # Collect data (incremental or fresh) based on presence of old data if .update # Ensure commit directory is present collector = Collector.new(.limit, false, .pretty) commits_directory = File.join(collector.repo_path, ".git_statistics") FileUtils.mkdir_p(commits_directory) file_count = Utilities.number_of_matching_files(commits_directory, /\d+\.json/) - 1 if file_count >= 0 time = Utilities.get_modified_time(commits_directory + "#{file_count}.json") # Only use --since if there is data present collector.collect(.branch, "--since=\"#{time}\"") collected = true end end # If no data was collected as there was no present data then start fresh unless collected collector = Collector.new(.limit, true, .pretty) collector.collect(.branch) end # Calculate statistics collector.commits.calculate_statistics(.email, .merges) # Print results results = Formatters::Console.new(collector.commits) puts results.print_summary(.sort, .email, .top) end |
#parse_options ⇒ Object
62 63 64 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 90 91 92 93 94 95 96 |
# File 'lib/git_statistics.rb', line 62 def OptionParser.new do |opt| opt.version = VERSION opt.on "-e", "--email", "Use author's email instead of name" do .email = true end opt.on "-m", "--merges", "Factor in merges when calculating statistics" do .merges = true end opt.on "-p", "--pretty", "Save the commits in git_repo/.git_statistics in pretty print (larger file size)" do .pretty = true end opt.on "-u", "--update", "Update saved commits with new data" do .update = true end opt.on "-s", "--sort TYPE", "Sort authors by {commits, additions, deletions, create, delete, rename, copy, merges}" do |type| .sort = type end opt.on "-t", "--top N", Float,"Show the top N authors in results" do |value| .top = value end opt.on "-b", "--branch", "Use current branch for statistics (otherwise all branches)" do .branch = true end opt.on "-v", "--verbose", "Verbose output (shows INFO level log statements)" do .verbose = true end opt.on "-d", "--debug", "Debug output (shows DEBUG level log statements)" do .debug = true end opt.on "-l", "--limit MAX_COMMITS", Float, "The maximum limit of commits to hold in memory at a time" do |number| .limit = number end end.parse! end |