Class: Dcmgr::Models::BaseNew
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Dcmgr::Models::BaseNew
- Defined in:
- lib/dcmgr/models/base_new.rb
Direct Known Subclasses
Account, AccountResource, FrontendSystem, InstanceNetfilterGroup, InstanceNic, IpLease, NetfilterRule, Network, RequestLog, Tag, TagMapping
Constant Summary collapse
- LOCK_TABLES_KEY =
'__locked_tables'
Class Method Summary collapse
- .dataset ⇒ Object
-
.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.
- .lock! ⇒ Object
- .Proxy(klass) ⇒ Object
- .unlock! ⇒ Object
Class Method Details
.dataset ⇒ Object
279 280 281 282 283 284 285 286 287 |
# File 'lib/dcmgr/models/base_new.rb', line 279 def self.dataset locktbls = Thread.current[LOCK_TABLES_KEY] if locktbls && locktbls[self.db.uri.to_s + @dataset.first_source_alias.to_s] @dataset.opts = @dataset.opts.merge({:lock=>:update}) else @dataset.opts = @dataset.opts.merge({:lock=>nil}) end @dataset end |
.install_data ⇒ Object
Callback when the initial data is setup to the database.
308 309 310 |
# File 'lib/dcmgr/models/base_new.rb', line 308 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
320 321 322 323 324 325 326 |
# File 'lib/dcmgr/models/base_new.rb', line 320 def self.install_data_hooks(&blk) @install_data_hooks ||= [] if blk @install_data_hooks << blk end @install_data_hooks end |
.lock! ⇒ Object
265 266 267 268 269 270 |
# File 'lib/dcmgr/models/base_new.rb', line 265 def self.lock! locktbls = Thread.current[LOCK_TABLES_KEY] if locktbls locktbls[self.db.uri.to_s + @dataset.first_source_alias.to_s]=1 end end |
.Proxy(klass) ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/dcmgr/models/base_new.rb', line 291 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 |
.unlock! ⇒ Object
272 273 274 275 276 277 |
# File 'lib/dcmgr/models/base_new.rb', line 272 def self.unlock! locktbls = Thread.current[LOCK_TABLES_KEY] if locktbls locktbls.delete(self.db.uri.to_s + @dataset.first_source_alias.to_s) end end |