Class: Mumukit::Hook
- Inherits:
-
Object
- Object
- Mumukit::Hook
- Includes:
- WithContentType
- Defined in:
- lib/mumukit/hook.rb
Direct Known Subclasses
Defaults::ExpectationsHook, Defaults::FeedbackHook, Defaults::MetadataHook, Defaults::QueryHook, Defaults::TestHook, Defaults::ValidationHook, Templates::FileHook
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #env ⇒ Object
-
#initialize(config = nil) ⇒ Hook
constructor
A new instance of Hook.
- #logger ⇒ Object
- #method_missing(name, *args, &block) ⇒ Object
- #should_forward_to_config?(args, name) ⇒ Boolean
- #t(*args) ⇒ Object
Methods included from WithContentType
Constructor Details
#initialize(config = nil) ⇒ Hook
Returns a new instance of Hook.
6 7 8 |
# File 'lib/mumukit/hook.rb', line 6 def initialize(config=nil) @config = (config||{}).with_indifferent_access end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
14 15 16 17 |
# File 'lib/mumukit/hook.rb', line 14 def method_missing(name, *args, &block) super unless should_forward_to_config?(args, name, &block) @config[name] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
2 3 4 |
# File 'lib/mumukit/hook.rb', line 2 def config @config end |
Instance Method Details
#logger ⇒ Object
23 24 25 |
# File 'lib/mumukit/hook.rb', line 23 def logger env['rack.logger'] end |
#should_forward_to_config?(args, name) ⇒ Boolean
27 28 29 |
# File 'lib/mumukit/hook.rb', line 27 def should_forward_to_config?(args, name) args.length == 0 && !block_given? && @config[name] end |
#t(*args) ⇒ Object
10 11 12 |
# File 'lib/mumukit/hook.rb', line 10 def t(*args) I18n.t(*args) end |