Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
persisted_attributes
Advanced tools
PersistedAttributes allows to add persisted attributes to ActiveRecord models without the need for a migration.
You might want to add a temporary attribute, for monitoring or reporting purposes, or avoid to pollute your domain tables with marketing-related fields.
With PersistedAttributes, this is as easy as the following:
class User
include PersistedAttributes::ActiveRecord
has_persisted_attribute :subscribe_to_newsletter, field_type: :boolean
end
user = User.create(subscribe_to_newsletter: true)
user.subscribe_to_newsletter # => true
The declared attribute works seamlessly like a traditionnal ActiveRecord attribute. This means you can use features such as validations without any futher work:
class Post
include PersistedAttributes::ActiveRecord
has_persisted_attribute :title
validates :title, presence: true
end
post = Post.new
post.valid? # => false
post.errors.full_messages # => ["Title can't be blank"]
Add this line to your application's Gemfile:
gem "persisted_attributes"
And then execute:
$ bundle
Or install it yourself as:
$ gem install persisted_attributes
Persisted attributes are backed by the persisted_attributes_attributes
table. After installing the gem run migrations to add the required tables:
rails persisted_attributes:install:migrations
Once the migrations are done, start adding attributes to model by including the PersistedAttributes::ActiveRecord
module any active record model:
class Post
include PersistedAttributes::ActiveRecord
end
And voilà! Your model is ready to declare new persisted attributes. The API is as simple as:
class Post
include PersistedAttributes::ActiveRecord
# Use `has_persisted_attribute` with the field name to declare a new attribute.
has_persisted_attribute :title
# Default type for a field is :string. Use the `field_type` option to declare another field type
has_persisted_attribute :reading_time, field_type: :integer
has_persisted_attribute :published, field_type: :boolean
end
For now, PersistedAttributes allow for three field types;
The list will likely grow with time, usage and needs.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that persisted_attributes demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.