Sequel::Model:像create_table这样的方法从哪里来?
我想了解续集是如何运作的。下面的示例继承自 Sequel::Model 并调用 set_schema、create_table 等。
我试图找到这些方法的文档,但在 Sequel::Model 的 rdoc 上没有运气: http://sequel.rubyforge.org/rdoc/classes/Sequel/Model.html
这些方法来自哪里Sequel::Model 如何使它们可用?
class Task < Sequel::Model
set_schema do
primary_key :id
varchar :title, :unique => true, :empty => false
boolean :done, :default => false
end
create_table unless table_exists?
if empty?
create :title => 'Laundry'
create :title => 'Wash dishes'
end
end
I am trying to understand how Sequel works. The example below inherit from Sequel::Model and calls set_schema, create_table, etc.
I was trying to find the documentation for these methods, but no luck on the rdoc for Sequel::Model: http://sequel.rubyforge.org/rdoc/classes/Sequel/Model.html
Where are these methods coming from and how does Sequel::Model make them available?
class Task < Sequel::Model
set_schema do
primary_key :id
varchar :title, :unique => true, :empty => false
boolean :done, :default => false
end
create_table unless table_exists?
if empty?
create :title => 'Laundry'
create :title => 'Wash dishes'
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们在
Sequel::Plugins::Schema::ClassMethods
(lib/sequel/plugins/schema.rb) 中定义,并在您调用plugin :schema
时包含在模型。http://sequel.rubyforge.org/ rdoc-plugins/classes/Sequel/Plugins/Schema/ClassMethods.html#M000110
http://sequel.rubyforge.org/rdoc/classes/Sequel/Model.html#M000130
问题中的示例不完整,除非设置与数据库的连接,否则将无法工作并且从模型中调用
plugin :schema
。They're defined in
Sequel::Plugins::Schema::ClassMethods
(lib/sequel/plugins/schema.rb) and included when you callplugin :schema
in your model.http://sequel.rubyforge.org/rdoc-plugins/classes/Sequel/Plugins/Schema/ClassMethods.html#M000110
http://sequel.rubyforge.org/rdoc/classes/Sequel/Model.html#M000130
The example in the question is incomplete and won't work unless a connection to a database is setup and the
plugin :schema
is called from the model.