Class: Karabiner::Item

Inherits:
Object
  • Object
show all
Includes:
DSL::Item, XmlTree
Defined in:
lib/karabiner/item.rb

Constant Summary collapse

AVAILABLE_OPTIONS =
%i[
  not
  only
  config_not
  config_only
  device_not
  device_only
].freeze

Constants included from DSL::Item

DSL::Item::AVAILABLE_PROPERTIES

Instance Method Summary collapse

Methods included from DSL::Item

#execute, #invoke, #remap, #show_message

Methods included from XmlTree

#add_child, #search_childs

Constructor Details

#initialize(name, options = {}) ⇒ Item

Returns a new instance of Item.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/karabiner/item.rb', line 17

def initialize(name, options = {})
  @skip_identifier = options.delete(:skip_identifier)

  if name
    property = Karabiner::Property.new("name", name)
    add_child(property)
  end

  options.each do |option, value|
    raise "Unavailable option: #{option}" unless AVAILABLE_OPTIONS.include?(option)

    property = Karabiner::Property.new(option, value)
    add_child(property)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Karabiner::DSL::Item

Instance Method Details

#to_xmlObject



33
34
35
36
37
38
# File 'lib/karabiner/item.rb', line 33

def to_xml
  validate_name_existence
  generate_identifier unless @skip_identifier

  super
end