lib/core/lorj_basecontroller.rb
# controller helper function:
# This helper controller function helps to query and object list
# from a Lorj query Hash. See query Hash details in #ctrl_query_match.
#
# * *args*:
#   - +objects+ : Collection of object which respond to each
#   - +query+   : Hash. Containing a list of attributes to test
#     See #ctrl_do_query_match for details
#   - +triggers+: Hash. Optional. Procs to interact at several places:
#     - :before  : &code(object) - To execute some code on the object
#       before extract.
#       *return* true to go on, or false to ignore the object.
#     - :after   : &code(object, query, selected) - To execute some code on
#       the object after extract.
#       This after trigger is the last change to select or not the object
#       for the query. Note that query structure defined by lorj by default.
#       *return* true if the object is selected. false otherwise.
#     - :extract : &code(object, key) - To execute the data extraction
#       This block is required only if call of [] or :<key> is not supported
#       *return* the value extracted.
#
controller helper function:
This helper controller function helps to query and object list
from a Lorj query Hash. See query Hash details in #ctrl_query_match.

*args*:
+objects+ : Collection of object which respond to each
+query+   : Hash. Containing a list of attributes to test
See #ctrl_do_query_match for details
+triggers+: Hash. Optional. Procs to interact at several places:
:before  : &code(object) - To execute some code on the object
before extract.
return* true to go on, or false to ignore the object.
:after   : &code(object, query, selected) - To execute some code on
the object after extract.
This after trigger is the last change to select or not the object
for the query. Note that query structure defined by lorj by default.
return* true if the object is selected. false otherwise.
:extract : &code(object, key) - To execute the data extraction
This block is required only if call of [] or : is not supported
return* the value extracted.
controller helper function : This helper controller function helps to query and object list from a Lorj query Hash . See query Hash details in #ctrl_query_match . * args * : + objects + : Collection of object which respond to each + query + : Hash . Containing a list of attributes to test See #ctrl_do_query_match for details + triggers + : Hash . Optional . Procs to interact at several places : : before : &code ( object ) - To execute some code on the object before extract . return * true to go on or false to ignore the object . : after : &code ( object query selected ) - To execute some code on the object after extract . This after trigger is the last change to select or not the object for the query . Note that query structure defined by lorj by default . return * true if the object is selected . false otherwise . : extract : &code ( object key ) - To execute the data extraction This block is required only if call of [] or : is not supported return * the value extracted .
def ctrl_query_each(objects, query, triggers = {}) 
      results = []
      Lorj.debug(4, "Filtering with '%s'", query)
      unless objects.class.method_defined?(:each)
        controller_error "'%s' do not have 'each' function.", objects.class
      end
      objects.each do |o|
        trig_ret = _run_trigger(triggers, :before, [TrueClass, FalseClass],
                                true, o, query)
        next unless trig_ret
        if [Proc, Method].include?(triggers[:extract].class)
          code = triggers[:extract]
          selected = ctrl_do_query_match(o, query) { |d, k| code.call d, k }
        else
          selected = ctrl_do_query_match(o, query)
        end
        selected = _run_trigger(triggers, :after, [TrueClass, FalseClass],
                                selected, o, query, selected)
        results.push o if selected
      end
      Lorj.debug(4, '%d records selected', results.length)
      results
    end
def ctrl_query_each ( objects , query , triggers = { } ) results = [ ] Lorj . debug ( 4 , "Filtering with '%s'" , query ) unless objects . class . method_defined? ( :each ) controller_error "'%s' do not have 'each' function." , objects . class end objects . each do | o | trig_ret = _run_trigger ( triggers , :before , [ TrueClass , FalseClass ] , true , o , query ) next unless trig_ret if [ Proc , Method ] . include? ( triggers [ :extract ] . class ) code = triggers [ :extract ] selected = ctrl_do_query_match ( o , query ) { | d , k | code . call d , k } else selected = ctrl_do_query_match ( o , query ) end selected = _run_trigger ( triggers , :after , [ TrueClass , FalseClass ] , selected , o , query , selected ) results . push o if selected end Lorj . debug ( 4 , '%d records selected' , results . length ) results end
controller helper function:
This helper controller function helps to query and object list
from a Lorj query Hash.
controller helper function : This helper controller function helps to query and object list from a Lorj query Hash .
# :doc:
objects
<not_specific>
query
<not_specific>
triggers
<not_specific>