
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
Python's function decorators for Ruby.
I probably wouldn't use this in production.
gem install method_decorators
Extend MethodDecorators in a class where you want to use them, and then stick +DecoratorName
before your method declaration to decorate the method.
require "method_decorators/memoize"
class MyMath
extend MethodDecorators
+MethodDecorators::Memoize
def self.fib(n)
if n <= 1
1
else
fib(n - 1) * fib(n - 2)
end
end
end
puts MyMath.fib(200)
You can also decorate with an instance of a decorator, rather than the class. This is useful for configuring specific options for the decorator.
class ExternalService
extend MethodDecorators
+MethodDecorators::Retry.new(3)
def request
...
end
end
You can also set multiple decorators for your methods. Each decorator executes within the previously declared decorator. i.e. they are nested, as expected to be.
class ExternalService
extend MethodDecorators
+MethodDecorators::Retry.new(3)
+MethodDecorators::Within.new(2.seconds)
def request
...
end
end
Include these with require 'method_decorators/name_of_decorator'
, or all at once with require 'method_decorators/all'
.
class Transactional < MethodDecorators::Decorator
def call(wrapped, this, *args, &blk)
ActiveRecord::Base.transaction do
wrapped.call(*args, &blk)
end
end
end
MethodDecorators is available under the MIT license and is freely available for all use, including personal, commercial, and academic. See LICENSE for details.
FAQs
Unknown package
We found that method_decorators 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.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.