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::PrecompileHook, Defaults::QueryHook, Defaults::TestHook, Defaults::TryHook, Defaults::ValidationHook, Templates::ExpectationsHook, Templates::FileHook, Templates::MultiFilePrecompileHook
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
-
#env ⇒ Object
The rack ‘env`.
-
#initialize(config = nil) ⇒ Hook
constructor
A new instance of Hook.
-
#logger ⇒ Object
The rack ‘env` logger.
- #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 |
Class Method Details
.stateful_through(cookie_clazz) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/mumukit/hook.rb', line 36 def self.stateful_through() include Mumukit::Templates::WithCookie define_method :cookie_class do end end |
Instance Method Details
#env ⇒ Object
The rack ‘env`
20 21 22 |
# File 'lib/mumukit/hook.rb', line 20 def env Mumukit::Env.env end |
#logger ⇒ Object
The rack ‘env` logger.
Use ‘Mumukit::Env.logger` or `Mumukit::Env.root_logger` if you need a logger outside a hook context
28 29 30 |
# File 'lib/mumukit/hook.rb', line 28 def logger Mumukit::Env.rack_logger end |
#should_forward_to_config?(args, name) ⇒ Boolean
32 33 34 |
# File 'lib/mumukit/hook.rb', line 32 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 |