Module: Metro::Scenes
Overview
Instance Method Summary collapse
-
#add(scene) ⇒ Object
Add a scene to the hash of scenes with the scene name of the scene as the key to retrieving this scene.
-
#find(scene_name) ⇒ Object
Finds the scene based on the specified scene name.
-
#generate(scene_or_scene_name, options = {}) ⇒ Object
Finds the scene with the specified name and then creates an instance of that scene.
-
#generate_scene_from(scene_or_scene_name) ⇒ Object
If we have been given a scene, then we simply want to use it otherwise we need to find and generate our scene from the scene name.
-
#list ⇒ Array<String>
All the names supported by the scenes hash.
-
#post_filters ⇒ Object
Post filters are applied to the scene after it has been found.
-
#register_post_filter(post_filter) ⇒ Object
Register a filter that will be executed after a scene is found and generated.
Instance Method Details
#add(scene) ⇒ Object
Add a scene to the hash of scenes with the scene name of the scene as the key to retrieving this scene.
36 37 38 |
# File 'lib/metro/scenes.rb', line 36 def add(scene) all_scenes_for(scene).each { |scene| scenes_hash[scene.scene_name] = scene.to_s } end |
#find(scene_name) ⇒ Object
Finds the scene based on the specified scene name.
46 47 48 |
# File 'lib/metro/scenes.rb', line 46 def find(scene_name) scenes_hash[scene_name].constantize end |
#generate(scene_or_scene_name, options = {}) ⇒ Object
Finds the scene with the specified name and then creates an instance of that scene.
64 65 66 67 |
# File 'lib/metro/scenes.rb', line 64 def generate(scene_or_scene_name, = {}) new_scene = generate_scene_from(scene_or_scene_name) apply_post_filters(new_scene,) end |
#generate_scene_from(scene_or_scene_name) ⇒ Object
If we have been given a scene, then we simply want to use it otherwise we need to find and generate our scene from the scene name.
76 77 78 79 80 81 82 |
# File 'lib/metro/scenes.rb', line 76 def generate_scene_from(scene_or_scene_name) if scene_or_scene_name.is_a? Scene scene_or_scene_name else find(scene_or_scene_name).new end end |
#list ⇒ Array<String>
Returns all the names supported by the scenes hash.
53 54 55 |
# File 'lib/metro/scenes.rb', line 53 def list scenes_hash.keys end |
#post_filters ⇒ Object
Post filters are applied to the scene after it has been found. These are all objects that can respond to the #filter method.
88 89 90 |
# File 'lib/metro/scenes.rb', line 88 def post_filters @post_filters ||= [] end |
#register_post_filter(post_filter) ⇒ Object
Register a filter that will be executed after a scene is found and generated. This allows for the scene to be modified or changed based on the provided options.
A filter is any object that responds to #filter and accepts two parameters: the scene and a hash of options.
101 102 103 |
# File 'lib/metro/scenes.rb', line 101 def register_post_filter(post_filter) post_filters.push(post_filter) end |