Class: Keyremac::Root

Inherits:
Object
  • Object
show all
Includes:
Container
Defined in:
lib/keyremac/base.rb,
lib/keyremac/dump.rb

container collapse

Attributes included from Container

#children

container collapse

Instance Method Summary collapse

Methods included from Container

#add, #method_missing

Constructor Details

#initializeRoot

Returns a new instance of Root.



102
103
104
105
106
107
# File 'lib/keyremac/base.rb', line 102

def initialize
  @root_item = Item.new 'root_item'
  Keyremac::Focus.focus.clear
  Keyremac::Focus.focus << @root_item
  @children = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Keyremac::Container

Instance Attribute Details

#root_itemObject (readonly)

Returns the value of attribute root_item.



100
101
102
# File 'lib/keyremac/base.rb', line 100

def root_item
  @root_item
end

Instance Method Details

#app(only, **options, &block) ⇒ Item

Parameters:

  • only (String)
  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • same (Object)

    as item method

Returns:



127
128
129
130
# File 'lib/keyremac/base.rb', line 127

def app(only, **options, &block)
  options[:app] = only
  item(**options, &block)
end

#dump(xml = nil) ⇒ Object



90
91
92
93
94
95
96
97
98
99
# File 'lib/keyremac/dump.rb', line 90

def dump(xml = nil)
  xml ||= Builder::XmlMarkup.new(indent: 2)
  xml.instruct!
  xml.root do
    @root_item.dump xml
    @children.each { |child|
      child.dump(xml)
    }
  end
end

#item(app: nil, inputsource: nil, &block) ⇒ Item

yield [] children

Parameters:

  • app (String) (defaults to: nil)

    only tag

  • inputsource (String) (defaults to: nil)

    inputsource_only tag

Returns:



113
114
115
116
117
118
119
120
121
122
# File 'lib/keyremac/base.rb', line 113

def item(app: nil, inputsource: nil, &block)
  Item.new.tap { |item|
    item.only_ app if app
    item.inputsource_only_ inputsource if inputsource
    @children << item
    Keyremac::Focus.set_focus item do
      item.instance_eval(&block)
    end
  }
end