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



189
190
191
192
# File 'lib/active_scaffold/tableless.rb', line 189

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



172
173
174
# File 'lib/active_scaffold/tableless.rb', line 172

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

.connectionObject



185
186
187
# File 'lib/active_scaffold/tableless.rb', line 185

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

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



202
203
204
205
206
207
# File 'lib/active_scaffold/tableless.rb', line 202

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



194
195
196
# File 'lib/active_scaffold/tableless.rb', line 194

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

.find_one(id, relation) ⇒ Object



198
199
200
# File 'lib/active_scaffold/tableless.rb', line 198

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

.table_exists?Boolean

Returns:

  • (Boolean)


180
181
182
# File 'lib/active_scaffold/tableless.rb', line 180

def self.table_exists?
  true
end

.table_nameObject



176
177
178
# File 'lib/active_scaffold/tableless.rb', line 176

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

Instance Method Details

#_create_recordObject

:nodoc:



213
214
215
# File 'lib/active_scaffold/tableless.rb', line 213

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

#_update_recordObject

:nodoc:



217
218
219
# File 'lib/active_scaffold/tableless.rb', line 217

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

#destroyObject



209
210
211
# File 'lib/active_scaffold/tableless.rb', line 209

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