Class: Scale::TypeRegistry
- Inherits:
-
Object
- Object
- Scale::TypeRegistry
- Includes:
- Singleton
- Defined in:
- lib/type_registry.rb
Instance Attribute Summary collapse
-
#custom_types ⇒ Object
optional.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#spec_name ⇒ Object
readonly
init by load, and will not change.
-
#spec_version ⇒ Object
will change by different spec version.
-
#types ⇒ Object
readonly
init by load, and will not change.
-
#versioning ⇒ Object
readonly
optional.
Instance Method Summary collapse
Instance Attribute Details
#custom_types ⇒ Object
optional
8 9 10 |
# File 'lib/type_registry.rb', line 8 def custom_types @custom_types end |
#metadata ⇒ Object
Returns the value of attribute metadata.
12 13 14 |
# File 'lib/type_registry.rb', line 12 def @metadata end |
#spec_name ⇒ Object (readonly)
init by load, and will not change
7 8 9 |
# File 'lib/type_registry.rb', line 7 def spec_name @spec_name end |
#spec_version ⇒ Object
will change by different spec version
11 12 13 |
# File 'lib/type_registry.rb', line 11 def spec_version @spec_version end |
#types ⇒ Object (readonly)
init by load, and will not change
7 8 9 |
# File 'lib/type_registry.rb', line 7 def types @types end |
#versioning ⇒ Object (readonly)
optional
8 9 10 |
# File 'lib/type_registry.rb', line 8 def versioning @versioning end |
Instance Method Details
#all_types ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/type_registry.rb', line 50 def all_types all_types = {}.merge(@types) if @spec_version && @versioning @versioning.each do |item| if @spec_version >= item["runtime_range"][0] && ( item["runtime_range"][1].nil? || @spec_version <= item["runtime_range"][1] ) all_types.merge!(item["types"]) end end end all_types.merge!(@custom_types) if @custom_types all_types end |
#get(type_name) ⇒ Object
41 42 43 44 |
# File 'lib/type_registry.rb', line 41 def get(type_name) all_types = self.all_types type_traverse(type_name, all_types) end |
#load(spec_name: nil, custom_types: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/type_registry.rb', line 14 def load(spec_name: nil, custom_types: nil) @spec_name = nil @types = nil @versioning = nil @custom_types = nil default_types, _, _ = load_chain_spec_types("default") if spec_name begin @spec_name = spec_name spec_types, @versioning, @spec_version = load_chain_spec_types(spec_name) @types = default_types.merge(spec_types) rescue => ex # TODO: check different errors Scale::Types.logger.error "There is no types json file named #{spec_name}" @types = default_types end else @spec_name = "default" @types = default_types end self.custom_types = custom_types true end |