Class: KO::Object

Inherits:
Object
  • Object
show all
Extended by:
Properties, Signals
Defined in:
lib/ko/object.rb

Direct Known Subclasses

Application

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Signals

extended, inherited, signals

Methods included from Properties

extended, property

Constructor Details

#initialize(id: nil, parent: nil) ⇒ Object

Returns a new instance of Object.



21
22
23
24
# File 'lib/ko/object.rb', line 21

def initialize(id: nil, parent: nil)
  @id = id
  self.parent = parent || find_parent
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



17
18
19
# File 'lib/ko/object.rb', line 17

def id
  @id
end

#parentObject

Returns the value of attribute parent.



17
18
19
# File 'lib/ko/object.rb', line 17

def parent
  @parent
end

Class Method Details

.[](id = nil, parent = nil) ⇒ Object



9
10
11
12
13
14
# File 'lib/ko/object.rb', line 9

def [](id = nil, parent = nil, &)
  new(id:, parent:).tap do |obj|
    obj.instance_exec(&) if block_given?
    obj.ready.emit
  end
end

Instance Method Details

#[](id) ⇒ Object



43
# File 'lib/ko/object.rb', line 43

def [](id) = children[id]

#_Object



45
# File 'lib/ko/object.rb', line 45

def _ = self

#add_child(obj) ⇒ Object



36
37
38
39
40
# File 'lib/ko/object.rb', line 36

def add_child(obj)
  obj.parent = self if obj.parent != self

  children.add(obj)
end

#appObject



44
# File 'lib/ko/object.rb', line 44

def app = KO::Application.instance

#childrenObject



26
# File 'lib/ko/object.rb', line 26

def children = @children ||= Children.new

#inspectObject



47
48
49
50
# File 'lib/ko/object.rb', line 47

def inspect
  id_str = id.nil? ? "" : "[#{id.inspect}]"
  "#<#{self.class}#{id_str} signals=#{signals.count} properties=#{properties.count} children=#{children.count}>"
end

#remove_child(obj) ⇒ Object



42
# File 'lib/ko/object.rb', line 42

def remove_child(obj) = children.remove(obj)