Class: Hairballs::Configuration
- Inherits:
-
Object
- Object
- Hairballs::Configuration
- Defined in:
- lib/hairballs/configuration.rb
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) {|plugin| ... } ⇒ 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.
38 39 40 41 42 43 44 45 46 |
# File 'lib/hairballs/configuration.rb', line 38 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.
33 34 35 |
# File 'lib/hairballs/configuration.rb', line 33 def completion_procs @completion_procs end |
#current_theme ⇒ Hairballs::Theme (readonly)
16 17 18 |
# File 'lib/hairballs/configuration.rb', line 16 def current_theme @current_theme end |
#loaded_plugins ⇒ Array<Hairballs::Plugin> (readonly)
All Hairballs::Plugins that have been loaded.
26 27 28 |
# File 'lib/hairballs/configuration.rb', line 26 def loaded_plugins @loaded_plugins end |
#plugins ⇒ Array<Hairballs::Plugin> (readonly)
All Hairballs::Plugins available to be loaded.
21 22 23 |
# File 'lib/hairballs/configuration.rb', line 21 def plugins @plugins end |
#project_name ⇒ String (readonly)
Name of the project, if it can be determined. If not, defaults to “irb”.
36 37 38 |
# File 'lib/hairballs/configuration.rb', line 36 def project_name @project_name end |
#themes ⇒ Array<Hairballs::Theme> (readonly)
13 14 15 |
# File 'lib/hairballs/configuration.rb', line 13 def themes @themes end |
Instance Method Details
#add_plugin(name, **options) {|plugin| ... } ⇒ Object
Builds a new Hairballs::Plugin and adds it to thelist of ‘.plugins` that can be used.
115 116 117 118 119 120 121 122 |
# File 'lib/hairballs/configuration.rb', line 115 def add_plugin(name, **) plugin = Plugin.new(name, ) yield plugin plugins << plugin vputs "Added plugin: #{name}" plugin end |
#add_theme(name) {|theme| ... } ⇒ Theme
Builds a new Hairballs::Theme and adds it to the list of ‘.themes` that can be used.
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/hairballs/configuration.rb', line 83 def add_theme(name) theme = Theme.new(name) yield theme themes << theme vputs "Added theme: #{name}" theme end |
#load_plugin(plugin_name, **options) ⇒ Object
Searches for the Hairballs::Plugin by the plugin_name
, then loads it. Raises
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/hairballs/configuration.rb', line 127 def load_plugin(plugin_name, **) plugin_to_use = plugins.find { |plugin| plugin.name == plugin_name } fail PluginNotFound.new(plugin_name) unless plugin_to_use vputs "Using plugin: #{plugin_name}" plugin_to_use.load!() loaded_plugins << plugin_to_use true end |
#project_root ⇒ Pathname
68 69 70 |
# File 'lib/hairballs/configuration.rb', line 68 def project_root @project_root ||= find_project_root end |
#project_root?(path) ⇒ Boolean
74 75 76 |
# File 'lib/hairballs/configuration.rb', line 74 def project_root?(path) File.(path) == project_root end |
#rails? ⇒ Boolean
Is IRB getting loaded for a Rails console?
56 57 58 |
# File 'lib/hairballs/configuration.rb', line 56 def rails? ENV.has_key?('RAILS_ENV') || !!defined?(Rails) end |
#use_theme(theme_name) ⇒ Object
Tells IRB to use the Hairballs::Theme of theme_name
.
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/hairballs/configuration.rb', line 97 def use_theme(theme_name) switch_to = themes.find { |theme| theme.name == theme_name } fail ThemeUseFailure.new(theme_name) unless switch_to vputs "Switched to theme: #{theme_name}" switch_to.use! @current_theme = switch_to true end |