canvas-lms/app/models/tableless.rb

50 lines
1.5 KiB
Ruby
Raw Normal View History

2011-02-01 09:57:29 +08:00
#
# Copyright (C) 2011 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# allows you to have models that do not have database tables
# concept pulled from the comments of this page:
# http://stackoverflow.com/questions/937429/activerecordbase-without-table-rails
class Tableless < ActiveRecord::Base
attr_accessible
2011-02-01 09:57:29 +08:00
def self.columns
@columns ||= [];
end
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default,
sql_type.to_s, null)
end
# Override the save method to prevent exceptions.
def save(validate = true)
validate ? valid? : true
end
def self.tableless?
true
end
def self.find_by_sql(*args); []; end
def self.count_by_sql(*args); 0; end
def self.delete_all(*args); end
def self.update_all(*args); end
def self.execute_simple_calculation(*args); end
def self.execute_grouped_calculation(*args); end
2011-02-01 09:57:29 +08:00
end