Method: ModelHelpers#class_at_path

Defined in:
lib/volt/models/model_helpers.rb

#class_at_path(path) ⇒ Object

Gets the class for a model at the specified path.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/volt/models/model_helpers.rb', line 24

def class_at_path(path)
  if path
    begin
      # remove the _ and then singularize
      if path.last == :[]
        klass_name = path[-2][1..-1].singularize.camelize
      else
        klass_name = path[-1][1..-1].singularize.camelize
      end

      klass = $page.model_classes[klass_name] || Model
    rescue NameError => e
      # Ignore exception, just means the model isn't defined
      klass = Model
    end
  else
    klass = Model
  end

  return klass
end