Method: Sequel::Model::ClassMethods#def_Model
- Defined in:
- lib/sequel/model/base.rb
#def_Model(mod) ⇒ Object
Define a Model method on the given module that calls the Model method on the receiver. This is how the Sequel::Model() method is defined, and allows you to define Model() methods on other modules, making it easier to have custom model settings for all models under a namespace. Example:
module Foo
Model = Class.new(Sequel::Model)
Model.def_Model(self)
DB = Model.db = Sequel.connect(ENV['FOO_DATABASE_URL'])
Model.plugin :prepared_statements
class Bar < Model
# Uses Foo::DB[:bars]
end
class Baz < Model(:my_baz)
# Uses Foo::DB[:my_baz]
end
end
142 143 144 145 146 147 |
# File 'lib/sequel/model/base.rb', line 142 def def_Model(mod) model = self (class << mod; self; end).send(:define_method, :Model) do |source| model.Model(source) end end |