Module: Crystal::AbstractController::ClassMethods

Defined in:
lib/crystal/controller/abstract_controller.rb

Instance Method Summary collapse

Instance Method Details

#controller_context_classObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/crystal/controller/abstract_controller.rb', line 27

def controller_context_class
  unless @controller_context_class
    parent_context_class = nil
    ancestors[1..-1].each do |anc|            
      break if parent_context_class = anc.respond_to(:controller_context_class)
    end
    parent_context_class ||= Crystal::ControllerContext

    class_name = "#{self.name}::#{self.name.split('::').last}ControllerContext"

    # raise "Tempate context #{class_name} already defined!" if Object.const_defined? class_name
    eval "class #{class_name} < #{parent_context_class}; end", TOPLEVEL_BINDING, __FILE__, __LINE__
    @controller_context_class = class_name.constantize
  end
  @controller_context_class
end

#controller_nameObject



23
24
25
# File 'lib/crystal/controller/abstract_controller.rb', line 23

def controller_name
  self.namespace ? "#{self.namespace.name}/#{self.alias}" : self.alias
end

#helper(*args) ⇒ Object



44
45
46
47
48
49
# File 'lib/crystal/controller/abstract_controller.rb', line 44

def helper *args
  args.to_a.each do |mod| 
    mod.must_be.a Module
    controller_context_class.inherit mod
  end 
end

#helper_method(*args) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/crystal/controller/abstract_controller.rb', line 51

def helper_method *args
  args = args.first if args.size == 1 and args.first.is_a?(Array)
  # args.each{|m| m.to_s.must_be.in self.instance_methods}
  args.each do |m|          
    controller_context_class.delegate m, :to => :controller
  end      
end