
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
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
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.