Class: VCDry::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/vcdry/registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

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_configObject (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

#dupObject



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

Returns:

  • (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

Raises:



30
31
32
33
34
# File 'lib/vcdry/registry.rb', line 30

def keyword(name, type, options = {})
  raise ReservedNameError.new(name) if @other_keywords_config&.name == name.to_sym

  @keywords[name] = Config.new(name, type, **options)
end

#keyword_configsObject



36
37
38
# File 'lib/vcdry/registry.rb', line 36

def keyword_configs
  @keywords.values
end

#keywordsObject



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

Returns:

  • (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