
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
A simple gem for injecting dependencies into classes. I got bored of copying the same code again and again so I made this simple gem.
require 'collaborator'
class BugFinder
...
end
class BugKiller
# mixing the Collaborator module
extend Collaborator
# declare a dependency, pass an instance of the collaborator object
dependency :bug_finder, BugFinder.new
end
The dependecy method just creates a couple of attribute accesors, so you can use the dependecy like this:
class BugKiller
extend Collaborator
dependency :bug_finder, BugFinder.new
def run
bugs = bug_finder.run
...
end
end
In your test you just inject a new dependency like so:
bug_killer = BugKiller.new
bug_killer.bug_finder = mocked_bug_finder
You can also pass a lambda as the second argument, this will defer evaluation of the dependecy until it is actually used
class BugKiller
extend Collaborator
dependency :bug_finder, ->{ BugFinder.new }
def run
bugs = bug_finder.run
...
end
end
Sometimes it is useful to prepare the collaborators in some way before actually using them. To do this just create a method in your class called 'prepare_collaborator'.
class BugKiller
extend Collaborator
dependency :bug_finder, ->{ BugFinder.new }
# this function receives the name of the collaborator e.g. :bug_finder and the collaborator itself
def prepare_collaborator(name, collaborator)
collaborator.log_enable = true
end
end
When a dependency is injected e.g. bug_killer.bug_finder = mocked_bug_finder this method is also called on the injected dependency
Copyright (c) 2013 Sebastian. See LICENSE.txt for further details.
FAQs
Unknown package
We found that collaborator 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
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.