KO
|
EN
gitlite — search
Search
#python
#java
#python3
#arduino
#golang
#machine-learning
#rust
#html
#flask
#javascript
#seismology
#nodejs
service_factory
★ 11
Open GitHub ↗
No description available.
Download README (.md)
Explore Similar Repositories
mbtawesome
:
An MBTA subway status application with a good attitude
gradle-plugins
:
Collection of various Gradle Plugins
django-uwkhtmltopdf
:
A Django app to generate pdfs from templates using wkhtmltopdf
promise.js
:
No longer under active development!
ERVolumeAdjust
:
This fills a gap in AVFoundation (OSX), allowing an app to control the input volume of an audio device.
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
service_factory
?
Download (.md)
# ServiceFactory IOC container ## Installation Add this line to your application's Gemfile: gem 'service_factory' And then execute: $ bundle Or install it yourself as: $ gem install service_factory ## Usage 1. Create service_factory.rb in config/initializers directory ```ruby ServiceFactory.register do user_info UserInfo remote_data_service do |url| RemoteData.new(url) end env :test, :development do user_info Fake::UserInfo end memoize do memoized_info { costly_operation } memoized_class BigFatClass end end ``` 2. Then you can use it ```ruby ServiceFactory.user_info("John Dou") #Same as UserInfo.new("John Dou") or Fake::UserInfo.new("John Dou") ServiceFactory.remote_data_service("http://service.com") #Same as RemoteData.new("http://service.com") ServiceFactory.memoized_info #Runs only once ``` See spec/service_factory_spec.rb for the full list of features 3. You can also use rspec-mock with this factory ```ruby ServiceFactory.should_receive(:user_info).with("John Dou").and_return(double(:user_info, address: "baker street")) ``` 4. Sometimes runing rails in development (for example, using `rails s`) lead to empty factory after reloading. To prevent this add code to config/environment/development.rb ```ruby ActionDispatch::Reloader.to_prepare do load Rails.root.join('config/initializers/implementation.rb') end ``` ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request