Class: Hairballs::Configuration
- Inherits:
-
Object
- Object
- Hairballs::Configuration
- Defined in:
- lib/hairballs/configuration.rb
Overview
The base-level Hairballs
class maintains an object of this type, which contains the current configuration.
Instance Attribute Summary collapse
-
#completion_procs ⇒ Array<Proc>
readonly
Used for maintaining all possible completion Procs, thus allowing many different plugins to define a Proc for completion without overriding Procs defined for other plugins.
- #current_theme ⇒ Hairballs::Theme readonly
-
#loaded_plugins ⇒ Array<Hairballs::Plugin>
readonly
All Hairballs::Plugins that have been loaded.
-
#plugins ⇒ Array<Hairballs::Plugin>
readonly
All Hairballs::Plugins available to be loaded.
-
#project_name ⇒ String
readonly
Name of the project, if it can be determined.
- #themes ⇒ Array<Hairballs::Theme> readonly
Instance Method Summary collapse
-
#add_plugin(name, **options) ⇒ Object
Builds a new Hairballs::Plugin and adds it to thelist of ‘.plugins` that can be used.
-
#add_theme(name) {|theme| ... } ⇒ Theme
Builds a new Hairballs::Theme and adds it to the list of ‘.themes` that can be used.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#load_plugin(plugin_name, **options) ⇒ Object
Searches for the Hairballs::Plugin by the
plugin_name
, then loads it. - #project_root ⇒ Pathname
- #project_root?(path) ⇒ Boolean
-
#rails? ⇒ Boolean
Is IRB getting loaded for a Rails console?.
-
#use_theme(theme_name) ⇒ Object
Tells IRB to use the Hairballs::Theme of
theme_name
. - #version ⇒ String
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
40 41 42 43 44 45 46 47 48 |
# File 'lib/hairballs/configuration.rb', line 40 def initialize @themes = [] @current_theme = nil @plugins = [] @loaded_plugins = [] @completion_procs = [] @project_name = nil @project_root = nil end |
Instance Attribute Details
#completion_procs ⇒ Array<Proc> (readonly)
Used for maintaining all possible completion Procs, thus allowing many different plugins to define a Proc for completion without overriding Procs defined for other plugins.
35 36 37 |
# File 'lib/hairballs/configuration.rb', line 35 def completion_procs @completion_procs end |
#current_theme ⇒ Hairballs::Theme (readonly)
18 19 20 |
# File 'lib/hairballs/configuration.rb', line 18 def current_theme @current_theme end |
#loaded_plugins ⇒ Array<Hairballs::Plugin> (readonly)
All Hairballs::Plugins that have been loaded.
28 29 30 |
# File 'lib/hairballs/configuration.rb', line 28 def loaded_plugins @loaded_plugins end |
#plugins ⇒ Array<Hairballs::Plugin> (readonly)
All Hairballs::Plugins available to be loaded.
23 24 25 |
# File 'lib/hairballs/configuration.rb', line 23 def plugins @plugins end |
#project_name ⇒ String (readonly)
Name of the project, if it can be determined. If not, defaults to “irb”.
38 39 40 |
# File 'lib/hairballs/configuration.rb', line 38 def project_name @project_name end |
#themes ⇒ Array<Hairballs::Theme> (readonly)
15 16 17 |
# File 'lib/hairballs/configuration.rb', line 15 def themes @themes end |
Instance Method Details
#add_plugin(name, **options) ⇒ Object
Builds a new Hairballs::Plugin and adds it to thelist of ‘.plugins` that can be used.
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/hairballs/configuration.rb', line 117 def add_plugin(name, **) vputs "[config] Adding plugin: #{name}" plugin = Plugin.new(name, ) yield plugin plugins << plugin vputs "[config] Added plugin: #{name}" plugin rescue => ex # rubocop:disable Metrics/LineLength vputs "[config] Exception adding plugin: #{ex.class}: #{ex.}\n#{ex.backtrace[0]}" # rubocop:enable Metrics/LineLength end |
#add_theme(name) {|theme| ... } ⇒ Theme
Builds a new Hairballs::Theme and adds it to the list of ‘.themes` that can be used.
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/hairballs/configuration.rb', line 85 def add_theme(name) theme = Theme.new(name) yield theme themes << theme vputs "[config] Added theme: #{name}" theme end |
#load_plugin(plugin_name, **options) ⇒ Object
Searches for the Hairballs::Plugin by the plugin_name
, then loads it. Raises
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/hairballs/configuration.rb', line 134 def load_plugin(plugin_name, **) plugin_to_use = plugins.find { |plugin| plugin.name == plugin_name } fail PluginNotFound, plugin_name unless plugin_to_use vputs "[config] Using plugin: #{plugin_name}" plugin_to_use.load!() loaded_plugins << plugin_to_use true end |
#project_root ⇒ Pathname
70 71 72 |
# File 'lib/hairballs/configuration.rb', line 70 def project_root @project_root ||= find_project_root end |
#project_root?(path) ⇒ Boolean
76 77 78 |
# File 'lib/hairballs/configuration.rb', line 76 def project_root?(path) File.(path) == project_root end |
#rails? ⇒ Boolean
Is IRB getting loaded for a Rails console?
58 59 60 |
# File 'lib/hairballs/configuration.rb', line 58 def rails? ENV.key?('RAILS_ENV') || Kernel.const_defined?(:Rails) end |
#use_theme(theme_name) ⇒ Object
Tells IRB to use the Hairballs::Theme of theme_name
.
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/hairballs/configuration.rb', line 99 def use_theme(theme_name) switch_to = themes.find { |theme| theme.name == theme_name } fail ThemeUseFailure, theme_name unless switch_to vputs "[config] Switched to theme: #{theme_name}" switch_to.use! @current_theme = switch_to true end |