Sha256: 6543da1df23adfd4ba4c1feacc28f30f1c1eba3e01b93c257c61be780cdb2522

Contents?: true

Size: 907 Bytes

Versions: 41

Compression:

Stored size: 907 Bytes

Contents

module Cms
  module DataLoader
    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
    def create(model_name, record_name, data={})
      puts "-- create_#{model_name}(:#{record_name})"
      @data ||= {}
      @data[model_name.pluralize.to_sym] ||= {}
      model = model_name.classify.constantize.new(data)
      model.save!
      @data[model_name.pluralize.to_sym][record_name] = model
    end
  end
end

Version data entries

41 entries across 41 versions & 11 rubygems

Version Path
SFEley-browsercms-3.0.2 lib/cms/data_loader.rb
buzzware-browsercms-3.0.2 lib/cms/data_loader.rb
coredumplings-browsercms-3.0.0 lib/cms/data_loader.rb
nate-browsercms-3.0.210 lib/cms/data_loader.rb
nate-browsercms-3.0.211 lib/cms/data_loader.rb
we5-browsercms-3.0.1.1 lib/cms/data_loader.rb
webficient-browsercms-3.0.1 lib/cms/data_loader.rb
webficient-browsercms-3.0.2 lib/cms/data_loader.rb
webficient-browsercms-3.0.3 lib/cms/data_loader.rb
webficient-browsercms-3.0.4 lib/cms/data_loader.rb
browsercms-3.3.4 lib/cms/data_loader.rb
browsercms-3.3.3 lib/cms/data_loader.rb
browsercms-3.1.5 lib/cms/data_loader.rb
browsercms-3.1.4 lib/cms/data_loader.rb
browsercms-3.3.2 lib/cms/data_loader.rb
browsercms-3.3.1 lib/cms/data_loader.rb
browsercms-3.3.0 lib/cms/data_loader.rb
browsercms-3.1.3 lib/cms/data_loader.rb
browsercms-3.3.0.beta lib/cms/data_loader.rb
bf4-browsercms-3.1.0 lib/cms/data_loader.rb