Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Pinball is a library for using dependency injection within Ruby applications. It provides a clear IOC Container that manages dependencies between your classes.
Consider a Service
class that has a dependency on a Repository
. We would
like this dependency to be available to the service when it is created.
First we create a container object and declare the dependencies.
require 'pinball'
Pinball::Container.configure do
define :repository, Repository
end
Then we declare the repository
dependency in the Service class by
using the inject
declaration.
class Service
inject :repository
end
Now we can instantiate Service object and repository
method will
be already accessible in it's constructor! In this case repository
method will return the instance of Repository.
Notice: each call of repository
will create new instance of Repository
.
Also you can inject any already existed object
require 'pinball'
Pinball::Container.configure do
define :string, 'any pre-defined string'
end
In this case string
method will return 'any pre-defined string'
The most powerful feature of pinball is block injection.
For example, you have FirstService
class, that dependent on
SecondService
class, but for instantiating SecondService
you need
to pass @current_user
from FirstService
to it's constructor:
class FirstService
inject :second_service
def initialize(current_user)
@current_user = current_user
end
end
class SecondService
def initialize(current_user)
@current_user = current_user
end
end
Simple defining of SecondService
dependency will not work here.
So we can define dependency with a block:
Pinball::Container.configure do
define :second_service do
SecondService.new(@current_user)
end
end
This block will be executed it FirstService
instance context where
@current_user
will be accessible.
Notice: each call of second_service
will call this block over and over again.
Instead of class injection, singleton injection will not create new objects every time. It will create only one and then returns it. Perfect for stateless services and other singletons. Modifying of classes is not required.
Pinball::Container.configure do
define_singleton :second_service, SingletonClass
end
Sometimes you need to inject dependency to class, when it must be available in
class methods. For this purpose Pinball has class_inject
declaration:
class Foo
class_inject :baz
end
Foo.baz
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)Inspired by Encase gem
FAQs
Unknown package
We found that pinball 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.