Class: Hairballs::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/hairballs/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_procsArray<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.

Returns:

  • (Array<Proc>)


33
34
35
# File 'lib/hairballs/configuration.rb', line 33

def completion_procs
  @completion_procs
end

#current_themeHairballs::Theme (readonly)

Returns:



16
17
18
# File 'lib/hairballs/configuration.rb', line 16

def current_theme
  @current_theme
end

#loaded_pluginsArray<Hairballs::Plugin> (readonly)

All Hairballs::Plugins that have been loaded.

Returns:



26
27
28
# File 'lib/hairballs/configuration.rb', line 26

def loaded_plugins
  @loaded_plugins
end

#pluginsArray<Hairballs::Plugin> (readonly)

All Hairballs::Plugins available to be loaded.

Returns:



21
22
23
# File 'lib/hairballs/configuration.rb', line 21

def plugins
  @plugins
end

#project_nameString (readonly)

Name of the project, if it can be determined. If not, defaults to “irb”.

Returns:

  • (String)


36
37
38
# File 'lib/hairballs/configuration.rb', line 36

def project_name
  @project_name
end

#themesArray<Hairballs::Theme> (readonly)

Returns:



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.

Parameters:

  • name (Symbol)
  • options (Hash)

    Plugin-dependent options to define. These get passed along the the Hairballs::Plugin object and are used as attributes of the plugin.

Yields:

  • (plugin)


115
116
117
118
119
120
121
122
# File 'lib/hairballs/configuration.rb', line 115

def add_plugin(name, **options)
  plugin = Plugin.new(name, options)
  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.

Parameters:

  • name (Symbol)

    Name to give the new Theme.

Yields:

  • (theme)

Returns:



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

Parameters:

  • plugin_name (Symbol)


127
128
129
130
131
132
133
134
135
136
# File 'lib/hairballs/configuration.rb', line 127

def load_plugin(plugin_name, **options)
  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!(options)
  loaded_plugins << plugin_to_use

  true
end

#project_rootPathname

Returns:

  • (Pathname)


68
69
70
# File 'lib/hairballs/configuration.rb', line 68

def project_root
  @project_root ||= find_project_root
end

#project_root?(path) ⇒ Boolean

Parameters:

  • path (String)

Returns:

  • (Boolean)


74
75
76
# File 'lib/hairballs/configuration.rb', line 74

def project_root?(path)
  File.expand_path(path) == project_root
end

#rails?Boolean

Is IRB getting loaded for a Rails console?

Returns:

  • (Boolean)


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.

Parameters:

  • theme_name (Symbol)

    The name of the Theme to use/switch to.



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

#versionString

Returns:

  • (String)


49
50
51
# File 'lib/hairballs/configuration.rb', line 49

def version
  Hairballs::VERSION
end