Module: Metior

Defined in:
lib/metior.rb,
lib/metior/vcs.rb,
lib/metior/actor.rb,
lib/metior/errors.rb,
lib/metior/report.rb,
lib/metior/commit.rb,
lib/metior/version.rb,
lib/metior/repository.rb,
lib/metior/auto_include_adapter.rb,
lib/metior/collections/collection.rb,
lib/metior/collections/actor_collection.rb,
lib/metior/collections/commit_collection.rb

Overview

This code is free software; you can redistribute it and/or modify it under the terms of the new BSD License.

Copyright (c) 2011-2012, Sebastian Staudt

Defined Under Namespace

Modules: Adapter, AutoIncludeAdapter, Registerable, Report, VCS Classes: Actor, ActorCollection, Collection, Commit, CommitCollection, FileNotFoundError, Repository, UnknownAdapterError, UnknownVCSError, UnsupportedError

Constant Summary

VERSION =
'0.2.0'
@@reports =

This holds all available reports, i.e. their names and the corresponding class

{}
@@vcs_adapters =

This hash will be dynamically filled with all available VCS adapters and the corresponding modules

{}
@@vcs_types =

This hash will be dynamically filled with all available VCS types and the corresponding modules

{}

Class Method Summary (collapse)

Class Method Details

+ (Module) find_adapter(name)

Returns the adapter Module for a given symbolic adapter name

Parameters:

  • name (Symbol)

    The symbolic name of the adapter

Returns:

  • (Module)

    The adapter for the given name

Raises:



87
88
89
90
91
# File 'lib/metior.rb', line 87

def self.find_adapter(name)
  name = name.to_sym
  raise UnknownAdapterError.new(name) unless @@vcs_adapters.key? name
  @@vcs_adapters[name]
end

+ (Class) find_report(name)

Find the base class of the report with the given name

Parameters:

  • The (Symbol)

    symbolic name of the report

Returns:

  • (Class)

    The report for the given name

Raises:

  • (UnknownReportError)


97
98
99
100
101
# File 'lib/metior.rb', line 97

def self.find_report(name)
  name = name.to_sym
  raise UnknownReportError.new(name) unless @@reports.key? name
  @@reports[name]
end

+ (Module) find_vcs(name)

Returns the VCS Module for a given symbolic VCS name

Parameters:

  • name (Symbol)

    The symbolic name of the VCS

Returns:

  • (Module)

    The VCS for the given name

Raises:



121
122
123
124
125
# File 'lib/metior.rb', line 121

def self.find_vcs(name)
  name = name.to_sym
  raise UnknownVCSError.new(name) unless @@vcs_types.key? name
  @@vcs_types[name]
end

+ (Object) register(name, mod)

Registers a VCS or adapter Module using the given symbolic name

Parameters:

  • name (Symbol)

    The symbolic name to register the Module as

  • mod (Module)

    The component to register



107
108
109
110
111
112
113
114
115
# File 'lib/metior.rb', line 107

def self.register(name, mod)
  if mod.include? VCS
    @@vcs_types[name] = mod
  elsif mod.include? Adapter
    @@vcs_adapters[name] = mod
  elsif mod.include? Report
    @@reports[name] = mod
  end
end

+ (Object) report(type, repo_options, target_dir, range = nil, report = 'default')

Generates a report for the given repository

Parameters:

  • type (Symbol)

    The type of the repository, e.g. :git

  • options (Array<Object>)

    The options to use for creating the new repository, e.g. a file system path

  • target_dir (String)

    The target directory to save the report to

  • range (String, Range) (defaults to: nil)

    The commit range to analyze for the report

  • report (String) (defaults to: 'default')

    The name of the report template to use



54
55
56
57
58
# File 'lib/metior.rb', line 54

def self.report(type, repo_options, target_dir, range = nil, report = 'default')
  repo = repository type, *repo_options
  range ||= repo.current_branch
  Report.create(report, repo, range).generate target_dir
end

+ (Repository) repository(name, *options)

Creates a new repository for the given VCS or adapter name and repository path

Parameters:

  • name (Symbol)

    The name of the repository's VCS or the adapter to use

  • options (Array<Object>)

    The options to use for creating the new repository, e.g. a file system path

Returns:

  • (Repository)

    A VCS specific Repository instance



37
38
39
40
41
42
43
44
# File 'lib/metior.rb', line 37

def self.repository(name, *options)
  begin
    adapter = find_adapter name
  rescue UnknownAdapterError
    adapter = find_vcs(name).default_adapter
  end
  adapter::Repository.new *options
end

+ (Hash<Symbol, Object>) simple_stats(type, repo_options, range = nil)

Calculates simplistic stats for the given repository and branch

Parameters:

  • type (Symbol)

    The type of the repository, e.g. :git

  • repo_options (Object, Array<Object>)

    The options to supply to the repository

  • range (String, Range) (defaults to: nil)

    The range of commits for which the commits should be loaded. This may be given as a string ('master..development'), a range ('master'..'development') or as a single ref ('master'). A single ref name means all commits reachable from that ref.

Returns:

  • (Hash<Symbol, Object>)

    The calculated stats for the given repository and branch



72
73
74
75
76
77
78
79
80
81
# File 'lib/metior.rb', line 72

def self.simple_stats(type, repo_options, range = nil)
  repo  = repository type, *repo_options
  range ||= repo.current_branch

  commits = repo.commits(range)
  {
    :commit_count     => commits.size,
    :top_contributors => repo.top_contributors(range, 5)
  }.merge commits.activity
end