Skip to content

store the actual feature configuration in a variable instead of in real constants under the Feature module#4

Merged
Roguelazer merged 5 commits intomasterfrom
store_in_variable
Nov 8, 2016
Merged

store the actual feature configuration in a variable instead of in real constants under the Feature module#4
Roguelazer merged 5 commits intomasterfrom
store_in_variable

Conversation

@Roguelazer
Copy link
Copy Markdown
Contributor

Right now, if you call Toggles.init after toggles has already been initialized, it will leave the old config in place (it has no way of removing previous definitions).

This instead builds the entire class hierarchy in an anonymous module and attaches it as a variable to the Features module, meaning that it can be atomically swapped into and out of place.

I still think that using the module system to store dynamic data is very poor taste and if I felt like refactoring all of our internal consumers, I would probably rewrite this to explicitly use nested hashes.

Copy link
Copy Markdown
Contributor

@att14 att14 left a comment

Choose a reason for hiding this comment

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

Looks good. Nothing major jumps out.

Comment thread spec/toggles/configuration_spec.rb Outdated
@@ -1,3 +1,5 @@
require 'spec_helper'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you need these requires?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should happen automatically from the .rspec file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I added them when I was trying to fix some test failures (which actually turned out to be because the describe Feature::Foo declaration was trying to load the constant Feature::Foo before the before(:each) block ran, which I fixed by changing all of the describes from constants to strings. I'll remove them.

Comment thread lib/toggles.rb
base = path.chomp(File.extname(path)).split("/")
if base.size > 1
directories = base[0...-1]
filename = base[-1]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You don't like the splat?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you know me. explicit > implicit.

Comment thread lib/toggles.rb Outdated
def reinit_if_changed
# Reload the configuration if the top-level directory has changed.
# Does not detect changes to files inside that directory unless your
#
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment isn't complete, but I think it is in the README.

Comment thread lib/toggles/feature.rb Outdated

@@tree = Module.new

def Feature.set_tree(tree)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you just use self here instead of Feature?

@Roguelazer Roguelazer merged commit 5f11a5f into master Nov 8, 2016
Roguelazer added a commit that referenced this pull request Nov 8, 2016
 - Re-running `Toggles.init` will now correctly re-load all features,
   including removing features that have been removed from the
   underlying store
 - New `Toggles.reinit_if_changed` method will cache the inode/mtime
   of the root directory that feature config lives in and run `init`
   if and only if that directory itself has changed
 - Various test improvements

Merge remote-tracking branch 'origin/store_in_variable'

Closes #4
@Roguelazer Roguelazer deleted the store_in_variable branch November 8, 2016 21:11
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.

2 participants