Class: ActiveScaffold::Tableless

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

Defined Under Namespace

Modules: Association, CollectionAssociation, RelationExtension, SingularAssociation Classes: AssociationScope, Column, Connection, Relation, StatementCache

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveRecord::Base

#associated_valid?, #no_errors_in_associated?, #save_associated, #save_associated!, #to_label

Class Method Details

.column(name, sql_type = nil, options = {}) ⇒ Object



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

def self.column(name, sql_type = nil, options = {})
  column = Column.new(name.to_s, options[:default], sql_type.to_s, options.has_key?(:null) ? options[:null] : true)
  column.tap { columns << column }
end

.columnsObject



166
# File 'lib/active_scaffold/tableless.rb', line 166

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

.columns_hashObject



154
155
156
157
158
159
160
# File 'lib/active_scaffold/tableless.rb', line 154

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

.connectionObject



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

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

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



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

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



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

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

.find_one(id, relation) ⇒ Object



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

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

.initialize_find_by_cacheObject



161
162
163
# File 'lib/active_scaffold/tableless.rb', line 161

def self.initialize_find_by_cache
  self.find_by_statement_cache = Hash.new { |h, k| h[k] = StatementCache.new(k) }
end

.table_exists?Boolean

Returns:

  • (Boolean)


168
# File 'lib/active_scaffold/tableless.rb', line 168

def self.table_exists?; true; end

.table_nameObject



167
# File 'lib/active_scaffold/tableless.rb', line 167

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

Instance Method Details

#create_recordObject Also known as: create

:nodoc:



200
201
202
# File 'lib/active_scaffold/tableless.rb', line 200

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

#destroyObject



196
197
198
# File 'lib/active_scaffold/tableless.rb', line 196

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

#update_recordObject Also known as: update

:nodoc:



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

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