Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Chain::DSL for use with instances of itself #10

Merged
merged 21 commits into from Jul 31, 2013

Conversation

snusnu
Copy link
Owner

@snusnu snusnu commented Jul 30, 2013

It always bugged me that Environment needed to get the registry and chain_dsl injected separately when it feels like chain_dsl should know the registry. Also, it kinda bugged me that a new Chain::DSL subclass was created for every environment.

The real reason tho, is that with moving registry access inside a chain_dsl instance, Environment#initialize can be changed to only accept chain_dsl (for now). This will "open up 2 more slots" for parameters to #initialize - i like 3 params at most). In the future, I will then inject a mutable action registry and the application environment into Environment#initialize, in addition to chain_dsl.

This will eventually allow for decentralized dispatch table definition, by providing something like Environment#chain(name, other = Chain::EMPTY, &block) where name will be used to register the created chain with the mutable registry. Furthermore, Environment#dispatcher will need no more parameters, as the populated dispatch table (the action registry) as well as the application environment, will already be available inside an Environment instance. It is safe to assume that the (user provided) application environment object is already loaded at the time Substation::Environment gets instantiated. This is because the app environment is part of the app, which by itself, should know nothing about substation anyway.

This obviously needs more work, but integration specs pass already. Once unit specs pass too, I will merge this into the decentralized_dispatch_table branch and continue working from there.

@registry.each_with_object(Class.new(DSL)) { |(name, builder), dsl|
define_dsl_method(name, builder, dsl)
}
def compile_dsl_module
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to have a public visibility for this? In general, by default, I think of all methods as private unless they are absolutely necessary in the public interface to allow things to work.

In this case the method is kind of a command and query method. It does some work and returns the @dsl_module. You can't call it without that extra work being performed.

What I might suggest is either having an #initialize_dsl_module method that sets up the state of the object, or have a #dsl_module method that initializes the module and does all the work adding the dsl methods one time and memorizes it in @dsl_module.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkubb thx for catching that! there's no need to expose that method to the public.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkubb fixed in a817720

@snusnu snusnu merged commit 797926d into decentralized_dispatch_table Jul 31, 2013
@snusnu snusnu deleted the chain_dsl_instances branch July 31, 2013 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants