Class: Engine2::TypeAheadMeta
- Inherits:
-
DecodeMeta
- Object
- Meta
- DecodeMeta
- Engine2::TypeAheadMeta
- Defined in:
- lib/engine2/meta/decode_meta.rb
Instance Attribute Summary
Attributes inherited from Meta
#action, #assets, #invokable, #static
Instance Method Summary collapse
Methods inherited from DecodeMeta
#decode, #post_process, #post_run, #separator, #show_max_selected
Methods included from MetaAPISupport
#config, #decorate, #field_filter, #hide_fields, #info, #info!, #loc!, #reload_routes!, #render, #show_fields
Methods included from MetaModelSupport
#action_defined, #get_type_info, #hide_pk, #show_pk, #unsupported_association
Methods included from MetaQuerySupport
#find_record, #get_query, #post_run, #query, #select
Methods inherited from Meta
#action_defined, #check_static_meta, #dynamic?, #freeze_meta, #get, http_method, #http_method, inherited, #initialize, #invoke!, #lookup, #merge, #meta_type, meta_type, #post_process, #post_run, #request, #request_meta_proc_params, #split_keys
Constructor Details
This class inherits a constructor from Engine2::Meta
Instance Method Details
#invoke(handler) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/engine2/meta/decode_meta.rb', line 73 def invoke handler if query = handler.params[:query] condition = (@meta[:decode_fields] || @meta[:fields]).map{|f|f.like("%#{query}%")}.inject{|q, f| q | f} {entries: get_query.where(condition).limit(@meta[:limit]).all} else handler.permit id = handler.params[:id] record = get_query[Hash[assets[:model].primary_keys.zip(split_keys(id))]] # handler.halt_not_found(LOCS[:no_entry]) unless record {entry: record} end end |
#limit(lmt) ⇒ Object
69 70 71 |
# File 'lib/engine2/meta/decode_meta.rb', line 69 def limit lmt @meta[:limit] = lmt end |
#pre_run ⇒ Object
64 65 66 67 |
# File 'lib/engine2/meta/decode_meta.rb', line 64 def pre_run super limit 10 end |