Class: Theatre::CallbackDefinitionLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/theatre/callback_definition_loader.rb

Overview

This class provides the a wrapper aroung which an events.rb file can be instance_eval’d.

Defined Under Namespace

Classes: BlankSlateMessageRecorder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theatre, root_name = :events) ⇒ CallbackDefinitionLoader

Returns a new instance of CallbackDefinitionLoader.



9
10
11
12
13
14
# File 'lib/theatre/callback_definition_loader.rb', line 9

def initialize(theatre, root_name=:events)
  @theatre   = theatre
  @root_name = root_name
  
  create_recorder_method root_name
end

Instance Attribute Details

#root_nameObject (readonly)

Returns the value of attribute root_name.



8
9
10
# File 'lib/theatre/callback_definition_loader.rb', line 8

def root_name
  @root_name
end

#theatreObject (readonly)

Returns the value of attribute theatre.



8
9
10
# File 'lib/theatre/callback_definition_loader.rb', line 8

def theatre
  @theatre
end

Instance Method Details

#anonymous_recorderObject



16
17
18
# File 'lib/theatre/callback_definition_loader.rb', line 16

def anonymous_recorder
  BlankSlateMessageRecorder.new(&method(:callback_registered))
end

#load_events_code(code) ⇒ Object

Parses the given Ruby source code and returns this object.

NOTE: Only use this if you’re generating the code yourself! If you’re loading a file from the filesystem, you should use load_events_file() since load_events_file() will properly attribute errors in the code to the file from which the code was loaded.

Parameters:

  • code (String)

    The Ruby source code to parse



40
41
42
43
# File 'lib/theatre/callback_definition_loader.rb', line 40

def load_events_code(code)
  instance_eval code
  self
end

#load_events_file(file) ⇒ Object

Parses the given Ruby source code file and returns this object.

Parameters:

  • file (String, File)

    The filename or File object for the Ruby source code file to parse.



25
26
27
28
29
# File 'lib/theatre/callback_definition_loader.rb', line 25

def load_events_file(file)
  file = File.open(file) if file.kind_of? String
  instance_eval file.read, file.path
  self
end