Module: PictureTag::Router
- Included in:
- PictureTag
- Defined in:
- lib/jekyll_picture_tag/router.rb
Overview
The rest of the application doesn't care where the instruction logic resides. This module 'routes' method calls to the right place, so information consumers can just call 'PictureTag.(some method)'
This is accomplished with a bit of metaprogramming, which is hopefully not unnecessarily clever or complicated. Missing methods are converted to class names, which are looked up under the Instructions module namespace.
Instantiated Instructions are stored in a hash, keyed by method name.
Instance Attribute Summary collapse
-
#context ⇒ Object
These two attributes encompass everything passed in by Jekyll.
-
#raw_params ⇒ Object
These two attributes encompass everything passed in by Jekyll.
Instance Method Summary collapse
-
#clear_instructions ⇒ Object
Required at least for testing; instructions are persisted between tags otherwise.
- #method_missing(method_name, *args) ⇒ Object
- #respond_to_missing?(method_name, *args) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/jekyll_picture_tag/router.rb', line 15 def method_missing(method_name, *args) if instruction_exists?(method_name) instruction(method_name).value(*args) else super end end |
Instance Attribute Details
#context ⇒ Object
These two attributes encompass everything passed in by Jekyll.
13 14 15 |
# File 'lib/jekyll_picture_tag/router.rb', line 13 def context @context end |
#raw_params ⇒ Object
These two attributes encompass everything passed in by Jekyll.
13 14 15 |
# File 'lib/jekyll_picture_tag/router.rb', line 13 def raw_params @raw_params end |
Instance Method Details
#clear_instructions ⇒ Object
Required at least for testing; instructions are persisted between tags otherwise.
29 30 31 |
# File 'lib/jekyll_picture_tag/router.rb', line 29 def clear_instructions instructions.clear end |
#respond_to_missing?(method_name, *args) ⇒ Boolean
23 24 25 |
# File 'lib/jekyll_picture_tag/router.rb', line 23 def respond_to_missing?(method_name, *args) instruction_exists?(method_name) || super end |