class Mongoid::Generators::ProxiedGenerator

Public Instance Methods

generate_model() click to toggle source
# File lib/generators/mongoid/proxied_generator.rb, line 11
def generate_model
  invoke "mongoid:model", [name] unless model_exists? && behavior == :invoke
end
inject_proxied_content() click to toggle source
# File lib/generators/mongoid/proxied_generator.rb, line 15
def inject_proxied_content
  inject_into_file model_path, model_contents, after: inject_after_pattern(:mongoid) if model_exists?
end
model_contents() click to toggle source
# File lib/generators/mongoid/proxied_generator.rb, line 19
      def model_contents
<<RUBY
  include Mongoid::Timestamps
  
  # Fields
  field :host, type: String
  field :ip_address, type: String
  field :port, type: Integer
  
  field :username, type: String
  field :password, type: String
  field :auth_mode, type: String, default: :credentials
  
  field :protocol, type: String, default: :http
  field :proxy_type, type: String, default: :public
  field :category, type: String
  
  field :country, type: String
  field :city, type: String
  
  field :valid_proxy, type: Boolean, default: false
  field :successful_attempts, type: Integer, default: 0
  field :failed_attempts, type: Integer, default: 0
  
  field :checkable, type: Boolean, default: true
  field :asyncable, type: Boolean, default: true
  
  field :last_checked_at, type: DateTime
  
  # Validations
  validates :host, presence: true, uniqueness: {scope: :port}
  
  # Indexes
  index({ host: 1, port: 1 }, { unique: true, drop_dups: true })
  index({ protocol: 1, proxy_type: 1, valid_proxy: -1, failed_attempts: 1 })
  index({ valid_proxy: 1 })
  
  # Methods
  include ::Proxied::Nosql::ProxyMethods
RUBY
      end