manuelmorales / little-boxes Goto Github PK
View Code? Open in Web Editor NEWDependency injection framework in Ruby
License: MIT License
Dependency injection framework in Ruby
License: MIT License
I really like the idea of lazy evaluations and initialization.
But I am not sure that the vocabulary borrowed from RSpec ("let") sits with me well.
What if you could just use the words lazy
and eager
instead of let
and eager
?
And letc
I would propose to merge with let
(and replace by eager/lazy), and instead of the current dependency
use depends
or inject
. This would better express that lazy/eager
is for defining a dependency that will be used elsewhere, while depends
or inject
is for expressing a dependency on the externally defined object.
Also, instead of receiving box as an argument, perhaps the lambda can be run as instance_exec
from the box itself, so that you don't need to provide box.
and can just type this:
class MyApp::MainBox
include LittleBoxes::Box
lazy(:redis) do
require 'redis'
Redis.new
end
eager(:publisher) do # no parameter, because evaluated inside of box.instance_exec
Publisher.new redis: redis
end
end
class Publisher
include LittleBoxes::Configurable
inject :redis
end
class MainBox
# ...
lazy(:publisher) { Publisher.new }
end
What is the purpose of letc
and why not just always resolve dependencies? I totally get the need for lazy
and eager
, but I wasn't really clear why you'd need two methods to define objects in the mainbox.
Overall โ interesting concept and definitely worth looking into. Thanks for your work, and feel free to throw away all the suggestions. After all, naming is highly subjective if not personal :)
Dependabot can't resolve your Ruby dependency files.
As a result, Dependabot couldn't update your dependencies.
The error Dependabot encountered was:
Bundler::VersionConflict with message: Bundler could not find compatible versions for gem "bundler":
In Gemfile:
bundler (~> 1.3)
Current Bundler version:
bundler (2.2.15)
Your bundle requires a different version of Bundler than the one you're running.
Install the necessary version with `gem install bundler:1.17.3` and rerun bundler using `run.rb _1.17.3_`
If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.
Okay, this is a mouthful
Given
class MainBox
include LittleBoxes::Box
box(:things) do
let(:stuff) { "stuff" }
let(:otherstuff) { "stuff I dont care about" }
end
end
If I want to have a test box, that overrides stuff, I have to redefine the box like so.
class TestBox
include LittleBoxes::Box
import MainBox
box(:things) do
let(:stuff) { "teststuff" }
end
end
box.things.othersuff is lost when using the test box. I know I can solve this by having box(:things)
actually be another class, like box(:things, ThingsBox)
, then I coudl simple import MainBox, and replace the :things box with say, box(:things, TestThingsBox)
but I was wondering if there was a better way of accomplishing this.
Ideally I'd only like to mutate (I know this is a trigger word for most) the existing box imported from MainBox.
Cheers!
Hi!
This gem and approach is amazing. I am wondering how to use it with Bundler, which typically loads all the Gemfile dependencies at start. You finish your talk with statement that it's a completely different way of writing code. Does it mean Bundler initialization in boot.rb would be replaced by loading box, and all the dependencies should be carefully distributed within box configuration structure?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.