lib/ocean/api_resource.rb
#
# This method implements the common behaviour in Ocean for requesting collections
# of resources, including conditions, +GROUP+ and substring searches. It can be used
# directly on a class:
#
#  @collection = ApiUser.collection(params)
#
# or on any Relation:
#
#  @collection = @api_user.groups.collection(params)
#
# Since a Relation is returned, further chaining is possible:
#
#  @collection = @api_user.groups.collection(params).active.order("email ASC")
#
# The whole params hash can safely be passed as the input arg: keys are filtered so 
# that matches only are done against the attributes declared in the controller using 
# +ocean_resource_model+. Ranges are allowed for those attributes declared to accept
# them using the +ranged+ parameter of +ocean_resource_model+.
#
# The +group:+ keyword arg, if present, adds a +GROUP+ clause to the generated SQL.
#
# The +search:+ keyword arg, if present, searches for the value in the database string or
# text column declared in the controller's +ocean_resource_model+ declaration.
# The search is done using an SQL +LIKE+ clause, with the substring framed by 
# wildcard characters. It's self-evident that this is not an efficient search method
# for larger datasets; in such cases, other search methods should be employed.
#
# If +page:+ is present, pagination will be added. If +page+ is less than zero, an
# empty Relation will be returned. Otherwise, +page_size:+ (default 25) will be used
# to calculate OFFSET and LIMIT. The default +page_size+ for a resource class can
# also be declared using +ocean_resource_model+.
#
# Right restrictions, if provided, will be added to the relation before it is
# returned.
#
This method implements the common behaviour in Ocean for requesting collections
of resources, including conditions, +GROUP+ and substring searches. It can be used
directly on a class.



or on any Relation.



Since a Relation is returned, further chaining is possible.



The whole params hash can safely be passed as the input arg: keys are filtered so
that matches only are done against the attributes declared in the controller using
+ocean_resource_model+. Ranges are allowed for those attributes declared to accept
them using the +ranged+ parameter of +ocean_resource_model+.

The +group:+ keyword arg, if present, adds a +GROUP+ clause to the generated SQL.

The +search:+ keyword arg, if present, searches for the value in the database string or
text column declared in the controller's +ocean_resource_model+ declaration.
The search is done using an SQL +LIKE+ clause, with the substring framed by
wildcard characters. It's self-evident that this is not an efficient search method
for larger datasets; in such cases, other search methods should be employed.

If +page:+ is present, pagination will be added. If +page+ is less than zero, an
empty Relation will be returned. Otherwise, +page_size:+ (default 25) will be used
to calculate OFFSET and LIMIT. The default +page_size+ for a resource class can
also be declared using +ocean_resource_model+.

Right restrictions, if provided, will be added to the relation before it is
returned.
This method implements the common behaviour in Ocean for requesting collections of resources including conditions + GROUP + and substring searches . It can be used directly on a class . or on any Relation . Since a Relation is returned further chaining is possible . The whole params hash can safely be passed as the input arg : keys are filtered so that matches only are done against the attributes declared in the controller using + ocean_resource_model + . Ranges are allowed for those attributes declared to accept them using the + ranged + parameter of + ocean_resource_model + . The + group : + keyword arg if present adds a + GROUP + clause to the generated SQL . The + search : + keyword arg if present searches for the value in the database string or text column declared in the controller ' s + ocean_resource_model + declaration . The search is done using an SQL + LIKE + clause with the substring framed by wildcard characters . It ' s self - evident that this is not an efficient search method for larger datasets ; in such cases other search methods should be employed . If + page : + is present pagination will be added . If + page + is less than zero an empty Relation will be returned . Otherwise + page_size : + ( default 25 ) will be used to calculate OFFSET and LIMIT . The default + page_size + for a resource class can also be declared using + ocean_resource_model + . Right restrictions if provided will be added to the relation before it is returned .
def collection_internal(conds={}, group, search, page, page_size, restrictions)
      if index_only != []
        new_conds = {}
        index_only.each do |key| 
          val = conds[key]
          next unless val
          if ranged_matchers.include?(key) && val.include?(",")
            new_conds[key] = parse_range(val)
          else
            new_conds[key] = parse_scalar(val)
          end
        end
        conds = new_conds
      end
      query = all.where(conds)
      query = query.group(group) if group.present? && index_only.include?(group.to_sym)
      if search.present?
        return query.none if index_search_property.blank?
        query = query.where("#{index_search_property} LIKE ?", "%#{search}%")
      end
      if page.present?
        page = page.to_i
        return query.none if page < 0
        page_size = page_size.to_i || collection_page_size
        query = query.limit(page_size).offset(page_size * page)
      end
      add_right_restrictions(query, restrictions) 
    end
def collection_internal ( conds = { } , group , search , page , page_size , restrictions ) if index_only != [ ] new_conds = { } index_only . each do | key | val = conds [ key ] next unless val if ranged_matchers . include? ( key ) && val . include? ( "," ) new_conds [ key ] = parse_range ( val ) else new_conds [ key ] = parse_scalar ( val ) end end conds = new_conds end query = all . where ( conds ) query = query . group ( group ) if group . present? && index_only . include? ( group . to_sym ) if search . present? return query . none if index_search_property . blank? query = query . where ( "#{index_search_property} LIKE ?" , "%#{search}%" ) end if page . present? page = page . to_i return query . none if page < 0 page_size = page_size . to_i || collection_page_size query = query . limit ( page_size ) . offset ( page_size * page ) end add_right_restrictions ( query , restrictions ) end
This method implements the common behaviour in Ocean for requesting collections
of resources, including conditions, +GROUP+ and substring searches.
This method implements the common behaviour in Ocean for requesting collections of resources including conditions + GROUP + and substring searches .
# Fold in the conditions # Take care of grouping # Searching # Pagination # Finally, add any app/context restrictions, then return the accumulated Relation
conds
group
search
page
page_size
restrictions