Class: ActiveScaffold::Tableless
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ActiveScaffold::Tableless
show all
- Defined in:
- lib/active_scaffold/tableless.rb
Defined Under Namespace
Modules: Association, CollectionAssociation, RelationExtension, SingularAssociation, Tableless, TablelessCollectionAssociation, TablelessSingularAssociation
Classes: AssociationScope, Column, Connection, Relation, StatementCache
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.column(name, sql_type = nil, options = {}) ⇒ Object
225
226
227
228
|
# File 'lib/active_scaffold/tableless.rb', line 225
def self.column(name, sql_type = nil, options = {})
column = Column.new(name.to_s, options[:default], sql_type.to_s, options.key?(:null) ? options[:null] : true)
column.tap { columns << column }
end
|
208
209
210
|
# File 'lib/active_scaffold/tableless.rb', line 208
def self.columns
@tableless_columns ||= []
end
|
.columns_hash ⇒ Object
187
188
189
190
191
192
193
|
# File 'lib/active_scaffold/tableless.rb', line 187
def self.columns_hash
if self < ActiveScaffold::Tableless
@columns_hash ||= Hash[columns.map { |c| [c.name, c] }]
else
super
end
end
|
.connection ⇒ Object
221
222
223
|
# File 'lib/active_scaffold/tableless.rb', line 221
def self.connection
@connection ||= Connection.new(self)
end
|
.execute_simple_calculation(relation, operation, column_name, distinct) ⇒ Object
238
239
240
241
242
243
244
|
# File 'lib/active_scaffold/tableless.rb', line 238
def self.execute_simple_calculation(relation, operation, column_name, distinct)
if operation == 'count' && [relation.klass.primary_key, :all].include?(column_name)
find_all(relation).size
else
raise "self.execute_simple_calculation must be implemented in a Tableless model to support #{operation} #{column_name}#{' distinct' if distinct} columns"
end
end
|
.find_all(relation) ⇒ Object
230
231
232
|
# File 'lib/active_scaffold/tableless.rb', line 230
def self.find_all(relation)
raise 'self.find_all must be implemented in a Tableless model'
end
|
.find_one(id, relation) ⇒ Object
234
235
236
|
# File 'lib/active_scaffold/tableless.rb', line 234
def self.find_one(id, relation)
raise 'self.find_one must be implemented in a Tableless model'
end
|
.initialize_find_by_cache ⇒ Object
195
196
197
198
199
200
|
# File 'lib/active_scaffold/tableless.rb', line 195
def self.initialize_find_by_cache
@find_by_statement_cache = {
true => Hash.new { |h, k| h[k] = StatementCache.new(k) },
false => Hash.new { |h, k| h[k] = StatementCache.new(k) }
}
end
|
.table_exists? ⇒ Boolean
216
217
218
|
# File 'lib/active_scaffold/tableless.rb', line 216
def self.table_exists?
true
end
|
.table_name ⇒ Object
212
213
214
|
# File 'lib/active_scaffold/tableless.rb', line 212
def self.table_name
@table_name ||= ActiveModel::Naming.plural(self)
end
|
Instance Method Details
#_create_record ⇒ Object
Also known as:
create_record
250
251
252
|
# File 'lib/active_scaffold/tableless.rb', line 250
def _create_record run_callbacks(:create) {}
end
|
#_update_record ⇒ Object
Also known as:
update_record
255
256
257
|
# File 'lib/active_scaffold/tableless.rb', line 255
def _update_record(*) run_callbacks(:update) {}
end
|
246
247
248
|
# File 'lib/active_scaffold/tableless.rb', line 246
def destroy
raise 'destroy must be implemented in a Tableless model'
end
|