module GreyscaleRecord::Associations::Hasable

Public Instance Methods

additional_options() click to toggle source
# File lib/greyscale_record/associations/hasable.rb, line 18
def additional_options
  [ :as, :through ]
end
as() click to toggle source
# File lib/greyscale_record/associations/hasable.rb, line 32
def as
  opts[:as]
end
as?() click to toggle source
# File lib/greyscale_record/associations/hasable.rb, line 36
def as?
  opts.has_key? :as
end
query( instance ) click to toggle source
# File lib/greyscale_record/associations/hasable.rb, line 8
def query( instance )
  if through?
    { id: target_ids( instance ) }
  elsif as?
    { "#{as}_id" => instance.id }
  else
    { key => instance.id }
  end
end
target_ids( instance ) click to toggle source
# File lib/greyscale_record/associations/hasable.rb, line 40
def target_ids( instance )
  intermadiates = Array(instance.send( through ) )
  
  intermadiates.map do | intermediate | 
    intermediate.send( through_key )
  end
end
through() click to toggle source
# File lib/greyscale_record/associations/hasable.rb, line 24
def through
  opts[:through]
end
through?() click to toggle source
# File lib/greyscale_record/associations/hasable.rb, line 28
def through?
  opts.has_key? :through
end
through_key() click to toggle source
# File lib/greyscale_record/associations/hasable.rb, line 48
def through_key
  idify klass
end