dangerdawson / dryer Goto Github PK
View Code? Open in Web Editor NEWSet of small libraries to give ruby a bit of DI love
License: MIT License
Set of small libraries to give ruby a bit of DI love
License: MIT License
So say we have the following situation:
class Variant
cast: stock_check, class_name: StockCheck
end
class StockCheck
cast: update_products, class_name: UpdateProduct
def call
update_products.call
end
end
class UpdateProduct
def call
variant.in_stock_cache = true
end
end
The question I have is how do we get variant down to UpdateProduct, as it will be passed the caster object ( I have renamed the sender object to caster )
We could do this:
1.
class UpdateProduct
include Dryer::Cast::Target
def call
caster.variant.in_stock_cache = true
end
end
or
2.
class UpdateProduct
include Dryer::Cast::Target
delegate :variant to :caster
def call
variant.in_stock_cache = true
end
end
or
3.
class UpdateProduct
include Dryer::Cast.target(:variant)
def call
variant.in_stock_cache = true
end
end
In the first 2 we would have to make sure that the object we sent to UpdateProduct.new() responded to variant, for option 3 we would have to call UpdateProduct.new with variant as a param
Hence for all of them we would need the framework to do some magic on the caster side e.g
class StockCheck
cast: update_products, class_name: UpdateProduct, with: [:variant]
def call
update_products.call
end
private
def variant
caster.variant
end
end
Do you see the problem?
dryer_delegate
to cast
~~Dryer::Delegate
to ``Dryer::Cast~~
Dryer::Delegate::Send
and Dryer::DelegateTarget
Dryer::Delegate::Send
can be included without arguments.cast_targets
|| .cast_methods
see [(https://github.com//pull/4)]
cast_private :product_parts_updater, class_name: "StockCheck::InStockCache::Update" do
cast_private :model, class_name: "InStockCache::ProductPart"
end
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.