Class: Riml::ClassMap
- Inherits:
-
Object
- Object
- Riml::ClassMap
- Defined in:
- lib/riml/class_map.rb
Overview
Map of => ClassDefinitionNode Can also query object for superclass of a named class, etc…
Ex : class_map.superclass(“g:SomeClass”) => “g:SomeClassBase”
Instance Attribute Summary collapse
-
#globbed_imports ⇒ Object
readonly
Returns the value of attribute globbed_imports.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #class_names ⇒ Object
- #classes ⇒ Object
- #has_global_import? ⇒ Boolean
-
#initialize ⇒ ClassMap
constructor
A new instance of ClassMap.
- #safe_fetch(key) ⇒ Object
- #superclass(key) ⇒ Object
Constructor Details
#initialize ⇒ ClassMap
Returns a new instance of ClassMap.
12 13 14 15 16 |
# File 'lib/riml/class_map.rb', line 12 def initialize @map = {} # list of ImportedClass objects that are #globbed? @globbed_imports = [] end |
Instance Attribute Details
#globbed_imports ⇒ Object (readonly)
Returns the value of attribute globbed_imports.
10 11 12 |
# File 'lib/riml/class_map.rb', line 10 def globbed_imports @globbed_imports end |
Instance Method Details
#[](key) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/riml/class_map.rb', line 18 def [](key) ensure_key_is_string!(key) klass = @map[key] return klass if klass if key[0..1] == 'g:' globbed_imports.each do |imported_class| if imported_class.match?(key) return @map[key] = ImportedClass.new(key) end end end raise ClassNotFound, "class #{key.inspect} not found." end |
#[]=(key, val) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/riml/class_map.rb', line 32 def []=(key, val) ensure_key_is_string!(key) if class_node = @map[key] if !class_node.instance_variable_get("@registered_state") && !val.instance_variable_get("@registered_state") class_redefinition!(key) end end @map[key] = val end |
#class_names ⇒ Object
52 53 54 |
# File 'lib/riml/class_map.rb', line 52 def class_names @map.keys end |
#classes ⇒ Object
48 49 50 |
# File 'lib/riml/class_map.rb', line 48 def classes @map.values end |
#has_global_import? ⇒ Boolean
60 61 62 |
# File 'lib/riml/class_map.rb', line 60 def has_global_import? @globbed_imports.any? { |import| import.global_import? } end |
#safe_fetch(key) ⇒ Object
56 57 58 |
# File 'lib/riml/class_map.rb', line 56 def safe_fetch(key) @map[key] end |
#superclass(key) ⇒ Object
43 44 45 46 |
# File 'lib/riml/class_map.rb', line 43 def superclass(key) super_key = self[key].superclass_name self[super_key] end |