Class: Repofetch
- Inherits:
-
Object
- Object
- Repofetch
- Defined in:
- lib/repofetch.rb,
lib/repofetch/cli.rb,
lib/repofetch/env.rb,
lib/repofetch/stat.rb,
lib/repofetch/util.rb,
lib/repofetch/theme.rb,
lib/repofetch/config.rb,
lib/repofetch/github.rb,
lib/repofetch/gitlab.rb,
lib/repofetch/plugin.rb,
lib/repofetch/version.rb,
lib/repofetch/exceptions.rb,
lib/repofetch/timespan_stat.rb,
lib/repofetch/bitbucketcloud.rb,
lib/repofetch/bitbucketcloud/stats.rb
Overview
Main class for repofetch
Defined Under Namespace
Modules: Util Classes: BitbucketCloud, CLI, Config, Env, Error, Github, Gitlab, NoPluginsError, Plugin, PluginUsageError, Stat, Theme, TimespanStat, TooManyPluginsError
Constant Summary collapse
- MAX_ASCII_WIDTH =
40
- MAX_ASCII_HEIGHT =
20
- DEFAULT_THEME =
Theme.new.freeze
- VERSION =
File.read(File.('VERSION', __dir__)).strip
Class Attribute Summary collapse
-
.config ⇒ Object
Returns the value of attribute config.
-
.plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Class Method Summary collapse
-
.get_plugin(path, args) ⇒ Plugin
Returns the plugin that should be used.
-
.get_plugin_for_path(path) ⇒ Plugin?
Gets a single plugin that matches the given path.
-
.get_plugin_for_repo(path) ⇒ Plugin?
Gets a single plugin that matches the given repository.
-
.get_plugins_for_path(path) ⇒ Array<Plugin>
Gets the plugins that matches the given path.
-
.get_plugins_for_repo(path) ⇒ Array<Plugin>
Gets the plugins that matches the given repository.
-
.load_config ⇒ Object
Loads the config, without affecting the file system.
-
.load_config! ⇒ Object
Loads the config, writing a default config if it doesn’t exist.
-
.register_plugin(plugin) ⇒ Object
Registers a plugin.
-
.replace_or_register_plugin(old, new) ⇒ Object
Replaces an existing plugin.
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
23 24 25 |
# File 'lib/repofetch.rb', line 23 def config @config end |
.plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
24 25 26 |
# File 'lib/repofetch.rb', line 24 def plugins @plugins end |
Class Method Details
.get_plugin(path, args) ⇒ Plugin
Returns the plugin that should be used. Raises a Repofetch::NoPluginsError
if no plugins are found. Raises a Repofetch::TooManyPluginsError
if more than one plugin is found.
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/repofetch.rb', line 70 def self.get_plugin(path, args) path_plugin = get_plugin_for_path(path) repo_plugin = get_plugin_for_repo(path) raise TooManyPluginsError if path_plugin && repo_plugin raise NoPluginsError if path_plugin.nil? && repo_plugin.nil? return path_plugin.from_path(path, args) unless path_plugin.nil? git = Git.open(path) repo_plugin.from_git(git, args) end |
.get_plugin_for_path(path) ⇒ Plugin?
Gets a single plugin that matches the given path.
98 99 100 101 102 103 104 |
# File 'lib/repofetch.rb', line 98 def self.get_plugin_for_path(path) plugins = get_plugins_for_path(path) raise TooManyPluginsError if plugins.length > 1 plugins[0] end |
.get_plugin_for_repo(path) ⇒ Plugin?
Gets a single plugin that matches the given repository.
126 127 128 129 130 131 132 |
# File 'lib/repofetch.rb', line 126 def self.get_plugin_for_repo(path) plugins = get_plugins_for_repo(path) raise TooManyPluginsError if plugins.length > 1 plugins[0] end |
.get_plugins_for_path(path) ⇒ Array<Plugin>
Gets the plugins that matches the given path.
89 90 91 |
# File 'lib/repofetch.rb', line 89 def self.get_plugins_for_path(path) @plugins.filter { |plugin_class| plugin_class.matches_path?(path) } end |
.get_plugins_for_repo(path) ⇒ Array<Plugin>
Gets the plugins that matches the given repository.
111 112 113 114 115 116 117 118 119 |
# File 'lib/repofetch.rb', line 111 def self.get_plugins_for_repo(path) begin git = Git.open(path) rescue ArgumentError return [] end @plugins.filter { |plugin_class| plugin_class.matches_repo?(git) } end |
.load_config ⇒ Object
Loads the config, without affecting the file system.
28 29 30 |
# File 'lib/repofetch.rb', line 28 def self.load_config @config = Config.load end |
.load_config! ⇒ Object
Loads the config, writing a default config if it doesn’t exist.
33 34 35 |
# File 'lib/repofetch.rb', line 33 def self.load_config! @config = Config.load! end |
.register_plugin(plugin) ⇒ Object
Registers a plugin.
40 41 42 |
# File 'lib/repofetch.rb', line 40 def self.register_plugin(plugin) @plugins << plugin end |
.replace_or_register_plugin(old, new) ⇒ Object
Replaces an existing plugin. If the existing plugin does not exist, then it registers the plugin instead.
49 50 51 52 53 54 55 56 57 |
# File 'lib/repofetch.rb', line 49 def self.replace_or_register_plugin(old, new) index = @plugins.find_index(old) if index.nil? register_plugin(new) else @plugins[index] = new @plugins end end |