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



31
32
33
34
35
36
# File 'lib/mumukit/hook.rb', line 31

def self.stateful_through(cookie_clazz)
  include Mumukit::Templates::WithCookie
  define_method :cookie_class do
    cookie_clazz
  end
end

Instance Method Details

#envObject



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

def env
  Mumukit::Env.env
end

#loggerObject



23
24
25
# File 'lib/mumukit/hook.rb', line 23

def logger
  env['rack.logger']
end

#should_forward_to_config?(args, name) ⇒ Boolean

Returns:

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