Module: ActiveRecord::Tableless::SingletonMethods

Defined in:
lib/activerecord-tableless.rb

Instance Method Summary collapse

Instance Method Details

#add_columns(sql_type, *args) ⇒ Object

Register a set of columns with the same SQL type



101
102
103
104
105
# File 'lib/activerecord-tableless.rb', line 101

def add_columns(sql_type, *args)
  args.each do |col|
    column col, sql_type
  end
end

#column(name, sql_type = nil, default = nil, null = true) ⇒ Object



91
92
93
# File 'lib/activerecord-tableless.rb', line 91

def column(name, sql_type = nil, default = nil, null = true)
  tableless_options[:columns] << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, Type::Value.new, sql_type.to_s, null)
end

#columnsObject

Return the list of columns registered for the model. Used internally by ActiveRecord



84
85
86
# File 'lib/activerecord-tableless.rb', line 84

def columns
  tableless_options[:columns]
end

#destroy(*args) ⇒ Object



107
108
109
110
111
112
113
114
# File 'lib/activerecord-tableless.rb', line 107

def destroy(*args)
  case tableless_options[:database]
  when :pretend_success
    self.new()
  when :fail_fast
    raise NoDatabase.new("Can't #destroy on Tableless class")
  end
end

#destroy_all(*args) ⇒ Object



116
117
118
119
120
121
122
123
# File 'lib/activerecord-tableless.rb', line 116

def destroy_all(*args)
  case tableless_options[:database]
  when :pretend_success
    []
  when :fail_fast
    raise NoDatabase.new("Can't #destroy_all on Tableless class")
  end
end

#table_exists?Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/activerecord-tableless.rb', line 164

def table_exists?
  false
end

#tableless?Boolean

Returns:

  • (Boolean)


160
161
162
# File 'lib/activerecord-tableless.rb', line 160

def tableless?
  true
end

#transaction(&block) ⇒ Object



150
151
152
153
154
155
156
157
158
# File 'lib/activerecord-tableless.rb', line 150

def transaction(&block)
#        case tableless_options[:database]
#        when :pretend_success
    @_current_transaction_records ||= []
    yield
#        when :fail_fast
#          raise NoDatabase.new("Can't #transaction on Tableless class")
#        end
end