
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Eventually
is a module that facilitates evented callback management similar to the EventEmitter API in NodeJS. Support for Ruby's various callback styles is heavily baked in, so using blocks, lambdas, procs, or even detached methods works out of the box, batteries included. Simply include Eventually
in the class you will be emitting events from, register some listeners and fire away.
class Car
include Eventually
def stop
#...
emit(:stopped, 0)
end
end
car = Car.new
car.on(:stopped) do |mph|
puts 'the car stopped, sitting at %d mph' % mph
end
car.stop # this will indirectly invoke the above callback
For documentation purposes, it can often be nice to define up front what events you'll be expecting to emit from the instances of a certain class. Anyone who's ever spent a couple of minutes trying to dig up their database columns from an ActiveRecord model knows what I'm talking about. Annoying. So Eventually
let's you put that all up front in a nice DSL.
class Car
include Eventually
emits :stopped, :started, :turning
emits :reversing
end
The previous snippet acts mostly as documentation.
See the examples/basic.rb file for a slightly more complicated setup than this one.
However, sometimes you want to be sure that a given registered callback will conform to your event interface, so specify an arity validation. Let's add another event to our definition and ensure that callbacks registering for that event must have an arity of 1. This will also raise an error if you attempt to emit an event with the wrong argument arity.
class Car
include Eventually
emits :driving, :arity => 1
end
car = Car.new
car.on(:driving) do
puts 'The car is driving'
end
# Error will be raise explaining the arity mismatch (expected 1, received -1)
See the examples/arity.rb file for more on this.
Strict mode is useful if you want to enforce the #emits
documentation as being the ONLY events that your instances can emit or be registered against.
class Car
include Eventually
enable_strict!
emits :started, :stopped
def turn
# Emitting :turning event here will throw an error in strict mode
emit(:turning)
end
end
car = Car.new
# Registering for the :turning event here will throw an error in strict mode
car.on(:turning) do
puts 'the car is turning'
end
See the examples/scrict.rb file for more on this.
Further examples can be found in the examples directory. I know, novel idea that one.
@localshred wrote this. He sometimes blogs too.
FAQs
Unknown package
We found that eventually 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
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.