
Security News
Researcher Exposes Zero-Day Clickjacking Vulnerabilities in Major Password Managers
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
Simple attempt to inject dependencies through method decorators (https://github.com/michaelfairley/method_decorators)
Add this line to your application's Gemfile:
gem 'service_provider'
And then execute:
$ bundle
Or install it yourself as:
$ gem install service_provider
Service provider comes with an automatic service provider, which registers every provided service under its name. You can specify your own service provider (see below).
The class that provides a dependency has to extend the ServiceProvider
module and to decorate its initialize method with the Provides
decorator:
class SquareService
extend ServiceProvider
+Provides
def initialize
end
end
The (suggested) name of the service provided defaults to the underscored class name, and can also be given as a parameter: +Provides.new(:square_service)
. The standard service provider used will use this name as the name of the service. Custom service providers (see below) might not make use of this information.
The class that requires a service has to extend the MethodDecorators
module and to decorate its initialize method with the Requires
decorator. The argument passed into the Requires
decorator will be the name of the instance variable that holds that service.
class SquareSample
extend MethodDecorators
+Requires.new(:square_service)
def initialize
end
def do_work(num)
@square_service.square(num)
end
end
After a service has been required it can be manually set on the object, through a setter for the instance variable, i.e. square_service=
.
You might want to specify how services are provided when you have multiple classes that implement the same service or when you want to change the implementations completely, i.e. for tests. To do so, provide your own service provider and register it with ServiceProvider
:
class CustomServiceProvider
def provide(service_class, service_class_provided_service_name)
#how to store services
end
def get_service(service_name)
#how to retrieve services by name
end
end
ServiceProvider.provider_implementation = CustomServiceProvider.new
git checkout -b my-new-feature
)git commit -am 'Added some feature'
)git push origin my-new-feature
)Copyright (c) Johannes Tuchscherer
Released under the MIT license. See LICENSE file for details.
FAQs
Unknown package
We found that service_provider 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
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
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.