Class: Candelabra::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/candelabra/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

short cut way of calling the system



41
42
43
44
45
46
47
# File 'lib/candelabra/configuration.rb', line 41

def method_missing( method, *args )
  if method.to_s =~ /on_/
    call_event( method )
  else
    super method, *args
  end
end

Instance Attribute Details

#auto_restartObject

Returns the value of attribute auto_restart.



5
6
7
# File 'lib/candelabra/configuration.rb', line 5

def auto_restart
  @auto_restart
end

#event_handlerObject

Returns the value of attribute event_handler.



5
6
7
# File 'lib/candelabra/configuration.rb', line 5

def event_handler
  @event_handler
end

#in_installerObject

Returns the value of attribute in_installer.



5
6
7
# File 'lib/candelabra/configuration.rb', line 5

def in_installer
  @in_installer
end

#on_error=(value) ⇒ Object (writeonly)

Sets the attribute on_error

Parameters:

  • value

    the value to set the attribute on_error to.



6
7
8
# File 'lib/candelabra/configuration.rb', line 6

def on_error=(value)
  @on_error = value
end

#on_song_finish=(value) ⇒ Object (writeonly)

Sets the attribute on_song_finish

Parameters:

  • value

    the value to set the attribute on_song_finish to.



6
7
8
# File 'lib/candelabra/configuration.rb', line 6

def on_song_finish=(value)
  @on_song_finish = value
end

#on_song_start=(value) ⇒ Object (writeonly)

Sets the attribute on_song_start

Parameters:

  • value

    the value to set the attribute on_song_start to.



6
7
8
# File 'lib/candelabra/configuration.rb', line 6

def on_song_start=(value)
  @on_song_start = value
end

Class Method Details

.clearObject

Clear out the old settings in the configuration



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

def clear
  auto_restart, event_handler = nil,nil
  @on_song_start, @on_song_finish, @on_error = nil,nil,nil
end

.go {|self.instance| ... } ⇒ Object

Initilize the configuration

Yields:

  • (self.instance)


10
11
12
13
# File 'lib/candelabra/configuration.rb', line 10

def go
  clear
  yield self.instance
end

Instance Method Details

#call_event(event) ⇒ Object

Call the event requested by the system

Returns what ever the system is configured to or nil



30
31
32
33
34
35
36
37
38
# File 'lib/candelabra/configuration.rb', line 30

def call_event( event )
  if handler?
    event_handler.send( event )
  elsif instance_variable_get( "@" + event.to_s ).respond_to?( 'call' )
    instance_variable_get( "@" + event.to_s ).send( :call )
  else
    instance_variable_get( "@" + event.to_s )
  end
end

#handler?Boolean

Check to determine if the hander has been set yet or not

Returns:

  • (Boolean)


23
24
25
# File 'lib/candelabra/configuration.rb', line 23

def handler?
  !event_handler.nil?
end