Created
November 23, 2010 07:48
-
-
Save liwh/711422 to your computer and use it in GitHub Desktop.
定义抽象类,实现代码重构
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/models/abstract_server.rb | |
class AbstractServer < ActiveRecord::Base | |
self.abstract_class = true | |
validates_presence_of :name, :address, :username, :password, :encoding | |
validates_length_of :name, :maximum => 20, :allow_blank => true | |
validates_length_of :address, :maximum => 20, :allow_blank => true | |
validates_length_of :username, :password, :maximum => 20, :allow_blank => true | |
validates_length_of :encoding, :maximum => 10, :allow_blank => true | |
end | |
# app/models/server.rb | |
class Server < AbstractServer | |
# some other method | |
end | |
# app/models/sourcer.rb | |
class Sourcer < AbstractServer | |
# some other method | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment