Module: CompositePrimaryKeys
- Defined in:
- lib/composite_primary_keys/version.rb,
lib/composite_primary_keys/composite_arrays.rb,
lib/composite_primary_keys/relation/batches.rb,
lib/composite_primary_keys/composite_relation.rb,
lib/composite_primary_keys/composite_predicates.rb,
lib/composite_primary_keys/relation/calculations.rb,
lib/composite_primary_keys/relation/query_methods.rb,
lib/composite_primary_keys/relation/finder_methods.rb,
lib/composite_primary_keys/associations/collection_association.rb
Defined Under Namespace
Modules: ActiveRecord, ArrayExtension, CollectionAssociation, CompositeRelation, Predicates, VERSION Classes: CompositeKeys
Constant Summary collapse
- ID_SEP =
','
- ID_SET_SEP =
';'
- ESCAPE_CHAR =
'^'
Class Method Summary collapse
-
.normalize(ids, cpk_size) ⇒ Object
Convert mixed representation of CPKs (by strings or arrays) to normalized representation (just by arrays).
Class Method Details
.normalize(ids, cpk_size) ⇒ Object
Convert mixed representation of CPKs (by strings or arrays) to normalized representation (just by arrays).
‘ids` is Array that may contain:
-
A CPK represented by an array or a string.
-
An array of CPKs represented by arrays or strings.
There is an issue. Let ‘ids` contain an array with serveral strings. We can’t distinguish case 1 from case 2 there in general. E.g. the item can be an array containing appropriate number of strings, and each string can contain appropriate number of commas. We consider case 2 to win there.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/composite_primary_keys/composite_arrays.rb', line 22 def self.normalize(ids, cpk_size) ids.map do |id| if Utils.cpk_as_array?(id, cpk_size) && id.any? { |item| !Utils.cpk_as_string?(item, cpk_size) } # CPK as an array - case 1 id elsif id.is_a?(Array) # An array of CPKs - case 2 normalize(id, cpk_size) elsif id.is_a?(String) # CPK as a string - case 1 CompositeKeys.parse(id) else id end end end |