Class: Engine2::TypeAheadAction
- Inherits:
-
DecodeAction
- Object
- Action
- DecodeAction
- Engine2::TypeAheadAction
- Defined in:
- lib/engine2/action/decode.rb
Instance Attribute Summary
Attributes inherited from Action
#assets, #invokable, #meta, #node, #static
Instance Method Summary collapse
- #case_insensitive ⇒ Object
- #get_case_insensitive ⇒ Object
- #get_limit ⇒ Object
- #invoke(handler) ⇒ Object
- #limit(lmt) ⇒ Object
- #order(*fields) ⇒ Object
- #pre_run ⇒ Object
Methods inherited from DecodeAction
#decode, #post_process, #post_run, #separator, #show_max_selected
Methods included from ActionAPISupport
#config, #decorate, #field_filter, #fields, #fields!, #hide_fields, #loc!, #render, #show_fields
Methods included from ActionModelSupport
#hide_pk, #node_defined, #show_pk, #unsupported_association
Methods included from ActionQuerySupport
#find_record, #get_query, #post_run, #query, #select
Methods inherited from Action
action_type, #action_type, #arguments, #check_anonymous_action_class, #check_static_action, #define_invoke, #define_method, #dynamic?, #execute, #freeze_action, #http_method, http_method, inherit, inherited, #initialize, #invoke!, #join_keys, #lookup, #merge, #node_defined, #post_process, #post_run, #repeat, #request, #request_action_proc_params, #split_keys
Constructor Details
This class inherits a constructor from Engine2::Action
Instance Method Details
#case_insensitive ⇒ Object
86 87 88 |
# File 'lib/engine2/action/decode.rb', line 86 def case_insensitive @case_insensitive = true end |
#get_case_insensitive ⇒ Object
82 83 84 |
# File 'lib/engine2/action/decode.rb', line 82 def get_case_insensitive @case_insensitive end |
#get_limit ⇒ Object
78 79 80 |
# File 'lib/engine2/action/decode.rb', line 78 def get_limit @limit end |
#invoke(handler) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/engine2/action/decode.rb', line 94 def invoke handler model = assets[:model] if query = handler.params[:query] fields = @meta[:decode_fields] || static.[:decode_fields] entries = if query.to_s.empty? get_query else table_name = model.table_name condition = fields.map{|f|table_name.q(f).like("%#{query}%", case_insensitive: @case_insensitive || static.get_case_insensitive)}.reduce{|q, f| q | f} get_query.where(condition) end.limit(@limit || static.get_limit).load_all {entries: entries} else handler.permit id = handler.params[:id] record = get_query.unordered.load Hash[model.primary_keys_qualified.zip(split_keys(id))] # handler.halt_not_found(LOCS[:no_entry]) unless record {entry: record} end end |
#limit(lmt) ⇒ Object
74 75 76 |
# File 'lib/engine2/action/decode.rb', line 74 def limit lmt @limit = lmt end |
#order(*fields) ⇒ Object
90 91 92 |
# File 'lib/engine2/action/decode.rb', line 90 def order *fields @query = get_query.order *fields end |
#pre_run ⇒ Object
69 70 71 72 |
# File 'lib/engine2/action/decode.rb', line 69 def pre_run super @limit = 10 end |