Module: Toggles
Defined Under Namespace
Classes: Configuration
Instance Method Summary collapse
- #configuration ⇒ Object
- #configure {|configuration| ... } ⇒ Object
-
#init ⇒ Object
Dynamically create modules and classes within the ‘Feature` module based on the directory structure of `features`.
Instance Method Details
#configuration ⇒ Object
12 13 14 |
# File 'lib/toggles.rb', line 12 def configuration @configuration ||= Configuration.new end |
#configure {|configuration| ... } ⇒ Object
7 8 9 10 |
# File 'lib/toggles.rb', line 7 def configure yield configuration init end |
#init ⇒ Object
Dynamically create modules and classes within the ‘Feature` module based on the directory structure of `features`.
For example if the ‘features` directory has the structure:
features ├── thing | ├── one.yml | └── two.yml └── test.yml
‘Feature::Test`, `Feature::Thing::One`, `Feature::Thing::Two` would be available by default.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/toggles.rb', line 30 def init return unless Dir.exists? configuration.features_dir Find.find(configuration.features_dir) do |path| if path.match(/\.ya?ml\Z/) _, *directories, filename = path.chomp(File.extname(path)).split("/") previous = Feature directories.each do |directory| module_name = directory.split("_").map(&:capitalize).join.to_sym previous = if previous.constants.include? module_name previous.const_get(module_name) else previous.const_set(module_name, Module.new) end end cls = Class.new(Feature::Base) do |c| c.const_set(:PERMISSIONS, Feature::Permissions.new(path)) end previous.const_set(filename.split("_").map(&:capitalize).join.to_sym, cls) end end end |