Sha256: 6e36612fc43a0b7fd7617818bad88b94380b3d0020b0071ff3ca81860789d274

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

require 'arel/visitors/postgresql'

# We override some fun stuff in the PostgreSQL visitor class inside of Arel.
# This is the _most_ direct approach to tweaking the SQL to INSERT, SELECT,
# and UPDATE values as encrypted. Unfortunately, the visitor API doesn't
# give us access to managers as well as nodes, so we have use the public
# Arel API via the connection adapter's to_sql method. Then we tweak the
# more specific bits here!

Arel::Visitors::PostgreSQL.class_eval do
  alias :original_visit_Arel_Nodes_Assignment :visit_Arel_Nodes_Assignment
  def visit_Arel_Nodes_Assignment(assignment)
    # Hijack the normally inoccuous assignment that happens, seeing as how
    # Arel normally forwards this shit to someone else and I hate it. 
    if PGCrypto[assignment.left.relation.name][assignment.left.name]
      # raise "#{visit(assignment.left)} = #{visit(assignment.right)}"
      "#{visit(assignment.left)} = #{visit(assignment.right)}"
    else
      original_visit_Arel_Nodes_Assignment(assignment)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pgcrypto-0.0.4 lib/pgcrypto/arel.rb
pgcrypto-0.0.3 lib/pgcrypto/arel.rb
pgcrypto-0.0.2 lib/pgcrypto/arel.rb
pgcrypto-0.0.1 lib/pgcrypto/arel.rb