Class: Xsdk::Scaffold::Rails::BaseSearch
- Inherits:
-
Object
- Object
- Xsdk::Scaffold::Rails::BaseSearch
- Defined in:
- lib/xsdk/scaffold/rails/base_search.rb
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(params, clazz) ⇒ BaseSearch
constructor
A new instance of BaseSearch.
- #search ⇒ Object
Constructor Details
#initialize(params, clazz) ⇒ BaseSearch
Returns a new instance of BaseSearch.
6 7 8 9 10 11 12 |
# File 'lib/xsdk/scaffold/rails/base_search.rb', line 6 def initialize(params, clazz) @clazz = clazz @query = "%#{params[:query]}%" @limit = params[:limit].try(:to_i) || 5 @columns = params[:columns] || %w[id] @source = @clazz.connection.quote_column_name(params[:source]) end |
Instance Method Details
#as_json ⇒ Object
14 15 16 |
# File 'lib/xsdk/scaffold/rails/base_search.rb', line 14 def as_json(*) search.as_json(only: @columns, methods: @columns) end |
#search ⇒ Object
18 19 20 |
# File 'lib/xsdk/scaffold/rails/base_search.rb', line 18 def search @clazz.where(" #{@source}::text ILIKE ? ", @query).limit(@limit) end |