Class: Mumukit::Hook

Inherits:
Object
  • Object
show all
Includes:
WithContentType
Defined in:
lib/mumukit/hook.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WithContentType

#content_type

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

#configObject (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(cookie_clazz)
  include Mumukit::Templates::WithCookie
  define_method :cookie_class do
    cookie_clazz
  end
end

Instance Method Details

#envObject

The rack ‘env`



20
21
22
# File 'lib/mumukit/hook.rb', line 20

def env
  Mumukit::Env.env
end

#loggerObject

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

Returns:

  • (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, **kwargs) ⇒ Object



10
11
12
# File 'lib/mumukit/hook.rb', line 10

def t(*args, **kwargs)
  I18n.t(*args, **kwargs)
end