Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Easiest and fast way to decorate Ruby on Rails models. Compatible with Rails 5.0 and 4.2, 4.1, 4.0.
Decorator Pattern – What is it? Check it here:
Add this line to your application's Gemfile:
gem 'light-decorator', '~> 1.0.1'
Create base class ApplicationDecorator
in folder app/decorators/application_decorator.rb
rails g light:decorator:install
Create decorator for your model. For example we will use the User
model.
We can manually create file:
# app/decorators/user_decorator.rb
class UserDecorator < ApplicationDecorator
def full_name
"#{object.first_name} #{object.last_name}"
end
end
Or we can just use command to create this file:
rails g decorator User
Decorate your model in controller or anywhere.
# Single record
User.find(params[:id]).decorate
User.find_and_decorate(params[:id])
User.decorate.find(params[:id])
# Collection
User.all.decorate
User.decorate
User.limit(10).decorate
User.decorate.limit(10)
# Options
User.find_and_decorate(params[:id], with: AnotherUserDecorator)
# Associations will be decorated automatically
user = User.find_and_decorate(params[:id])
user.decorated? # true
user.comments.decorated? # true
user.comments.first.decorated? # true
Example of Decorator
class UserDecorator < ApplicationDecorator
def full_name
"#{object.first_name} #{object.last_name}"
# or
"#{o.first_name} #{o.last_name}"
end
def full_name_link
helpers.link_to full_name, user_path(object)
# or
h.link_to full_name, user_path(o)
end
end
Bug reports and pull requests are welcome on GitHub at https://github.com/light-ruby/light-decorator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that light-decorator 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 malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.