Class: VCDry::Registry
- Inherits:
-
Object
- Object
- VCDry::Registry
- Defined in:
- lib/vcdry/registry.rb
Instance Attribute Summary collapse
-
#other_keywords_config ⇒ Object
readonly
Returns the value of attribute other_keywords_config.
Instance Method Summary collapse
- #dup ⇒ Object
- #gather_unknown_keywords? ⇒ Boolean
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #keyword(name, type, options = {}) ⇒ Object
- #keyword_configs ⇒ Object
- #keywords ⇒ Object
- #other_keywords(name, type = :hash) ⇒ Object
- #remove_keyword(name) ⇒ Object
- #strict? ⇒ Boolean
- #strict_keywords(value) ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
8 9 10 11 12 |
# File 'lib/vcdry/registry.rb', line 8 def initialize @keywords = {} @other_keywords_config = nil @strict = true end |
Instance Attribute Details
#other_keywords_config ⇒ Object (readonly)
Returns the value of attribute other_keywords_config.
6 7 8 |
# File 'lib/vcdry/registry.rb', line 6 def other_keywords_config @other_keywords_config end |
Instance Method Details
#dup ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/vcdry/registry.rb', line 14 def dup object = self.class.new keywords = {} @keywords.each do |name, config| keywords[name] = config.dup end object.instance_variable_set(:@keywords, keywords) object.instance_variable_set(:@other_keywords_config, @other_keywords_config&.dup) object.instance_variable_set(:@strict, @strict) object end |
#gather_unknown_keywords? ⇒ Boolean
26 27 28 |
# File 'lib/vcdry/registry.rb', line 26 def gather_unknown_keywords? !@other_keywords_config.nil? end |
#keyword(name, type, options = {}) ⇒ Object
30 31 32 33 34 |
# File 'lib/vcdry/registry.rb', line 30 def keyword(name, type, = {}) raise ReservedNameError.new(name) if @other_keywords_config&.name == name.to_sym @keywords[name] = Config.new(name, type, **) end |
#keyword_configs ⇒ Object
36 37 38 |
# File 'lib/vcdry/registry.rb', line 36 def keyword_configs @keywords.values end |
#keywords ⇒ Object
40 41 42 |
# File 'lib/vcdry/registry.rb', line 40 def keywords @keywords.keys end |
#other_keywords(name, type = :hash) ⇒ Object
44 45 46 |
# File 'lib/vcdry/registry.rb', line 44 def other_keywords(name, type = :hash) @other_keywords_config = Config.new(name, type) end |
#remove_keyword(name) ⇒ Object
56 57 58 |
# File 'lib/vcdry/registry.rb', line 56 def remove_keyword(name) @keywords.delete(name) end |
#strict? ⇒ Boolean
48 49 50 |
# File 'lib/vcdry/registry.rb', line 48 def strict? !gather_unknown_keywords? && @strict end |
#strict_keywords(value) ⇒ Object
52 53 54 |
# File 'lib/vcdry/registry.rb', line 52 def strict_keywords(value) @strict = !!value end |