
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
simple_enum-multiple
Advanced tools
SimpleEnum::Multiple is extension of SimpleEnum, which brings multi-select enum support to SimpleEnum.
Add this to a model:
class User < ActiveRecord::Base
as_enum :favorites, [:iphone, :ipad, :macbook], accessor: :join_table
end
Then create the required users_favorites
table using migrations:
class AddFavoritesColumnToUser < ActiveRecord::Migration
def change
create_join_table :users, :favorites
end
end
It will store multi-enums data in a join table, if you don't want a join table, you may use bitwise
accessor:
# Migration
add_column :Users, :favorite_cds, :integer
# Model
as_enum :favorites, [:iphone, :ipad, :macbook], accessor: :bitwise
It will store multi-enums data in a integer column, and if you don't want SimpleEnum::Multiple manage how you store your data, you can use multiple
accessor:
# Model
# serialize :favorite_cds
# serialize :favorite_cds, YourOwnCoder
as_enum :favorites, [:iphone, :ipad, :macbook], accessor: :multiple
This accessor will not handle how the data saved in the database, so you have to use something like serialize :favorite_cds
, or implement your own Coder.
class User < ActiveRecord::Base
as_enum :favorites, [:iphone, :ipad, :macbook], accessor: :join_table
end
jane = User.new
jane.favorites = [:iphone, :ipad]
jane.iphone? # => true
jane.ipad? # => true
jane.macbook? # => false
jane.favorites # => [:iphone, ipad]
jane.favorite_cds # => [0, 1]
joe = User.new
joe.iphone! # => [:iphone]
joe.favorites # => [:iphone]
joe.favorite_cds # => [0]
User.favorites # => #<SimpleEnum::Enum:0x0....>
User.favorites[:iphone] # => [0]
User.favorites.values_at(:iphone, :ipad) # => [0, 1]
User.iphones # => #<ActiveRecord::Relation:0x0.... [jane, joe]>
# You can also do this since `favorites` returns a
# #<SimpleEnum::Multiple::CollectionProxy> rather than a #<Array>:
joe = User.new
joe.iphone! # => [:iphone]
joe.favorites.push :ipad
joe.favorites # => [:iphone, ipad]
joe.favorite_cds # => [0, 1]
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that simple_enum-multiple demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.