New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

acts_as_scrubbable

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

acts_as_scrubbable

  • 2.1.5
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

ActsAsScrubbable

Scrubbing made easy

Acts as scrubbable give you model level access to scrub your data per object.

It runs using the parallel gem for faster processing which is dependent on the amount of cores available on the box. More cores == faster scrubbing

Installation

gem 'acts_as_scrubbable'

Usage

Simple add the configuration for your fields that map directly to your columns

class User < ActiveRecord::Base
  ...

  acts_as_scrubbable :first_name, :last_name


  # optionally you can add a scope to limit the rows to update
  scope :scrubbable_scope, -> { where(some_value: true) }

  ...
end

Incase the mapping is not straight forward

class Address
  acts_as_scrubbable :lng => :longitude, :lat => :latitude
end

To run

The confirmation message will be the db host

rake scrub

....
2015-11-19 10:52:51 -0800: [WARN] - Please verify the information below to continue
2015-11-19 10:52:51 -0800: [WARN] - Host:  127.0.0.1
2015-11-19 10:52:51 -0800: [WARN] - Database: blog_development
Type '127.0.0.1' to continue.
-> 127.0.0.1
2015-11-19 10:52:51 -0800: [WARN] -- : Scrubbing classes
2015-11-19 10:52:51 -0800: [WARN] -- : Scrubbing ClassToScrub
...
2015-11-19 10:52:51 -0800: [WARN] -- : Scrub Complete!

In the case you are automating the rake task and want to skip the confirmation

rake scrub SKIP_CONFIRM=true

If you want to limit the classes you to be scrubbed you can set the SCRUB_CLASSES variable

rake scrub SCRUB_CLASSES=Blog,Post

If you want to skip the afterhook

rake scrub SKIP_AFTERHOOK=true

Extending

You may find the need to extend or add additional generators or an after_hook

ActsAsScrubbable.configure do |c|
  c.add :email_with_prefix, -> { "prefix-#{Faker::Internet.email}" }

  c.after_hook do
    puts "Running after commit"
    ActiveRecord::Base.connection.execute("TRUNCATE some_table")
  end
end

UPDATE VS UPSERT

By default, the scrubbing proces will run independent UPDATE statements for each scrubbed model. This can be time consuming if you are scrubbing a large number of records. As an alternative, some databases support doing bulk database updates using an upsert using the INSERT command. activerecord-import gives us easy support for this and as such it is a requirement to using this feature. Some details about the implementation can be found here. https://github.com/zdennis/activerecord-import#duplicate-key-update

Note that we only support the MySQL implementation at this time.

To use UPSERT over UPDATE, it can be enabled by specifying the environment variable USE_UPSERT='true' or through configuration.

ActsAsScrubbable.configure do |c|
  c.use_upsert = true
end

FAQs

Package last updated on 10 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc