Module: Poro::Context::FindMethods::HelperMethods
- Defined in:
- lib/poro/context.rb
Overview
Contains some private helper methods to help process finds. These rarely need to be used or overriden by Context subclasses.
Instance Method Summary collapse
-
#clean_find_opts(opts) ⇒ Object
Cleans the find opts.
-
#hashize_limit(limit_opt) ⇒ Object
Takes the limit option to find and returns a uniform hash version of it.
-
#hashize_order(order_opt) ⇒ Object
Takes the order option to find and returns a uniform hash version of it.
Instance Method Details
#clean_find_opts(opts) ⇒ Object
Cleans the find opts. This makes it so that no matter which (legal) style that they give their options to find, they are made into a single standard format that the subclasses can depend on.
344 345 346 347 348 349 |
# File 'lib/poro/context.rb', line 344 def clean_find_opts(opts) cleaned_opts = opts.dup cleaned_opts[:limit] = hashize_limit(opts[:limit]) if opts.has_key?(:limit) cleaned_opts[:order] = hashize_order(opts[:order]) if opts.has_key?(:order) return cleaned_opts end |
#hashize_limit(limit_opt) ⇒ Object
Takes the limit option to find and returns a uniform hash version of it.
The hash has the form:
{:limit => (integer || nil), :offset => (integer)}
Note that a limit of nil means that all records shoudl be returned.
357 358 359 360 361 362 363 364 365 |
# File 'lib/poro/context.rb', line 357 def hashize_limit(limit_opt) if( limit_opt.kind_of?(Hash) ) return {:limit => nil, :offset => 0}.merge(limit_opt) elsif( limit_opt.kind_of?(Array) ) return {:limit => limit_opt[0], :offset => limit_opt[1]||0} else return {:limit => (limit_opt&&limit_opt.to_i), :offset => 0} end end |
#hashize_order(order_opt) ⇒ Object
Takes the order option to find and returns a uniform hash version of it.
Returns a hash of each sort key followed by either :asc or :desc. If there are no sort keys, this returns an empty hash.
371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/poro/context.rb', line 371 def hashize_order(order_opt) if( order_opt.kind_of?(Hash) ) return order_opt elsif( order_opt.kind_of?(Array) ) return order_opt.inject({}) {|hash,(key,direction)| hash[key] = direction || :asc; hash} elsif( order_opt.nil? ) return {} else return {order_opt => :asc} end end |