Class: BinData::Registry
- Inherits:
-
Object
- Object
- BinData::Registry
- Defined in:
- lib/bindata/registry.rb,
lib/bindata/deprecated.rb
Overview
This registry contains a register of name -> class mappings.
Names are stored in under_score_style, not camelCase.
Class Method Summary collapse
-
.instance ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #is_registered?(name, endian = nil) ⇒ Boolean
- #lookup(name, endian = nil) ⇒ Object
- #register(name, class_to_register) ⇒ Object
-
#underscore_name(name) ⇒ Object
Convert camelCase
name
to underscore style.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
7 8 9 |
# File 'lib/bindata/registry.rb', line 7 def initialize @registry = {} end |
Class Method Details
.instance ⇒ Object
:nodoc:
28 29 30 31 |
# File 'lib/bindata/deprecated.rb', line 28 def Registry.instance #:nodoc: warn "'Registry.instance' is deprecated. Replacing with 'RegisteredClasses'" RegisteredClasses end |
Instance Method Details
#is_registered?(name, endian = nil) ⇒ Boolean
24 25 26 |
# File 'lib/bindata/registry.rb', line 24 def is_registered?(name, endian = nil) @registry.has_key?(lookup_key(name, endian)) end |
#lookup(name, endian = nil) ⇒ Object
18 19 20 21 22 |
# File 'lib/bindata/registry.rb', line 18 def lookup(name, endian = nil) key = lookup_key(name, endian) @registry[key] || lookup_int(key) end |
#register(name, class_to_register) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/bindata/registry.rb', line 11 def register(name, class_to_register) formatted_name = lookup_key(name) warn_if_name_is_already_registered(formatted_name, class_to_register) @registry[formatted_name] = class_to_register end |
#underscore_name(name) ⇒ Object
Convert camelCase name
to underscore style.
29 30 31 32 33 34 35 |
# File 'lib/bindata/registry.rb', line 29 def underscore_name(name) name.to_s.sub(/.*::/, ""). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |