public
Created

Conject blog post samples

  • Download Gist
car_sample.rb
Ruby
1 2 3 4 5
class Car
construct_with :chassis, :engine, :highway
end
 
car = Conject.default_object_context[:car]
config_sample.rb
Ruby
1 2 3 4 5
# Disable caching for specific objects:
my_context.configure_object engine: {cache: false}
 
# Custom object construction via proc or lambda:
my_context.configure_object chassis: {construct: lambda do "The Chassis" end}
subcontext_sample.rb
Ruby
1 2 3 4 5 6 7
class ChartPresenter
construct_with :chart_model, :chart_view
end
 
main_context.in_subcontext do |sub|
sub[:chart_model]
end
this_object_context_sample.rb
Ruby
1 2 3 4 5 6 7 8
class Galaxy
construct_with :this_object_context
def spawn_new_solar_system
this_object_context.in_subcontext do |subcontext|
subcontext[:sun].genesis
end
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.