Module: Pancake::Mixins::StackHelper::ClassMethods

Defined in:
lib/pancake/mixins/stack_helper.rb

Instance Method Summary collapse

Instance Method Details

#stack_classObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pancake/mixins/stack_helper.rb', line 14

def stack_class
  return @_stack_class if @_stack_class
  klass = nil
  if name =~ /^\#<Class/
    raise "Could not determine the stack.  Make sure you declare global classes with a preceeding ::"
  end
  ns = name.split("::")
  until ns.empty? || klass
    r = ActiveSupport::Inflector.constantize(ns.join("::"))
    if r.ancestors.include?(::Pancake::Stack)
      klass = r
    else
      ns.pop
    end
  end
  if klass.nil?
    raise "#{name} is not from a stack" unless _stack_class
  else
    self._stack_class = r
  end
  _stack_class
end