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

Instance Method Summary collapse

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

#contextObject

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_paramsObject

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_instructionsObject

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

Returns:

  • (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