Class: BaseNew

Inherits:
Sequel::Model
  • Object
show all
Defined in:
app/models/base_new.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.install_dataObject

Callback when the initial data is setup to the database.



259
260
261
# File 'app/models/base_new.rb', line 259

def self.install_data
  install_data_hooks.each{|h| h.call }
end

.install_data_hooks(&blk) ⇒ Object

Add callbacks to setup the initial data. The hooks will be called when Model1.install_data() is called.

class Model1 < Base

install_data_hooks do
  Model1.create({:col1=>1, :col2=>2})
end

end



271
272
273
274
275
276
277
# File 'app/models/base_new.rb', line 271

def self.install_data_hooks(&blk)
  @install_data_hooks ||= []
  if blk
    @install_data_hooks << blk
  end
  @install_data_hooks
end

.Proxy(klass) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'app/models/base_new.rb', line 238

def self.Proxy(klass)
  colnames = klass.schema.columns.map {|i| i[:name] }
  colnames.delete_if(klass.primary_key) if klass.restrict_primary_key?
  s = ::Struct.new(*colnames) do
    def to_hash
      n = {}
      self.each_pair { |k,v|
        n[k.to_sym]=v
      }
      n
    end
  end
  s
end

Instance Method Details

#with_timestamps?Boolean

Returns true if this Model has time stamps

Returns:

  • (Boolean)


254
255
256
# File 'app/models/base_new.rb', line 254

def with_timestamps?
  self.columns.include?(:created_at) && self.columns.include?(:updated_at)
end