# File lib/rbvmomi/type_loader.rb, line 21 def initialize target, fn @target = target @db = TypeStore.new fn end
# File lib/rbvmomi/type_loader.rb, line 38 def has_type? name fail unless name.is_a? String @typenames.member? name end
# File lib/rbvmomi/type_loader.rb, line 26 def init @typenames = Set.new(@db['_typenames'] + BasicTypes::BUILTIN) @target.constants.select { |x| has_type? x.to_s }.each { |x| load_type x.to_s } BasicTypes::BUILTIN.each do |x| @target.const_set x, BasicTypes.const_get(x) load_extension x end Object.constants.map(&:to_s).select { |x| has_type? x }.each do |x| load_type x end end
# File lib/rbvmomi/type_loader.rb, line 43 def load_type name fail unless name.is_a? String @target.const_set name, make_type(name) load_extension name nil end
# File lib/rbvmomi/type_loader.rb, line 52 def load_extension name dirs = @target.extension_dirs dirs.map { |x| File.join(x, "#{name}.rb") }. select { |x| File.exists? x }. each { |x| load x } end
# File lib/rbvmomi/type_loader.rb, line 71 def make_data_type name, desc superclass = @target.const_get desc['wsdl_base'] Class.new(superclass).tap do |klass| klass.init name, desc['props'] end end
# File lib/rbvmomi/type_loader.rb, line 85 def make_enum_type name, desc Class.new(BasicTypes::Enum).tap do |klass| klass.init name, desc['values'] end end
# File lib/rbvmomi/type_loader.rb, line 78 def make_managed_type name, desc superclass = @target.const_get desc['wsdl_base'] Class.new(superclass).tap do |klass| klass.init name, desc['props'], desc['methods'] end end
# File lib/rbvmomi/type_loader.rb, line 59 def make_type name name = name.to_s fail if BasicTypes::BUILTIN.member? name desc = @db[name] or fail "unknown VMODL type #{name}" case desc['kind'] when 'data' then make_data_type name, desc when 'managed' then make_managed_type name, desc when 'enum' then make_enum_type name, desc else fail desc.inspect end end