Class: GitFame::Base
- Inherits:
-
Object
- Object
- GitFame::Base
- Extended by:
- Memoist
- Includes:
- Helper
- Defined in:
- lib/git_fame/base.rb
Instance Method Summary collapse
- #authors ⇒ Object
-
#commits ⇒ Object
Fixnum Total number of commits.
-
#csv_puts ⇒ Object
Prints CSV.
-
#file_list ⇒ Object
TODO: Rename.
-
#files ⇒ Object
TODO: Rename this.
- #initialize(args) ⇒ Base constructor
-
#loc ⇒ Object
Fixnum Total number of lines.
-
#pretty_puts ⇒ Object
Generates pretty output.
-
#to_csv ⇒ Object
Generate csv output.
Methods included from Helper
Constructor Details
#initialize(args) ⇒ Base
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 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 |
# File 'lib/git_fame/base.rb', line 40 def initialize(args) @default_settings = { branch: "master", sorting: "loc", ignore_types: ["image", "binary"] } = args.fetch(:progressbar, false) = Hash.new { |h,k| h[k] = {} } # Create array out of comma separated list @exclude = args.fetch(:exclude, "").split(","). map{ |path| path.strip.sub(/\A\//, "") } @extensions = args.fetch(:extensions, "").split(",") # Default sorting option is by loc @include = args.fetch(:include, "").split(",") @sort = args.fetch(:sort, @default_settings.fetch(:sorting)) @repository = args.fetch(:repository) @by_type = args.fetch(:by_type, false) @branch = args.fetch(:branch, nil) @everything = args.fetch(:everything, false) @timeout = args.fetch(:timeout, CMD_TIMEOUT) # Figure out what branch the caller is using if present?(@branch = args[:branch]) unless branch_exists?(@branch) raise Error, "Branch '#{@branch}' does not exist" end else @branch = default_branch end @after = args.fetch(:after, nil) @before = args.fetch(:before, nil) [@after, @before].each do |date| if date and not valid_date?(date) raise Error, "#{date} is not a valid date" end end # Fields that should be visible in the final table # Used by #csv_puts, #to_csv and #pretty_puts # Format: [ [ :method_on_author, "custom column name" ] ] @visible_fields = [ :name, :loc, :commits, :files, [:distribution, "distribution (%)"] ] @wopt = args.fetch(:whitespace, false) ? "-w" : "" = {} @cache = {} @verbose = args.fetch(:verbose, false) populate end |
Instance Method Details
#authors ⇒ Object
164 165 166 167 168 |
# File 'lib/git_fame/base.rb', line 164 def .sort_by do || @sort == "name" ? .send(@sort) : -1 * .raw(@sort) end end |
#commits ⇒ Object
Returns Fixnum Total number of commits.
150 151 152 |
# File 'lib/git_fame/base.rb', line 150 def commits .inject(0) { |result, | .raw(:commits) + result } end |
#csv_puts ⇒ Object
Prints CSV
115 116 117 |
# File 'lib/git_fame/base.rb', line 115 def csv_puts puts to_csv end |
#file_list ⇒ Object
TODO: Rename
145 |
# File 'lib/git_fame/base.rb', line 145 def file_list; used_files; end |
#files ⇒ Object
TODO: Rename this
137 138 139 |
# File 'lib/git_fame/base.rb', line 137 def files used_files.count end |
#loc ⇒ Object
Returns Fixnum Total number of lines.
157 158 159 |
# File 'lib/git_fame/base.rb', line 157 def loc .inject(0) { |result, | .raw(:loc) + result } end |
#pretty_puts ⇒ Object
Generates pretty output
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/git_fame/base.rb', line 99 def pretty_puts extend Hirb::Console Hirb.enable({ pager: false }) puts "\nStatistics based on #{commit_range.to_s(true)}" puts "Active files: #{number_with_delimiter(files)}" puts "Active lines: #{number_with_delimiter(loc)}" puts "Total commits: #{number_with_delimiter(commits)}\n" unless @everything puts "\nNote: Files matching MIME type #{ignore_types.join(", ")} has been ignored\n\n" end table(, fields: printable_fields) end |
#to_csv ⇒ Object
Generate csv output
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/git_fame/base.rb', line 122 def to_csv CSV.generate do |csv| csv << fields .each do || csv << fields.map do |f| .send(f) end end end end |