Class: Hairballs::Theme

Inherits:
Object
  • Object
show all
Includes:
LibraryHelpers
Defined in:
lib/hairballs/theme.rb

Overview

Themes primarily provide a means for customizing the look of your IRB prompt, although you’re at liberty to also do any other Ruby stuff you’d like, including load up common Hairballs::Plugins.

Unless you know you do, you probably don’t need to use this directly; Hairballs.add_theme() and Hairballs.use_theme() should cover most use cases.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LibraryHelpers

#do_bundler_extending, #find_latest_gem, #libraries, #require_libraries, #undo_bundler_extending

Constructor Details

#initialize(name) ⇒ Theme

Returns a new instance of Theme.

Parameters:

  • name (Symbol)


32
33
34
35
36
# File 'lib/hairballs/theme.rb', line 32

def initialize(name)
  @name = name
  @prompt = Prompt.new
  @extend_bundler = false
end

Instance Attribute Details

#extend_bundlerBoolean

Tells Hairballs to do some hackery to let Themes use gems that aren’t specified in your app’s Gemfile. This alleviates you from having to declare gems in your Gemfile simply for the sake of managing your personal IRB preferences.

Returns:

  • (Boolean)


29
30
31
# File 'lib/hairballs/theme.rb', line 29

def extend_bundler
  @extend_bundler
end

#nameSymbol

Just an identifier for the Theme. Don’t name two themes the same name–that will cause problems.

Returns:

  • (Symbol)


20
21
22
# File 'lib/hairballs/theme.rb', line 20

def name
  @name
end

Instance Method Details

#irb_nameSymbol

The name of the Theme, but in the format that IRB.conf likes (an all-caps Symbol).

Returns:

  • (Symbol)


51
52
53
# File 'lib/hairballs/theme.rb', line 51

def irb_name
  @name.to_s.upcase.to_sym
end

#prompt(&block) ⇒ Hairballs::Prompt

Returns:



56
57
58
59
60
61
62
# File 'lib/hairballs/theme.rb', line 56

def prompt(&block)
  if block_given?
    @prompt_block = block
  else
    @prompt
  end
end

#use!Object

Tell IRB to use this Theme.



39
40
41
42
43
44
45
# File 'lib/hairballs/theme.rb', line 39

def use!
  do_bundler_extending if @extend_bundler
  vputs "[th:#{@name}] Requiring libs..."
  require_libraries
  set_up_prompt
  vputs "[th:#{@name}] Done setting up."
end