lib/ocean-rails.rb
def add_right_restrictions(rel, restrictions)
  return rel unless restrictions
  # First get the table to use as a basis for the OR clauses
  t = rel.arel_table
  # Accumulating Arel AND clauses
  cond = restrictions.reduce [] do |acc, rr|
    app = rr['app']
    context = rr['context']
    if    app != '*' && context != '*'
      acc << t[:app].eq(app).and(t[:context].eq(context))
    elsif app != '*' && context == '*'
      acc << t[:app].eq(app)
    elsif app == '*' && context != '*'
      acc << t[:context].eq(context)
    end
    acc
  end
  # Process the clauses. We might not need to OR anything.
  case cond.length
  when 0
    return rel
  when 1
    return rel.where(cond.first)
  else
    # OR the multiple clauses together
    cond = cond.reduce :or
    # Return a relation built from the Arel condition we've constructed
    rel.where(cond)
  end
end
#
# Takes a relation and adds right restrictions, if present.
#
Takes a relation and adds right restrictions, if present.
Takes a relation and adds right restrictions if present .
def add_right_restrictions(rel, restrictions)
  return rel unless restrictions
  t = rel.arel_table
  cond = restrictions.reduce [] do |acc, rr|
    app = rr['app']
    context = rr['context']
    if    app != '*' && context != '*'
      acc << t[:app].eq(app).and(t[:context].eq(context))
    elsif app != '*' && context == '*'
      acc << t[:app].eq(app)
    elsif app == '*' && context != '*'
      acc << t[:context].eq(context)
    end
    acc
  end
  case cond.length
  when 0
    return rel
  when 1
    return rel.where(cond.first)
  else
    cond = cond.reduce :or
    rel.where(cond)
  end
end
def add_right_restrictions ( rel , restrictions ) return rel unless restrictions t = rel . arel_table cond = restrictions . reduce [ ] do | acc , rr | app = rr [ 'app' ] context = rr [ 'context' ] if app != '*' && context != '*' acc << t [ :app ] . eq ( app ) . and ( t [ :context ] . eq ( context ) ) elsif app != '*' && context == '*' acc << t [ :app ] . eq ( app ) elsif app == '*' && context != '*' acc << t [ :context ] . eq ( context ) end acc end case cond . length when 0 return rel when 1 return rel . where ( cond . first ) else cond = cond . reduce :or rel . where ( cond ) end end
Takes a relation and adds right restrictions, if present.
Takes a relation and adds right restrictions if present .
# First get the table to use as a basis for the OR clauses # Accumulating Arel AND clauses # Process the clauses. We might not need to OR anything. # OR the multiple clauses together # Return a relation built from the Arel condition we've constructed
rel
restrictions