Method: Cms::DataLoader#method_missing

Defined in:
lib/cms/data_loader.rb

#method_missing(method_name, *args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/cms/data_loader.rb', line 3

def method_missing(method_name, *args)
  if md = method_name.to_s.match(/^create_(.+)$/)
    begin
      #Make sure this is an active record class
      super unless md[1].classify.constantize.ancestors.include?(ActiveRecord::Base)
    rescue NameError => e
      super
    end
    self.create(md[1], args[0], args[1] || {})
  elsif @data && @data.has_key?(method_name)
    record = @data[method_name][args.first]
    record ? record.class.find(record.id) : nil
  else
    super
  end
end