Class: ActiveScaffold::Tableless

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/active_scaffold/tableless.rb

Overview

rubocop:disable Rails/ApplicationRecord

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



244
245
246
247
# File 'lib/active_scaffold/tableless.rb', line 244

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

.columnsObject



227
228
229
# File 'lib/active_scaffold/tableless.rb', line 227

def self.columns
  @tableless_columns ||= []
end

.columns_hashObject



207
208
209
210
211
212
213
# File 'lib/active_scaffold/tableless.rb', line 207

def self.columns_hash
  if self < ActiveScaffold::Tableless
    @columns_hash ||= Hash[columns.map { |c| [c.name, c] }]
  else
    super
  end
end

.connectionObject



240
241
242
# File 'lib/active_scaffold/tableless.rb', line 240

def self.connection
  @connection ||= Connection.new(self)
end

.execute_simple_calculation(relation, operation, column_name, distinct) ⇒ Object



257
258
259
260
261
262
# File 'lib/active_scaffold/tableless.rb', line 257

def self.execute_simple_calculation(relation, operation, column_name, distinct)
  unless operation == 'count' && [relation.klass.primary_key, :all].include?(column_name)
    raise "self.execute_simple_calculation must be implemented in a Tableless model to support #{operation} #{column_name}#{' distinct' if distinct} columns"
  end
  find_all(relation).size
end

.find_all(relation) ⇒ Object



249
250
251
# File 'lib/active_scaffold/tableless.rb', line 249

def self.find_all(relation)
  raise 'self.find_all must be implemented in a Tableless model'
end

.find_one(id, relation) ⇒ Object



253
254
255
# File 'lib/active_scaffold/tableless.rb', line 253

def self.find_one(id, relation)
  raise 'self.find_one must be implemented in a Tableless model'
end

.initialize_find_by_cacheObject

5.0 and 5.1



219
220
221
# File 'lib/active_scaffold/tableless.rb', line 219

def self.initialize_find_by_cache
  self.find_by_statement_cache = Hash.new { |h, k| h[k] = StatementCache.new(k) } # rubocop:disable Rails/DynamicFindBy
end

.table_exists?Boolean

Returns:

  • (Boolean)


235
236
237
# File 'lib/active_scaffold/tableless.rb', line 235

def self.table_exists?
  true
end

.table_nameObject



231
232
233
# File 'lib/active_scaffold/tableless.rb', line 231

def self.table_name
  @table_name ||= ActiveModel::Naming.plural(self)
end

Instance Method Details

#_create_recordObject

:nodoc:



268
269
270
# File 'lib/active_scaffold/tableless.rb', line 268

def _create_record #:nodoc:
  run_callbacks(:create) {}
end

#_update_recordObject

:nodoc:



272
273
274
# File 'lib/active_scaffold/tableless.rb', line 272

def _update_record(*) #:nodoc:
  run_callbacks(:update) {}
end

#destroyObject



264
265
266
# File 'lib/active_scaffold/tableless.rb', line 264

def destroy
  raise 'destroy must be implemented in a Tableless model'
end