class Settings::Builder
Mirror to the Cursor
class, this class helps extend and expand a settings hierarchy.
Public Class Methods
define(group, &block)
click to toggle source
# File lib/iron/settings/builder.rb, line 7 def self.define(group, &block) builder = self.new(group) builder.define(&block) end
new(group)
click to toggle source
Bind to a group/root
# File lib/iron/settings/builder.rb, line 13 def initialize(group) @group = group end
Public Instance Methods
define(&block)
click to toggle source
Define in block mode
# File lib/iron/settings/builder.rb, line 18 def define(&block) DslProxy.exec(self, &block) end
group(name, &block)
click to toggle source
Create a new sub-group, yield for definition if block passed
# File lib/iron/settings/builder.rb, line 23 def group(name, &block) verify_key?(name) group = @group.find_group(name) unless group verify_available?(name, :group) group = @group.add_group(name) end # Chain it builder = self.class.new(group) builder.define(&block) if block builder end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/iron/settings/builder.rb, line 37 def method_missing(method, *args, &block) type = method.to_s if Settings.data_types.include?(type.gsub('_list','').to_sym) type = type.to_sym name = args[0] default = args[1] verify_key?(name) verify_available?(name, :entry) @group.add_entry(name, type, default, &block) else super end end
respond_to_missing?(method, include_private = false)
click to toggle source
# File lib/iron/settings/builder.rb, line 52 def respond_to_missing?(method, include_private = false) Settings.data_types.include?(method.to_s.gsub('_list','').to_sym) end
Protected Instance Methods
verify_available?(name, type)
click to toggle source
Raise's if name already in use for the group
# File lib/iron/settings/builder.rb, line 59 def verify_available?(name, type) unless @group.find_item(name).nil? raise RuntimeError.new("#{type.capitalize}'s name '#{name}' already defined for settings group: #{@group.key}") end end
verify_key?(key)
click to toggle source
# File lib/iron/settings/builder.rb, line 65 def verify_key?(key) unless key.is_a?(String) && key.match(/^[a-z][a-z0-9_]*$/) raise RuntimeError.new("Key '#{key}' is not a valid group/entry key while defining settings group #{@group.key} - must be a string with a-z, 0-9, or _ chars") end end