Module: QML::Access::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#meta_objectObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/qml/access.rb', line 34

def meta_object
  @meta_object ||= begin
    exporter = Exporter.new(self, name)

    signals = self.signals.grep(ALLOWED_PATTERN)
    properties = self.properties.grep(ALLOWED_PATTERN)

    signals.each do |signal|
      exporter.add_signal(signal, signal_infos[signal].params)
    end

    properties.each do |prop|
      exporter.add_property(prop, :"#{prop}_changed")
    end

    methods = ancestors.take_while { |k| k.include?(Access) }
      .map { |k| k.instance_methods(false) }.inject(&:|)
      .grep(ALLOWED_PATTERN)
    ignored_methods = signals | properties.flat_map { |p| [p, :"#{p}=", :"#{p}_changed"] }

    (methods - ignored_methods).each do |method|
      instance_method = self.instance_method(method)
      # ignore variadic methods
      if instance_method.arity >= 0
        exporter.add_method(method, instance_method.arity)
      end
    end
    exporter.to_meta_object
  end
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.



70
71
72
73
74
# File 'lib/qml/access.rb', line 70

def register_to_qml(opts = {})
  QML.on_init do
    register_to_qml_impl(opts)
  end
end

#register_to_qml_impl(opts) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/qml/access.rb', line 76

def register_to_qml_impl(opts)
   = (opts)

  meta_object.register(
    [:under],
    [:versions][0],
    [:versions][1],
    [:name]
  )
end