
Security News
Oxlint Introduces Type-Aware Linting Preview
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
= Decoratable
Provides an easy way to define decorations that add common behaviour to your methods.
== Installation
gem install decoratable
== Requirements
Decoratable does its magic via Module#prepend, which means:
== Usage
require "decoratable"
module Retryable
# All methods defined in this module can decorate methods
extend Decoratable
def retryable(tries = 1, options = { on: [RuntimeError] })
attempt = 0
# To invoke the original method, simply use `yield`
yield
rescue *options[:on]
attempt += 1
attempt > tries ? raise : retry
end
end
module Pryable
extend Decoratable
def pryable
yield
rescue => e
require "pry"
binding.pry
end
end
module Measurable
extend Decoratable
def measurable(logger = Logger.new(STDOUT))
start = Time.now
yield
ensure
# The decoration has access to the original method
# args and any block passed in the original method call are also available
# via __args__ and __block__ respectively
original_method = __decorated_method__
method_location, line = original_method.source_location
marker = "#{original_method.owner}##{original_method.name}[#{method_location}:#{line}]"
duration = (Time.now - start).round(2)
logger.info "#{marker} took #{duration}s to run."
end
end
class Client
extend Measurable
extend Pryable
extend Retryable
# This method will automatically retry on TimeoutErrors, up to 3 times
retryable(tries = 3, on: [TimeoutError])
def get
…
end
# If an error is raised in this method, we'll automatically get a pry session
# to help us debug it
pryable
def post
…
end
# Log the time this method takes to run
measurable
def delete
…
end
end
Decoratable provides a handful of decorations as part of the gem:
More to be added as time goes on.
FAQs
Unknown package
We found that decoratable 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
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.