Module: Screenplay::Cast
Overview
The Cast module is a singleton which is available for actors to register themselves and make themselves available.
Instance Method Summary collapse
Instance Method Details
#autoload ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/screenplay/cast.rb', line 28 def autoload # Require all standard actors Dir[File.dirname(__FILE__) + '/actors/*.rb'].each { | filename | require filename } ## Require custom actors @actors_path = $SCREENPLAY_ACTORS_DIR || Configuration[:general][:actors_dir] rescue File.join(Configuration.path, 'actors') Dir[@actors_path + '/**/*.rb'].each { | filename | require filename } ## Create an instance of each actor and register it to the cast Actor.descendants.each { | klass | name = klass.name.match(/(\w+)(Actor)?$/)[0].gsub(/Actor$/, '').snake_case register(klass.new(name)) } end |
#each ⇒ Object
17 18 19 |
# File 'lib/screenplay/cast.rb', line 17 def each @actors.each { | actor | yield actor } end |
#get(actor_name) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/screenplay/cast.rb', line 21 def get(actor_name) @actors.each { | actor | return actor if actor.name == actor_name.to_sym } return nil end |
#register(actor) ⇒ Object
11 12 13 14 15 |
# File 'lib/screenplay/cast.rb', line 11 def register(actor) raise "Actor #{actor.name} is already registered." if @actors.include?(actor.name) @actors.push(actor) @actors.sort_by!{ | actor | actor.name } end |