Class: CompositePrimaryKeys::CompositeKeys

Inherits:
Array
  • Object
show all
Defined in:
lib/composite_primary_keys/composite_arrays.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(value) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/composite_primary_keys/composite_arrays.rb', line 25

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

Instance Method Details

#in(other) ⇒ Object



36
37
38
39
40
41
# File 'lib/composite_primary_keys/composite_arrays.rb', line 36

def in(other)
  case other
    when Arel::SelectManager
      Arel::Nodes::In.new(self, other.ast)
  end
end

#to_sObject



44
45
46
47
# File 'lib/composite_primary_keys/composite_arrays.rb', line 44

def to_s
  # Doing this makes it easier to parse Base#[](attr_name)
  join(ID_SEP)
end