Class: BaseNew
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- BaseNew
- Defined in:
- app/models/base_new.rb
Direct Known Subclasses
Account, Authz, Information, Tag, TagMapping, User
Class Method Summary collapse
-
.install_data ⇒ Object
Callback when the initial data is setup to the database.
-
.install_data_hooks(&blk) ⇒ Object
Add callbacks to setup the initial data.
- .Proxy(klass) ⇒ Object
Class Method Details
.install_data ⇒ Object
Callback when the initial data is setup to the database.
250 251 252 |
# File 'app/models/base_new.rb', line 250 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
262 263 264 265 266 267 268 |
# File 'app/models/base_new.rb', line 262 def self.install_data_hooks(&blk) @install_data_hooks ||= [] if blk @install_data_hooks << blk end @install_data_hooks end |
.Proxy(klass) ⇒ Object
233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'app/models/base_new.rb', line 233 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 |