Sha256: 479b6578225ac220cb7d7e08e6ece0aa76f17faebff594815ebe33ef385175f3
Contents?: true
Size: 815 Bytes
Versions: 1
Compression:
Stored size: 815 Bytes
Contents
module CompositePrimaryKeys ID_SEP = ',' ID_SET_SEP = ';' module ArrayExtension def to_composite_keys CompositeKeys.new(self) end end def self.normalize(ids) ids.map do |id| if id.is_a?(Array) normalize(id) elsif id.is_a?(String) && id.index(ID_SEP) id.split(ID_SEP) else id end end end class CompositeKeys < Array def self.parse(value) case value when Array value.to_composite_keys when String self.new(value.split(ID_SEP)) else raise(ArgumentError, "Unsupported type: #{value}") end end def to_s # Doing this makes it easier to parse Base#[](attr_name) join(ID_SEP) end end end Array.send(:include, CompositePrimaryKeys::ArrayExtension)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
composite_primary_keys-8.1.0 | lib/composite_primary_keys/composite_arrays.rb |