Module: QML::Access::ClassMethods

Included in:
QML::Access
Defined in:
lib/qml/access.rb

Instance Method Summary collapse

Instance Method Details

#access_wrapper_factoryObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



81
82
83
# File 'lib/qml/access.rb', line 81

def access_wrapper_factory
  @access_wrapper_factory ||= create_access_wrapper_factory
end

#register_to_qml(opts = {}) ⇒ Object

Registers the class as a QML type.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :under (String)

    the namespece which encapsulates the exported QML type. If not specified, automatically inferred from the module nesting of the class.

  • :version (String)

    the version of the type. Defaults to VERSION constant of the encapsulating module / class of the class.

  • :name (String)

    the name of the type. Defaults to the name of the class.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/qml/access.rb', line 43

def register_to_qml(opts = {})
  under = opts[:under]
  version = opts[:version]
  name = opts[:name]

  if !under || !version || !name
    path = self.name.split('::')
  end
  if !under && !version
    fail AccessError, "cannot guess namespace of toplevel class '#{self.name}'" if path.size == 1
    encapsulatings = path[0, path.size - 1]
  end

  under ||= encapsulatings.join('.')
  version ||= eval("::#{encapsulatings.join('::')}").const_get(:VERSION)
  versions = version.split('.').map(&method(:Integer))
  fail AccessError, 'insufficient version (major and minor versions required)' unless versions.size >= 2
  name ||= path.last

  @qml_registeration = {
    under: under,
    version_major: versions[0],
    version_minor: versions[1],
    name: name
  }
  Access.unregistered_classes << self
end

#register_to_qml_realObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



72
73
74
75
76
77
78
# File 'lib/qml/access.rb', line 72

def register_to_qml_real
  access_wrapper_factory.register_to_qml(
    @qml_registeration[:under],
    @qml_registeration[:version_major],
    @qml_registeration[:version_minor],
    @qml_registeration[:name])
end