Module: ActiveRecord::Tablefree::SingletonMethods

Defined in:
lib/activerecord/tablefree.rb

Instance Method Summary collapse

Instance Method Details

#add_columns(sql_type, *args) ⇒ Object

Register a set of columns with the same SQL type


97
98
99
100
101
# File 'lib/activerecord/tablefree.rb', line 97

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

Register a new column.

Raises:


89
90
91
92
93
94
# File 'lib/activerecord/tablefree.rb', line 89

def column(name, sql_type = nil, default = nil, null = true)
  cast_class = "ActiveRecord::Type::#{sql_type.to_s.camelize}".constantize rescue nil
  raise InvalidColumnType, "sql_type is #{sql_type} (#{sql_type.class}), which is not supported" unless cast_class.respond_to?(:new)
  cast_type = cast_class.new
  tablefree_options[:columns_hash][name.to_s] = ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, cast_type, sql_type.to_s, null)
end

#destroy(*_args) ⇒ Object


103
104
105
106
107
108
109
110
# File 'lib/activerecord/tablefree.rb', line 103

def destroy(*_args)
  case tablefree_options[:database]
  when :pretend_success
    new
  when :fail_fast
    raise NoDatabase, "Can't #destroy on Tablefree class"
  end
end

#destroy_all(*_args) ⇒ Object


112
113
114
115
116
117
118
119
# File 'lib/activerecord/tablefree.rb', line 112

def destroy_all(*_args)
  case tablefree_options[:database]
  when :pretend_success
    []
  when :fail_fast
    raise NoDatabase, "Can't #destroy_all on Tablefree class"
  end
end

#load_schema!Object

Used internally by ActiveRecord 5. This is the special hook that makes everything else work.


76
77
78
79
80
81
82
83
84
85
86
# File 'lib/activerecord/tablefree.rb', line 76

def load_schema!
  @columns_hash = tablefree_options[:columns_hash].except(*ignored_columns)
  @columns_hash.each do |name, column|
    define_attribute(
      name,
      connection.lookup_cast_type_from_column(column),
      default: column.default,
      user_provided_default: false
    )
  end
end

#table_exists?Boolean

Returns:

  • (Boolean)

149
150
151
# File 'lib/activerecord/tablefree.rb', line 149

def table_exists?
  false
end

#tablefree?Boolean

Returns:

  • (Boolean)

145
146
147
# File 'lib/activerecord/tablefree.rb', line 145

def tablefree?
  true
end

#transactionObject


135
136
137
138
139
140
141
142
143
# File 'lib/activerecord/tablefree.rb', line 135

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