1
0

dsl.rb 822 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # frozen_string_literal: true
  2. module UserSettings::DSL
  3. module ClassMethods
  4. def setting(key, options = {})
  5. @definitions ||= {}
  6. UserSettings::Setting.new(key, options).tap do |s|
  7. @definitions[s.key] = s
  8. end
  9. end
  10. def setting_inverse_alias(key, original_key)
  11. @definitions[key] = @definitions[original_key].inverse_of(key)
  12. end
  13. def namespace(key, &block)
  14. @definitions ||= {}
  15. UserSettings::Namespace.new(key).configure(&block).tap do |n|
  16. @definitions.merge!(n.definitions)
  17. end
  18. end
  19. def keys
  20. @definitions.keys
  21. end
  22. def definition_for(key)
  23. @definitions[key.to_sym]
  24. end
  25. def definition_for?(key)
  26. @definitions.key?(key.to_sym)
  27. end
  28. end
  29. def self.included(base)
  30. base.extend ClassMethods
  31. end
  32. end