Sha256: 7634bf1a57af1977fc148171945de55666e03b546f1c8812c3b3a07b5976c6de

Contents?: true

Size: 1.48 KB

Versions: 28

Compression:

Stored size: 1.48 KB

Contents

class SearchEngine < ActiveRecord::Base
  attr_accessible :name, :display_name, :url, :base_url, :http_method,
    :query_param, :additional_param, :note
  default_scope :order => "search_engines.position"
  acts_as_list

  validates :name, :presence => true
  validates :query_param, :presence => true
  validates :http_method, :presence => true, :inclusion => %w(get post)
  validates :url, :presence => true, :url => true, :length => {:maximum => 255}
  validates :base_url, :presence => true, :url => true, :length => {:maximum => 255}
  after_save :clear_all_cache
  after_destroy :clear_all_cache

  paginates_per 10

  def clear_all_cache
    Rails.cache.delete('search_engine_all')
  end

  def search_params(query)
    params = {}
    if self.additional_param
      self.additional_param.gsub('{query}', query).to_s.split.each do |param|
        p = param.split("=")
        params[p[0].to_sym] = p[1]
      end
      return params
    end
  end
end

# == Schema Information
#
# Table name: search_engines
#
#  id               :integer          not null, primary key
#  name             :string(255)      not null
#  display_name     :text
#  url              :string(255)      not null
#  base_url         :text             not null
#  http_method      :text             not null
#  query_param      :text             not null
#  additional_param :text
#  note             :text
#  position         :integer
#  created_at       :datetime         not null
#  updated_at       :datetime         not null
#

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
enju_library-0.1.0.pre33 app/models/search_engine.rb
enju_library-0.1.0.pre32 app/models/search_engine.rb
enju_library-0.1.0.pre31 app/models/search_engine.rb
enju_library-0.1.0.pre30 app/models/search_engine.rb
enju_library-0.1.0.pre29 app/models/search_engine.rb
enju_library-0.1.0.pre28 app/models/search_engine.rb
enju_library-0.1.0.pre27 app/models/search_engine.rb
enju_library-0.1.0.pre26 app/models/search_engine.rb
enju_library-0.1.0.pre25 app/models/search_engine.rb
enju_library-0.1.0.pre24 app/models/search_engine.rb
enju_library-0.1.0.pre23 app/models/search_engine.rb
enju_library-0.1.0.pre22 app/models/search_engine.rb
enju_library-0.1.0.pre21 app/models/search_engine.rb
enju_library-0.1.0.pre20 app/models/search_engine.rb
enju_library-0.1.0.pre19 app/models/search_engine.rb
enju_library-0.1.0.pre18 app/models/search_engine.rb
enju_library-0.1.0.pre17 app/models/search_engine.rb
enju_library-0.1.0.pre16 app/models/search_engine.rb
enju_library-0.1.0.pre15 app/models/search_engine.rb
enju_library-0.1.0.pre14 app/models/search_engine.rb