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



94
95
96
97
98
# File 'lib/activerecord-tablefree.rb', line 94

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.



88
89
90
91
# File 'lib/activerecord-tablefree.rb', line 88

def column(name, sql_type = nil, default = nil, null = true)
  cast_type = "ActiveRecord::Type::#{sql_type.to_s.camelize}".constantize.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



100
101
102
103
104
105
106
107
# File 'lib/activerecord-tablefree.rb', line 100

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

#destroy_all(*_args) ⇒ Object



109
110
111
112
113
114
115
116
# File 'lib/activerecord-tablefree.rb', line 109

def destroy_all(*_args)
  case tablefree_options[:database]
  when :pretend_success
    []
  when :fail_fast
    raise NoDatabase.new("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.



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

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)


147
148
149
# File 'lib/activerecord-tablefree.rb', line 147

def table_exists?
  false
end

#tablefree?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/activerecord-tablefree.rb', line 143

def tablefree?
  true
end

#transaction(&block) ⇒ Object



133
134
135
136
137
138
139
140
141
# File 'lib/activerecord-tablefree.rb', line 133

def transaction(&block)
#        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